From 4cc516a03ca21dc7f596fac207c5bb1d35100b21 Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Tue, 19 May 2026 18:51:11 +0000 Subject: [PATCH 1/8] ci: pin GitHub Actions to commit SHAs Pin all GitHub Actions referenced in generated workflows (both first-party `actions/*` and third-party) to immutable commit SHAs. Updating pinned actions is now a deliberate codegen-side bump rather than implicit on every workflow run. From c50c22e150e08e5abe34bd18bbcba0759cee7c16 Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Wed, 13 May 2026 04:08:59 +0000 Subject: [PATCH 2/8] codegen metadata --- .stats.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.stats.yml b/.stats.yml index 6359ad060..198579a56 100644 --- a/.stats.yml +++ b/.stats.yml @@ -1,4 +1,4 @@ configured_endpoints: 232 -openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/openai/openai-50d816559ef0935e64d07789ff936a2b762e26ab0714a2fa6bc06d06d4484294.yml +openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/openai/openai-7f30f2390f57603d13ed862d360185cfb4f48b4bf9e56e73d1d17ae7e3dfc423.yml openapi_spec_hash: c5d8f37edbf66c1fef627d787b4c54fd -config_hash: b64135fff1fe9cf4069b9ecf59ae8b07 +config_hash: b496fe9c594a1820ad169a6f2d841a32 From e40c1af41ed6c2126669b2a71bbd796c80dfe0ec Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Wed, 13 May 2026 17:26:10 +0000 Subject: [PATCH 3/8] codegen metadata --- .stats.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.stats.yml b/.stats.yml index 198579a56..3cd01621d 100644 --- a/.stats.yml +++ b/.stats.yml @@ -1,4 +1,4 @@ configured_endpoints: 232 -openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/openai/openai-7f30f2390f57603d13ed862d360185cfb4f48b4bf9e56e73d1d17ae7e3dfc423.yml +openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/openai/openai-0127d9dfdff671141b07eb8fda98f6297f70267d2fa9249f4b0defb6826e5aba.yml openapi_spec_hash: c5d8f37edbf66c1fef627d787b4c54fd -config_hash: b496fe9c594a1820ad169a6f2d841a32 +config_hash: 70ff4da62a6a6ef9f91d566c38b7bddf From 33debacb88320787265e083cbdb91ec6e3e812f5 Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Fri, 15 May 2026 23:12:22 +0000 Subject: [PATCH 4/8] feat(api): update OpenAPI spec or Stainless config --- .stats.yml | 4 +- .../invites/InviteCreateParams.kt | 12 +- .../usage/UsageAudioSpeechesResponse.kt | 1101 +++++++++++++++++ .../usage/UsageAudioTranscriptionsResponse.kt | 1101 +++++++++++++++++ .../UsageCodeInterpreterSessionsResponse.kt | 1101 +++++++++++++++++ .../usage/UsageCompletionsResponse.kt | 1101 +++++++++++++++++ .../organization/usage/UsageCostsResponse.kt | 1101 +++++++++++++++++ .../usage/UsageEmbeddingsResponse.kt | 1101 +++++++++++++++++ .../organization/usage/UsageImagesResponse.kt | 1101 +++++++++++++++++ .../usage/UsageModerationsResponse.kt | 1101 +++++++++++++++++ .../usage/UsageVectorStoresResponse.kt | 1101 +++++++++++++++++ .../conversations/ConversationCreateParams.kt | 6 + .../conversations/items/ItemCreateParams.kt | 6 + .../models/responses/ResponseInputItem.kt | 44 + .../models/responses/ResponseInputItemTest.kt | 78 ++ 15 files changed, 10053 insertions(+), 6 deletions(-) diff --git a/.stats.yml b/.stats.yml index 3cd01621d..c3dc810d4 100644 --- a/.stats.yml +++ b/.stats.yml @@ -1,4 +1,4 @@ configured_endpoints: 232 -openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/openai/openai-0127d9dfdff671141b07eb8fda98f6297f70267d2fa9249f4b0defb6826e5aba.yml -openapi_spec_hash: c5d8f37edbf66c1fef627d787b4c54fd +openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/openai/openai-fcfdf0bb920ca15a6d01d1cfe988accb7559b2d991b6e2ad6b25cfae81ac2ae9.yml +openapi_spec_hash: 72ee7d4fe582e75d16e67b6c97881fed config_hash: 70ff4da62a6a6ef9f91d566c38b7bddf diff --git a/openai-java-core/src/main/kotlin/com/openai/models/admin/organization/invites/InviteCreateParams.kt b/openai-java-core/src/main/kotlin/com/openai/models/admin/organization/invites/InviteCreateParams.kt index aa78bf78b..171918955 100644 --- a/openai-java-core/src/main/kotlin/com/openai/models/admin/organization/invites/InviteCreateParams.kt +++ b/openai-java-core/src/main/kotlin/com/openai/models/admin/organization/invites/InviteCreateParams.kt @@ -53,7 +53,8 @@ private constructor( /** * An array of projects to which membership is granted at the same time the org invite is * accepted. If omitted, the user will be invited to the default project for compatibility with - * legacy behavior. + * legacy behavior. If empty list is passed, the user will not be invited to any projects, + * including the default one. * * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). @@ -155,7 +156,8 @@ private constructor( /** * An array of projects to which membership is granted at the same time the org invite is * accepted. If omitted, the user will be invited to the default project for compatibility - * with legacy behavior. + * with legacy behavior. If empty list is passed, the user will not be invited to any + * projects, including the default one. */ fun projects(projects: List) = apply { body.projects(projects) } @@ -356,7 +358,8 @@ private constructor( /** * An array of projects to which membership is granted at the same time the org invite is * accepted. If omitted, the user will be invited to the default project for compatibility - * with legacy behavior. + * with legacy behavior. If empty list is passed, the user will not be invited to any + * projects, including the default one. * * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). @@ -455,7 +458,8 @@ private constructor( /** * An array of projects to which membership is granted at the same time the org invite * is accepted. If omitted, the user will be invited to the default project for - * compatibility with legacy behavior. + * compatibility with legacy behavior. If empty list is passed, the user will not be + * invited to any projects, including the default one. */ fun projects(projects: List) = projects(JsonField.of(projects)) diff --git a/openai-java-core/src/main/kotlin/com/openai/models/admin/organization/usage/UsageAudioSpeechesResponse.kt b/openai-java-core/src/main/kotlin/com/openai/models/admin/organization/usage/UsageAudioSpeechesResponse.kt index 1aa7725dc..a4e7997c0 100644 --- a/openai-java-core/src/main/kotlin/com/openai/models/admin/organization/usage/UsageAudioSpeechesResponse.kt +++ b/openai-java-core/src/main/kotlin/com/openai/models/admin/organization/usage/UsageAudioSpeechesResponse.kt @@ -561,6 +561,36 @@ private constructor( .build() ) + /** + * Alias for calling [addResult] with + * `Result.ofOrganizationUsageFileSearches(organizationUsageFileSearches)`. + */ + fun addResult( + organizationUsageFileSearches: Result.OrganizationUsageFileSearchesResult + ) = addResult(Result.ofOrganizationUsageFileSearches(organizationUsageFileSearches)) + + /** + * Alias for calling [addResult] with the following: + * ```java + * Result.OrganizationUsageFileSearchesResult.builder() + * .numRequests(numRequests) + * .build() + * ``` + */ + fun addOrganizationUsageFileSearchesResult(numRequests: Long) = + addResult( + Result.OrganizationUsageFileSearchesResult.builder() + .numRequests(numRequests) + .build() + ) + + /** + * Alias for calling [addResult] with + * `Result.ofOrganizationUsageWebSearches(organizationUsageWebSearches)`. + */ + fun addResult(organizationUsageWebSearches: Result.OrganizationUsageWebSearchesResult) = + addResult(Result.ofOrganizationUsageWebSearches(organizationUsageWebSearches)) + /** * Alias for calling [addResult] with `Result.ofOrganizationCosts(organizationCosts)`. */ @@ -687,6 +717,8 @@ private constructor( private val organizationUsageCodeInterpreterSessions: OrganizationUsageCodeInterpreterSessionsResult? = null, + private val organizationUsageFileSearches: OrganizationUsageFileSearchesResult? = null, + private val organizationUsageWebSearches: OrganizationUsageWebSearchesResult? = null, private val organizationCosts: OrganizationCostsResult? = null, private val _json: JsonValue? = null, ) { @@ -727,6 +759,14 @@ private constructor( Optional = Optional.ofNullable(organizationUsageCodeInterpreterSessions) + /** The aggregated file search calls usage details of the specific time bucket. */ + fun organizationUsageFileSearches(): Optional = + Optional.ofNullable(organizationUsageFileSearches) + + /** The aggregated web search calls usage details of the specific time bucket. */ + fun organizationUsageWebSearches(): Optional = + Optional.ofNullable(organizationUsageWebSearches) + /** The aggregated costs details of the specific time bucket. */ fun organizationCosts(): Optional = Optional.ofNullable(organizationCosts) @@ -749,6 +789,10 @@ private constructor( fun isOrganizationUsageCodeInterpreterSessions(): Boolean = organizationUsageCodeInterpreterSessions != null + fun isOrganizationUsageFileSearches(): Boolean = organizationUsageFileSearches != null + + fun isOrganizationUsageWebSearches(): Boolean = organizationUsageWebSearches != null + fun isOrganizationCosts(): Boolean = organizationCosts != null /** The aggregated completions usage details of the specific time bucket. */ @@ -791,6 +835,14 @@ private constructor( "organizationUsageCodeInterpreterSessions" ) + /** The aggregated file search calls usage details of the specific time bucket. */ + fun asOrganizationUsageFileSearches(): OrganizationUsageFileSearchesResult = + organizationUsageFileSearches.getOrThrow("organizationUsageFileSearches") + + /** The aggregated web search calls usage details of the specific time bucket. */ + fun asOrganizationUsageWebSearches(): OrganizationUsageWebSearchesResult = + organizationUsageWebSearches.getOrThrow("organizationUsageWebSearches") + /** The aggregated costs details of the specific time bucket. */ fun asOrganizationCosts(): OrganizationCostsResult = organizationCosts.getOrThrow("organizationCosts") @@ -849,6 +901,10 @@ private constructor( visitor.visitOrganizationUsageCodeInterpreterSessions( organizationUsageCodeInterpreterSessions ) + organizationUsageFileSearches != null -> + visitor.visitOrganizationUsageFileSearches(organizationUsageFileSearches) + organizationUsageWebSearches != null -> + visitor.visitOrganizationUsageWebSearches(organizationUsageWebSearches) organizationCosts != null -> visitor.visitOrganizationCosts(organizationCosts) else -> visitor.unknown(_json) } @@ -922,6 +978,18 @@ private constructor( organizationUsageCodeInterpreterSessions.validate() } + override fun visitOrganizationUsageFileSearches( + organizationUsageFileSearches: OrganizationUsageFileSearchesResult + ) { + organizationUsageFileSearches.validate() + } + + override fun visitOrganizationUsageWebSearches( + organizationUsageWebSearches: OrganizationUsageWebSearchesResult + ) { + organizationUsageWebSearches.validate() + } + override fun visitOrganizationCosts( organizationCosts: OrganizationCostsResult ) { @@ -984,6 +1052,14 @@ private constructor( OrganizationUsageCodeInterpreterSessionsResult ) = organizationUsageCodeInterpreterSessions.validity() + override fun visitOrganizationUsageFileSearches( + organizationUsageFileSearches: OrganizationUsageFileSearchesResult + ) = organizationUsageFileSearches.validity() + + override fun visitOrganizationUsageWebSearches( + organizationUsageWebSearches: OrganizationUsageWebSearchesResult + ) = organizationUsageWebSearches.validity() + override fun visitOrganizationCosts( organizationCosts: OrganizationCostsResult ) = organizationCosts.validity() @@ -1008,6 +1084,8 @@ private constructor( organizationUsageVectorStores == other.organizationUsageVectorStores && organizationUsageCodeInterpreterSessions == other.organizationUsageCodeInterpreterSessions && + organizationUsageFileSearches == other.organizationUsageFileSearches && + organizationUsageWebSearches == other.organizationUsageWebSearches && organizationCosts == other.organizationCosts } @@ -1021,6 +1099,8 @@ private constructor( organizationUsageAudioTranscriptions, organizationUsageVectorStores, organizationUsageCodeInterpreterSessions, + organizationUsageFileSearches, + organizationUsageWebSearches, organizationCosts, ) @@ -1042,6 +1122,10 @@ private constructor( "Result{organizationUsageVectorStores=$organizationUsageVectorStores}" organizationUsageCodeInterpreterSessions != null -> "Result{organizationUsageCodeInterpreterSessions=$organizationUsageCodeInterpreterSessions}" + organizationUsageFileSearches != null -> + "Result{organizationUsageFileSearches=$organizationUsageFileSearches}" + organizationUsageWebSearches != null -> + "Result{organizationUsageWebSearches=$organizationUsageWebSearches}" organizationCosts != null -> "Result{organizationCosts=$organizationCosts}" _json != null -> "Result{_unknown=$_json}" else -> throw IllegalStateException("Invalid Result") @@ -1110,6 +1194,18 @@ private constructor( organizationUsageCodeInterpreterSessions ) + /** The aggregated file search calls usage details of the specific time bucket. */ + @JvmStatic + fun ofOrganizationUsageFileSearches( + organizationUsageFileSearches: OrganizationUsageFileSearchesResult + ) = Result(organizationUsageFileSearches = organizationUsageFileSearches) + + /** The aggregated web search calls usage details of the specific time bucket. */ + @JvmStatic + fun ofOrganizationUsageWebSearches( + organizationUsageWebSearches: OrganizationUsageWebSearchesResult + ) = Result(organizationUsageWebSearches = organizationUsageWebSearches) + /** The aggregated costs details of the specific time bucket. */ @JvmStatic fun ofOrganizationCosts(organizationCosts: OrganizationCostsResult) = @@ -1167,6 +1263,16 @@ private constructor( OrganizationUsageCodeInterpreterSessionsResult ): T + /** The aggregated file search calls usage details of the specific time bucket. */ + fun visitOrganizationUsageFileSearches( + organizationUsageFileSearches: OrganizationUsageFileSearchesResult + ): T + + /** The aggregated web search calls usage details of the specific time bucket. */ + fun visitOrganizationUsageWebSearches( + organizationUsageWebSearches: OrganizationUsageWebSearchesResult + ): T + /** The aggregated costs details of the specific time bucket. */ fun visitOrganizationCosts(organizationCosts: OrganizationCostsResult): T @@ -1262,6 +1368,22 @@ private constructor( ) } ?: Result(_json = json) } + "organization.usage.file_searches.result" -> { + return tryDeserialize( + node, + jacksonTypeRef(), + ) + ?.let { Result(organizationUsageFileSearches = it, _json = json) } + ?: Result(_json = json) + } + "organization.usage.web_searches.result" -> { + return tryDeserialize( + node, + jacksonTypeRef(), + ) + ?.let { Result(organizationUsageWebSearches = it, _json = json) } + ?: Result(_json = json) + } "organization.costs.result" -> { return tryDeserialize(node, jacksonTypeRef()) ?.let { Result(organizationCosts = it, _json = json) } @@ -1297,6 +1419,10 @@ private constructor( generator.writeObject(value.organizationUsageVectorStores) value.organizationUsageCodeInterpreterSessions != null -> generator.writeObject(value.organizationUsageCodeInterpreterSessions) + value.organizationUsageFileSearches != null -> + generator.writeObject(value.organizationUsageFileSearches) + value.organizationUsageWebSearches != null -> + generator.writeObject(value.organizationUsageWebSearches) value.organizationCosts != null -> generator.writeObject(value.organizationCosts) value._json != null -> generator.writeObject(value._json) @@ -5162,6 +5288,981 @@ private constructor( "OrganizationUsageCodeInterpreterSessionsResult{numSessions=$numSessions, object_=$object_, projectId=$projectId, additionalProperties=$additionalProperties}" } + /** The aggregated file search calls usage details of the specific time bucket. */ + class OrganizationUsageFileSearchesResult + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val numRequests: JsonField, + private val object_: JsonValue, + private val apiKeyId: JsonField, + private val projectId: JsonField, + private val userId: JsonField, + private val vectorStoreId: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("num_requests") + @ExcludeMissing + numRequests: JsonField = JsonMissing.of(), + @JsonProperty("object") @ExcludeMissing object_: JsonValue = JsonMissing.of(), + @JsonProperty("api_key_id") + @ExcludeMissing + apiKeyId: JsonField = JsonMissing.of(), + @JsonProperty("project_id") + @ExcludeMissing + projectId: JsonField = JsonMissing.of(), + @JsonProperty("user_id") + @ExcludeMissing + userId: JsonField = JsonMissing.of(), + @JsonProperty("vector_store_id") + @ExcludeMissing + vectorStoreId: JsonField = JsonMissing.of(), + ) : this( + numRequests, + object_, + apiKeyId, + projectId, + userId, + vectorStoreId, + mutableMapOf(), + ) + + /** + * The count of file search calls. + * + * @throws OpenAIInvalidDataException 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 numRequests(): Long = numRequests.getRequired("num_requests") + + /** + * Expected to always return the following: + * ```java + * JsonValue.from("organization.usage.file_searches.result") + * ``` + * + * However, this method can be useful for debugging and logging (e.g. if the server + * responded with an unexpected value). + */ + @JsonProperty("object") @ExcludeMissing fun _object_(): JsonValue = object_ + + /** + * When `group_by=api_key_id`, this field provides the API key ID of the grouped + * usage result. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun apiKeyId(): Optional = apiKeyId.getOptional("api_key_id") + + /** + * When `group_by=project_id`, this field provides the project ID of the grouped + * usage result. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun projectId(): Optional = projectId.getOptional("project_id") + + /** + * When `group_by=user_id`, this field provides the user ID of the grouped usage + * result. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun userId(): Optional = userId.getOptional("user_id") + + /** + * When `group_by=vector_store_id`, this field provides the vector store ID of the + * grouped usage result. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun vectorStoreId(): Optional = vectorStoreId.getOptional("vector_store_id") + + /** + * Returns the raw JSON value of [numRequests]. + * + * Unlike [numRequests], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("num_requests") + @ExcludeMissing + fun _numRequests(): JsonField = numRequests + + /** + * Returns the raw JSON value of [apiKeyId]. + * + * Unlike [apiKeyId], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("api_key_id") + @ExcludeMissing + fun _apiKeyId(): JsonField = apiKeyId + + /** + * 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 [userId]. + * + * Unlike [userId], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("user_id") @ExcludeMissing fun _userId(): JsonField = userId + + /** + * Returns the raw JSON value of [vectorStoreId]. + * + * Unlike [vectorStoreId], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("vector_store_id") + @ExcludeMissing + fun _vectorStoreId(): JsonField = vectorStoreId + + @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 + * [OrganizationUsageFileSearchesResult]. + * + * The following fields are required: + * ```java + * .numRequests() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [OrganizationUsageFileSearchesResult]. */ + class Builder internal constructor() { + + private var numRequests: JsonField? = null + private var object_: JsonValue = + JsonValue.from("organization.usage.file_searches.result") + private var apiKeyId: JsonField = JsonMissing.of() + private var projectId: JsonField = JsonMissing.of() + private var userId: JsonField = JsonMissing.of() + private var vectorStoreId: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from( + organizationUsageFileSearchesResult: OrganizationUsageFileSearchesResult + ) = apply { + numRequests = organizationUsageFileSearchesResult.numRequests + object_ = organizationUsageFileSearchesResult.object_ + apiKeyId = organizationUsageFileSearchesResult.apiKeyId + projectId = organizationUsageFileSearchesResult.projectId + userId = organizationUsageFileSearchesResult.userId + vectorStoreId = organizationUsageFileSearchesResult.vectorStoreId + additionalProperties = + organizationUsageFileSearchesResult.additionalProperties.toMutableMap() + } + + /** The count of file search calls. */ + fun numRequests(numRequests: Long) = numRequests(JsonField.of(numRequests)) + + /** + * Sets [Builder.numRequests] to an arbitrary JSON value. + * + * You should usually call [Builder.numRequests] with a well-typed [Long] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun numRequests(numRequests: JsonField) = apply { + this.numRequests = numRequests + } + + /** + * Sets the field to an arbitrary JSON value. + * + * It is usually unnecessary to call this method because the field defaults to + * the following: + * ```java + * JsonValue.from("organization.usage.file_searches.result") + * ``` + * + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun object_(object_: JsonValue) = apply { this.object_ = object_ } + + /** + * When `group_by=api_key_id`, this field provides the API key ID of the grouped + * usage result. + */ + fun apiKeyId(apiKeyId: String?) = apiKeyId(JsonField.ofNullable(apiKeyId)) + + /** Alias for calling [Builder.apiKeyId] with `apiKeyId.orElse(null)`. */ + fun apiKeyId(apiKeyId: Optional) = apiKeyId(apiKeyId.getOrNull()) + + /** + * Sets [Builder.apiKeyId] to an arbitrary JSON value. + * + * You should usually call [Builder.apiKeyId] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun apiKeyId(apiKeyId: JsonField) = apply { this.apiKeyId = apiKeyId } + + /** + * When `group_by=project_id`, this field provides the project ID of the grouped + * usage result. + */ + fun projectId(projectId: String?) = projectId(JsonField.ofNullable(projectId)) + + /** Alias for calling [Builder.projectId] with `projectId.orElse(null)`. */ + fun projectId(projectId: Optional) = projectId(projectId.getOrNull()) + + /** + * 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 + } + + /** + * When `group_by=user_id`, this field provides the user ID of the grouped usage + * result. + */ + 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 } + + /** + * When `group_by=vector_store_id`, this field provides the vector store ID of + * the grouped usage result. + */ + fun vectorStoreId(vectorStoreId: String?) = + vectorStoreId(JsonField.ofNullable(vectorStoreId)) + + /** + * Alias for calling [Builder.vectorStoreId] with `vectorStoreId.orElse(null)`. + */ + fun vectorStoreId(vectorStoreId: Optional) = + vectorStoreId(vectorStoreId.getOrNull()) + + /** + * Sets [Builder.vectorStoreId] to an arbitrary JSON value. + * + * You should usually call [Builder.vectorStoreId] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun vectorStoreId(vectorStoreId: JsonField) = apply { + this.vectorStoreId = vectorStoreId + } + + 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 [OrganizationUsageFileSearchesResult]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .numRequests() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): OrganizationUsageFileSearchesResult = + OrganizationUsageFileSearchesResult( + checkRequired("numRequests", numRequests), + object_, + apiKeyId, + projectId, + userId, + vectorStoreId, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing + * fields. + * + * @throws OpenAIInvalidDataException if any value type in this object doesn't match + * its expected type. + */ + fun validate(): OrganizationUsageFileSearchesResult = apply { + if (validated) { + return@apply + } + + numRequests() + _object_().let { + if (it != JsonValue.from("organization.usage.file_searches.result")) { + throw OpenAIInvalidDataException("'object_' is invalid, received $it") + } + } + apiKeyId() + projectId() + userId() + vectorStoreId() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OpenAIInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (if (numRequests.asKnown().isPresent) 1 else 0) + + object_.let { + if (it == JsonValue.from("organization.usage.file_searches.result")) 1 + else 0 + } + + (if (apiKeyId.asKnown().isPresent) 1 else 0) + + (if (projectId.asKnown().isPresent) 1 else 0) + + (if (userId.asKnown().isPresent) 1 else 0) + + (if (vectorStoreId.asKnown().isPresent) 1 else 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is OrganizationUsageFileSearchesResult && + numRequests == other.numRequests && + object_ == other.object_ && + apiKeyId == other.apiKeyId && + projectId == other.projectId && + userId == other.userId && + vectorStoreId == other.vectorStoreId && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + numRequests, + object_, + apiKeyId, + projectId, + userId, + vectorStoreId, + additionalProperties, + ) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "OrganizationUsageFileSearchesResult{numRequests=$numRequests, object_=$object_, apiKeyId=$apiKeyId, projectId=$projectId, userId=$userId, vectorStoreId=$vectorStoreId, additionalProperties=$additionalProperties}" + } + + /** The aggregated web search calls usage details of the specific time bucket. */ + class OrganizationUsageWebSearchesResult + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val numModelRequests: JsonField, + private val numRequests: JsonField, + private val object_: JsonValue, + private val apiKeyId: JsonField, + private val contextLevel: JsonField, + private val model: JsonField, + private val projectId: JsonField, + private val userId: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("num_model_requests") + @ExcludeMissing + numModelRequests: JsonField = JsonMissing.of(), + @JsonProperty("num_requests") + @ExcludeMissing + numRequests: JsonField = JsonMissing.of(), + @JsonProperty("object") @ExcludeMissing object_: JsonValue = JsonMissing.of(), + @JsonProperty("api_key_id") + @ExcludeMissing + apiKeyId: JsonField = JsonMissing.of(), + @JsonProperty("context_level") + @ExcludeMissing + contextLevel: JsonField = JsonMissing.of(), + @JsonProperty("model") + @ExcludeMissing + model: JsonField = JsonMissing.of(), + @JsonProperty("project_id") + @ExcludeMissing + projectId: JsonField = JsonMissing.of(), + @JsonProperty("user_id") + @ExcludeMissing + userId: JsonField = JsonMissing.of(), + ) : this( + numModelRequests, + numRequests, + object_, + apiKeyId, + contextLevel, + model, + projectId, + userId, + mutableMapOf(), + ) + + /** + * The count of model requests. + * + * @throws OpenAIInvalidDataException 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 numModelRequests(): Long = numModelRequests.getRequired("num_model_requests") + + /** + * The count of web search calls. + * + * @throws OpenAIInvalidDataException 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 numRequests(): Long = numRequests.getRequired("num_requests") + + /** + * Expected to always return the following: + * ```java + * JsonValue.from("organization.usage.web_searches.result") + * ``` + * + * However, this method can be useful for debugging and logging (e.g. if the server + * responded with an unexpected value). + */ + @JsonProperty("object") @ExcludeMissing fun _object_(): JsonValue = object_ + + /** + * When `group_by=api_key_id`, this field provides the API key ID of the grouped + * usage result. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun apiKeyId(): Optional = apiKeyId.getOptional("api_key_id") + + /** + * When `group_by=context_level`, this field provides the search context size of the + * grouped usage result. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun contextLevel(): Optional = contextLevel.getOptional("context_level") + + /** + * When `group_by=model`, this field provides the model name of the grouped usage + * result. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun model(): Optional = model.getOptional("model") + + /** + * When `group_by=project_id`, this field provides the project ID of the grouped + * usage result. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun projectId(): Optional = projectId.getOptional("project_id") + + /** + * When `group_by=user_id`, this field provides the user ID of the grouped usage + * result. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun userId(): Optional = userId.getOptional("user_id") + + /** + * Returns the raw JSON value of [numModelRequests]. + * + * Unlike [numModelRequests], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("num_model_requests") + @ExcludeMissing + fun _numModelRequests(): JsonField = numModelRequests + + /** + * Returns the raw JSON value of [numRequests]. + * + * Unlike [numRequests], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("num_requests") + @ExcludeMissing + fun _numRequests(): JsonField = numRequests + + /** + * Returns the raw JSON value of [apiKeyId]. + * + * Unlike [apiKeyId], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("api_key_id") + @ExcludeMissing + fun _apiKeyId(): JsonField = apiKeyId + + /** + * Returns the raw JSON value of [contextLevel]. + * + * Unlike [contextLevel], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("context_level") + @ExcludeMissing + fun _contextLevel(): JsonField = contextLevel + + /** + * Returns the raw JSON value of [model]. + * + * Unlike [model], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("model") @ExcludeMissing fun _model(): JsonField = model + + /** + * 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 [userId]. + * + * Unlike [userId], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @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 = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of + * [OrganizationUsageWebSearchesResult]. + * + * The following fields are required: + * ```java + * .numModelRequests() + * .numRequests() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [OrganizationUsageWebSearchesResult]. */ + class Builder internal constructor() { + + private var numModelRequests: JsonField? = null + private var numRequests: JsonField? = null + private var object_: JsonValue = + JsonValue.from("organization.usage.web_searches.result") + private var apiKeyId: JsonField = JsonMissing.of() + private var contextLevel: JsonField = JsonMissing.of() + private var model: JsonField = JsonMissing.of() + private var projectId: JsonField = JsonMissing.of() + private var userId: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from( + organizationUsageWebSearchesResult: OrganizationUsageWebSearchesResult + ) = apply { + numModelRequests = organizationUsageWebSearchesResult.numModelRequests + numRequests = organizationUsageWebSearchesResult.numRequests + object_ = organizationUsageWebSearchesResult.object_ + apiKeyId = organizationUsageWebSearchesResult.apiKeyId + contextLevel = organizationUsageWebSearchesResult.contextLevel + model = organizationUsageWebSearchesResult.model + projectId = organizationUsageWebSearchesResult.projectId + userId = organizationUsageWebSearchesResult.userId + additionalProperties = + organizationUsageWebSearchesResult.additionalProperties.toMutableMap() + } + + /** The count of model requests. */ + fun numModelRequests(numModelRequests: Long) = + numModelRequests(JsonField.of(numModelRequests)) + + /** + * Sets [Builder.numModelRequests] to an arbitrary JSON value. + * + * You should usually call [Builder.numModelRequests] with a well-typed [Long] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun numModelRequests(numModelRequests: JsonField) = apply { + this.numModelRequests = numModelRequests + } + + /** The count of web search calls. */ + fun numRequests(numRequests: Long) = numRequests(JsonField.of(numRequests)) + + /** + * Sets [Builder.numRequests] to an arbitrary JSON value. + * + * You should usually call [Builder.numRequests] with a well-typed [Long] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun numRequests(numRequests: JsonField) = apply { + this.numRequests = numRequests + } + + /** + * Sets the field to an arbitrary JSON value. + * + * It is usually unnecessary to call this method because the field defaults to + * the following: + * ```java + * JsonValue.from("organization.usage.web_searches.result") + * ``` + * + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun object_(object_: JsonValue) = apply { this.object_ = object_ } + + /** + * When `group_by=api_key_id`, this field provides the API key ID of the grouped + * usage result. + */ + fun apiKeyId(apiKeyId: String?) = apiKeyId(JsonField.ofNullable(apiKeyId)) + + /** Alias for calling [Builder.apiKeyId] with `apiKeyId.orElse(null)`. */ + fun apiKeyId(apiKeyId: Optional) = apiKeyId(apiKeyId.getOrNull()) + + /** + * Sets [Builder.apiKeyId] to an arbitrary JSON value. + * + * You should usually call [Builder.apiKeyId] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun apiKeyId(apiKeyId: JsonField) = apply { this.apiKeyId = apiKeyId } + + /** + * When `group_by=context_level`, this field provides the search context size of + * the grouped usage result. + */ + fun contextLevel(contextLevel: String?) = + contextLevel(JsonField.ofNullable(contextLevel)) + + /** + * Alias for calling [Builder.contextLevel] with `contextLevel.orElse(null)`. + */ + fun contextLevel(contextLevel: Optional) = + contextLevel(contextLevel.getOrNull()) + + /** + * Sets [Builder.contextLevel] to an arbitrary JSON value. + * + * You should usually call [Builder.contextLevel] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun contextLevel(contextLevel: JsonField) = apply { + this.contextLevel = contextLevel + } + + /** + * When `group_by=model`, this field provides the model name of the grouped + * usage result. + */ + fun model(model: String?) = model(JsonField.ofNullable(model)) + + /** Alias for calling [Builder.model] with `model.orElse(null)`. */ + fun model(model: Optional) = model(model.getOrNull()) + + /** + * Sets [Builder.model] to an arbitrary JSON value. + * + * You should usually call [Builder.model] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun model(model: JsonField) = apply { this.model = model } + + /** + * When `group_by=project_id`, this field provides the project ID of the grouped + * usage result. + */ + fun projectId(projectId: String?) = projectId(JsonField.ofNullable(projectId)) + + /** Alias for calling [Builder.projectId] with `projectId.orElse(null)`. */ + fun projectId(projectId: Optional) = projectId(projectId.getOrNull()) + + /** + * 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 + } + + /** + * When `group_by=user_id`, this field provides the user ID of the grouped usage + * result. + */ + 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 } + + 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 [OrganizationUsageWebSearchesResult]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .numModelRequests() + * .numRequests() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): OrganizationUsageWebSearchesResult = + OrganizationUsageWebSearchesResult( + checkRequired("numModelRequests", numModelRequests), + checkRequired("numRequests", numRequests), + object_, + apiKeyId, + contextLevel, + model, + projectId, + userId, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing + * fields. + * + * @throws OpenAIInvalidDataException if any value type in this object doesn't match + * its expected type. + */ + fun validate(): OrganizationUsageWebSearchesResult = apply { + if (validated) { + return@apply + } + + numModelRequests() + numRequests() + _object_().let { + if (it != JsonValue.from("organization.usage.web_searches.result")) { + throw OpenAIInvalidDataException("'object_' is invalid, received $it") + } + } + apiKeyId() + contextLevel() + model() + projectId() + userId() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OpenAIInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (if (numModelRequests.asKnown().isPresent) 1 else 0) + + (if (numRequests.asKnown().isPresent) 1 else 0) + + object_.let { + if (it == JsonValue.from("organization.usage.web_searches.result")) 1 + else 0 + } + + (if (apiKeyId.asKnown().isPresent) 1 else 0) + + (if (contextLevel.asKnown().isPresent) 1 else 0) + + (if (model.asKnown().isPresent) 1 else 0) + + (if (projectId.asKnown().isPresent) 1 else 0) + + (if (userId.asKnown().isPresent) 1 else 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is OrganizationUsageWebSearchesResult && + numModelRequests == other.numModelRequests && + numRequests == other.numRequests && + object_ == other.object_ && + apiKeyId == other.apiKeyId && + contextLevel == other.contextLevel && + model == other.model && + projectId == other.projectId && + userId == other.userId && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + numModelRequests, + numRequests, + object_, + apiKeyId, + contextLevel, + model, + projectId, + userId, + additionalProperties, + ) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "OrganizationUsageWebSearchesResult{numModelRequests=$numModelRequests, numRequests=$numRequests, object_=$object_, apiKeyId=$apiKeyId, contextLevel=$contextLevel, model=$model, projectId=$projectId, userId=$userId, additionalProperties=$additionalProperties}" + } + /** The aggregated costs details of the specific time bucket. */ class OrganizationCostsResult @JsonCreator(mode = JsonCreator.Mode.DISABLED) diff --git a/openai-java-core/src/main/kotlin/com/openai/models/admin/organization/usage/UsageAudioTranscriptionsResponse.kt b/openai-java-core/src/main/kotlin/com/openai/models/admin/organization/usage/UsageAudioTranscriptionsResponse.kt index 069f27748..77bce8b5c 100644 --- a/openai-java-core/src/main/kotlin/com/openai/models/admin/organization/usage/UsageAudioTranscriptionsResponse.kt +++ b/openai-java-core/src/main/kotlin/com/openai/models/admin/organization/usage/UsageAudioTranscriptionsResponse.kt @@ -564,6 +564,36 @@ private constructor( .build() ) + /** + * Alias for calling [addResult] with + * `Result.ofOrganizationUsageFileSearches(organizationUsageFileSearches)`. + */ + fun addResult( + organizationUsageFileSearches: Result.OrganizationUsageFileSearchesResult + ) = addResult(Result.ofOrganizationUsageFileSearches(organizationUsageFileSearches)) + + /** + * Alias for calling [addResult] with the following: + * ```java + * Result.OrganizationUsageFileSearchesResult.builder() + * .numRequests(numRequests) + * .build() + * ``` + */ + fun addOrganizationUsageFileSearchesResult(numRequests: Long) = + addResult( + Result.OrganizationUsageFileSearchesResult.builder() + .numRequests(numRequests) + .build() + ) + + /** + * Alias for calling [addResult] with + * `Result.ofOrganizationUsageWebSearches(organizationUsageWebSearches)`. + */ + fun addResult(organizationUsageWebSearches: Result.OrganizationUsageWebSearchesResult) = + addResult(Result.ofOrganizationUsageWebSearches(organizationUsageWebSearches)) + /** * Alias for calling [addResult] with `Result.ofOrganizationCosts(organizationCosts)`. */ @@ -690,6 +720,8 @@ private constructor( private val organizationUsageCodeInterpreterSessions: OrganizationUsageCodeInterpreterSessionsResult? = null, + private val organizationUsageFileSearches: OrganizationUsageFileSearchesResult? = null, + private val organizationUsageWebSearches: OrganizationUsageWebSearchesResult? = null, private val organizationCosts: OrganizationCostsResult? = null, private val _json: JsonValue? = null, ) { @@ -730,6 +762,14 @@ private constructor( Optional = Optional.ofNullable(organizationUsageCodeInterpreterSessions) + /** The aggregated file search calls usage details of the specific time bucket. */ + fun organizationUsageFileSearches(): Optional = + Optional.ofNullable(organizationUsageFileSearches) + + /** The aggregated web search calls usage details of the specific time bucket. */ + fun organizationUsageWebSearches(): Optional = + Optional.ofNullable(organizationUsageWebSearches) + /** The aggregated costs details of the specific time bucket. */ fun organizationCosts(): Optional = Optional.ofNullable(organizationCosts) @@ -752,6 +792,10 @@ private constructor( fun isOrganizationUsageCodeInterpreterSessions(): Boolean = organizationUsageCodeInterpreterSessions != null + fun isOrganizationUsageFileSearches(): Boolean = organizationUsageFileSearches != null + + fun isOrganizationUsageWebSearches(): Boolean = organizationUsageWebSearches != null + fun isOrganizationCosts(): Boolean = organizationCosts != null /** The aggregated completions usage details of the specific time bucket. */ @@ -794,6 +838,14 @@ private constructor( "organizationUsageCodeInterpreterSessions" ) + /** The aggregated file search calls usage details of the specific time bucket. */ + fun asOrganizationUsageFileSearches(): OrganizationUsageFileSearchesResult = + organizationUsageFileSearches.getOrThrow("organizationUsageFileSearches") + + /** The aggregated web search calls usage details of the specific time bucket. */ + fun asOrganizationUsageWebSearches(): OrganizationUsageWebSearchesResult = + organizationUsageWebSearches.getOrThrow("organizationUsageWebSearches") + /** The aggregated costs details of the specific time bucket. */ fun asOrganizationCosts(): OrganizationCostsResult = organizationCosts.getOrThrow("organizationCosts") @@ -852,6 +904,10 @@ private constructor( visitor.visitOrganizationUsageCodeInterpreterSessions( organizationUsageCodeInterpreterSessions ) + organizationUsageFileSearches != null -> + visitor.visitOrganizationUsageFileSearches(organizationUsageFileSearches) + organizationUsageWebSearches != null -> + visitor.visitOrganizationUsageWebSearches(organizationUsageWebSearches) organizationCosts != null -> visitor.visitOrganizationCosts(organizationCosts) else -> visitor.unknown(_json) } @@ -925,6 +981,18 @@ private constructor( organizationUsageCodeInterpreterSessions.validate() } + override fun visitOrganizationUsageFileSearches( + organizationUsageFileSearches: OrganizationUsageFileSearchesResult + ) { + organizationUsageFileSearches.validate() + } + + override fun visitOrganizationUsageWebSearches( + organizationUsageWebSearches: OrganizationUsageWebSearchesResult + ) { + organizationUsageWebSearches.validate() + } + override fun visitOrganizationCosts( organizationCosts: OrganizationCostsResult ) { @@ -987,6 +1055,14 @@ private constructor( OrganizationUsageCodeInterpreterSessionsResult ) = organizationUsageCodeInterpreterSessions.validity() + override fun visitOrganizationUsageFileSearches( + organizationUsageFileSearches: OrganizationUsageFileSearchesResult + ) = organizationUsageFileSearches.validity() + + override fun visitOrganizationUsageWebSearches( + organizationUsageWebSearches: OrganizationUsageWebSearchesResult + ) = organizationUsageWebSearches.validity() + override fun visitOrganizationCosts( organizationCosts: OrganizationCostsResult ) = organizationCosts.validity() @@ -1011,6 +1087,8 @@ private constructor( organizationUsageVectorStores == other.organizationUsageVectorStores && organizationUsageCodeInterpreterSessions == other.organizationUsageCodeInterpreterSessions && + organizationUsageFileSearches == other.organizationUsageFileSearches && + organizationUsageWebSearches == other.organizationUsageWebSearches && organizationCosts == other.organizationCosts } @@ -1024,6 +1102,8 @@ private constructor( organizationUsageAudioTranscriptions, organizationUsageVectorStores, organizationUsageCodeInterpreterSessions, + organizationUsageFileSearches, + organizationUsageWebSearches, organizationCosts, ) @@ -1045,6 +1125,10 @@ private constructor( "Result{organizationUsageVectorStores=$organizationUsageVectorStores}" organizationUsageCodeInterpreterSessions != null -> "Result{organizationUsageCodeInterpreterSessions=$organizationUsageCodeInterpreterSessions}" + organizationUsageFileSearches != null -> + "Result{organizationUsageFileSearches=$organizationUsageFileSearches}" + organizationUsageWebSearches != null -> + "Result{organizationUsageWebSearches=$organizationUsageWebSearches}" organizationCosts != null -> "Result{organizationCosts=$organizationCosts}" _json != null -> "Result{_unknown=$_json}" else -> throw IllegalStateException("Invalid Result") @@ -1113,6 +1197,18 @@ private constructor( organizationUsageCodeInterpreterSessions ) + /** The aggregated file search calls usage details of the specific time bucket. */ + @JvmStatic + fun ofOrganizationUsageFileSearches( + organizationUsageFileSearches: OrganizationUsageFileSearchesResult + ) = Result(organizationUsageFileSearches = organizationUsageFileSearches) + + /** The aggregated web search calls usage details of the specific time bucket. */ + @JvmStatic + fun ofOrganizationUsageWebSearches( + organizationUsageWebSearches: OrganizationUsageWebSearchesResult + ) = Result(organizationUsageWebSearches = organizationUsageWebSearches) + /** The aggregated costs details of the specific time bucket. */ @JvmStatic fun ofOrganizationCosts(organizationCosts: OrganizationCostsResult) = @@ -1170,6 +1266,16 @@ private constructor( OrganizationUsageCodeInterpreterSessionsResult ): T + /** The aggregated file search calls usage details of the specific time bucket. */ + fun visitOrganizationUsageFileSearches( + organizationUsageFileSearches: OrganizationUsageFileSearchesResult + ): T + + /** The aggregated web search calls usage details of the specific time bucket. */ + fun visitOrganizationUsageWebSearches( + organizationUsageWebSearches: OrganizationUsageWebSearchesResult + ): T + /** The aggregated costs details of the specific time bucket. */ fun visitOrganizationCosts(organizationCosts: OrganizationCostsResult): T @@ -1265,6 +1371,22 @@ private constructor( ) } ?: Result(_json = json) } + "organization.usage.file_searches.result" -> { + return tryDeserialize( + node, + jacksonTypeRef(), + ) + ?.let { Result(organizationUsageFileSearches = it, _json = json) } + ?: Result(_json = json) + } + "organization.usage.web_searches.result" -> { + return tryDeserialize( + node, + jacksonTypeRef(), + ) + ?.let { Result(organizationUsageWebSearches = it, _json = json) } + ?: Result(_json = json) + } "organization.costs.result" -> { return tryDeserialize(node, jacksonTypeRef()) ?.let { Result(organizationCosts = it, _json = json) } @@ -1300,6 +1422,10 @@ private constructor( generator.writeObject(value.organizationUsageVectorStores) value.organizationUsageCodeInterpreterSessions != null -> generator.writeObject(value.organizationUsageCodeInterpreterSessions) + value.organizationUsageFileSearches != null -> + generator.writeObject(value.organizationUsageFileSearches) + value.organizationUsageWebSearches != null -> + generator.writeObject(value.organizationUsageWebSearches) value.organizationCosts != null -> generator.writeObject(value.organizationCosts) value._json != null -> generator.writeObject(value._json) @@ -5165,6 +5291,981 @@ private constructor( "OrganizationUsageCodeInterpreterSessionsResult{numSessions=$numSessions, object_=$object_, projectId=$projectId, additionalProperties=$additionalProperties}" } + /** The aggregated file search calls usage details of the specific time bucket. */ + class OrganizationUsageFileSearchesResult + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val numRequests: JsonField, + private val object_: JsonValue, + private val apiKeyId: JsonField, + private val projectId: JsonField, + private val userId: JsonField, + private val vectorStoreId: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("num_requests") + @ExcludeMissing + numRequests: JsonField = JsonMissing.of(), + @JsonProperty("object") @ExcludeMissing object_: JsonValue = JsonMissing.of(), + @JsonProperty("api_key_id") + @ExcludeMissing + apiKeyId: JsonField = JsonMissing.of(), + @JsonProperty("project_id") + @ExcludeMissing + projectId: JsonField = JsonMissing.of(), + @JsonProperty("user_id") + @ExcludeMissing + userId: JsonField = JsonMissing.of(), + @JsonProperty("vector_store_id") + @ExcludeMissing + vectorStoreId: JsonField = JsonMissing.of(), + ) : this( + numRequests, + object_, + apiKeyId, + projectId, + userId, + vectorStoreId, + mutableMapOf(), + ) + + /** + * The count of file search calls. + * + * @throws OpenAIInvalidDataException 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 numRequests(): Long = numRequests.getRequired("num_requests") + + /** + * Expected to always return the following: + * ```java + * JsonValue.from("organization.usage.file_searches.result") + * ``` + * + * However, this method can be useful for debugging and logging (e.g. if the server + * responded with an unexpected value). + */ + @JsonProperty("object") @ExcludeMissing fun _object_(): JsonValue = object_ + + /** + * When `group_by=api_key_id`, this field provides the API key ID of the grouped + * usage result. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun apiKeyId(): Optional = apiKeyId.getOptional("api_key_id") + + /** + * When `group_by=project_id`, this field provides the project ID of the grouped + * usage result. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun projectId(): Optional = projectId.getOptional("project_id") + + /** + * When `group_by=user_id`, this field provides the user ID of the grouped usage + * result. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun userId(): Optional = userId.getOptional("user_id") + + /** + * When `group_by=vector_store_id`, this field provides the vector store ID of the + * grouped usage result. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun vectorStoreId(): Optional = vectorStoreId.getOptional("vector_store_id") + + /** + * Returns the raw JSON value of [numRequests]. + * + * Unlike [numRequests], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("num_requests") + @ExcludeMissing + fun _numRequests(): JsonField = numRequests + + /** + * Returns the raw JSON value of [apiKeyId]. + * + * Unlike [apiKeyId], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("api_key_id") + @ExcludeMissing + fun _apiKeyId(): JsonField = apiKeyId + + /** + * 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 [userId]. + * + * Unlike [userId], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("user_id") @ExcludeMissing fun _userId(): JsonField = userId + + /** + * Returns the raw JSON value of [vectorStoreId]. + * + * Unlike [vectorStoreId], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("vector_store_id") + @ExcludeMissing + fun _vectorStoreId(): JsonField = vectorStoreId + + @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 + * [OrganizationUsageFileSearchesResult]. + * + * The following fields are required: + * ```java + * .numRequests() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [OrganizationUsageFileSearchesResult]. */ + class Builder internal constructor() { + + private var numRequests: JsonField? = null + private var object_: JsonValue = + JsonValue.from("organization.usage.file_searches.result") + private var apiKeyId: JsonField = JsonMissing.of() + private var projectId: JsonField = JsonMissing.of() + private var userId: JsonField = JsonMissing.of() + private var vectorStoreId: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from( + organizationUsageFileSearchesResult: OrganizationUsageFileSearchesResult + ) = apply { + numRequests = organizationUsageFileSearchesResult.numRequests + object_ = organizationUsageFileSearchesResult.object_ + apiKeyId = organizationUsageFileSearchesResult.apiKeyId + projectId = organizationUsageFileSearchesResult.projectId + userId = organizationUsageFileSearchesResult.userId + vectorStoreId = organizationUsageFileSearchesResult.vectorStoreId + additionalProperties = + organizationUsageFileSearchesResult.additionalProperties.toMutableMap() + } + + /** The count of file search calls. */ + fun numRequests(numRequests: Long) = numRequests(JsonField.of(numRequests)) + + /** + * Sets [Builder.numRequests] to an arbitrary JSON value. + * + * You should usually call [Builder.numRequests] with a well-typed [Long] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun numRequests(numRequests: JsonField) = apply { + this.numRequests = numRequests + } + + /** + * Sets the field to an arbitrary JSON value. + * + * It is usually unnecessary to call this method because the field defaults to + * the following: + * ```java + * JsonValue.from("organization.usage.file_searches.result") + * ``` + * + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun object_(object_: JsonValue) = apply { this.object_ = object_ } + + /** + * When `group_by=api_key_id`, this field provides the API key ID of the grouped + * usage result. + */ + fun apiKeyId(apiKeyId: String?) = apiKeyId(JsonField.ofNullable(apiKeyId)) + + /** Alias for calling [Builder.apiKeyId] with `apiKeyId.orElse(null)`. */ + fun apiKeyId(apiKeyId: Optional) = apiKeyId(apiKeyId.getOrNull()) + + /** + * Sets [Builder.apiKeyId] to an arbitrary JSON value. + * + * You should usually call [Builder.apiKeyId] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun apiKeyId(apiKeyId: JsonField) = apply { this.apiKeyId = apiKeyId } + + /** + * When `group_by=project_id`, this field provides the project ID of the grouped + * usage result. + */ + fun projectId(projectId: String?) = projectId(JsonField.ofNullable(projectId)) + + /** Alias for calling [Builder.projectId] with `projectId.orElse(null)`. */ + fun projectId(projectId: Optional) = projectId(projectId.getOrNull()) + + /** + * 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 + } + + /** + * When `group_by=user_id`, this field provides the user ID of the grouped usage + * result. + */ + 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 } + + /** + * When `group_by=vector_store_id`, this field provides the vector store ID of + * the grouped usage result. + */ + fun vectorStoreId(vectorStoreId: String?) = + vectorStoreId(JsonField.ofNullable(vectorStoreId)) + + /** + * Alias for calling [Builder.vectorStoreId] with `vectorStoreId.orElse(null)`. + */ + fun vectorStoreId(vectorStoreId: Optional) = + vectorStoreId(vectorStoreId.getOrNull()) + + /** + * Sets [Builder.vectorStoreId] to an arbitrary JSON value. + * + * You should usually call [Builder.vectorStoreId] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun vectorStoreId(vectorStoreId: JsonField) = apply { + this.vectorStoreId = vectorStoreId + } + + 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 [OrganizationUsageFileSearchesResult]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .numRequests() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): OrganizationUsageFileSearchesResult = + OrganizationUsageFileSearchesResult( + checkRequired("numRequests", numRequests), + object_, + apiKeyId, + projectId, + userId, + vectorStoreId, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing + * fields. + * + * @throws OpenAIInvalidDataException if any value type in this object doesn't match + * its expected type. + */ + fun validate(): OrganizationUsageFileSearchesResult = apply { + if (validated) { + return@apply + } + + numRequests() + _object_().let { + if (it != JsonValue.from("organization.usage.file_searches.result")) { + throw OpenAIInvalidDataException("'object_' is invalid, received $it") + } + } + apiKeyId() + projectId() + userId() + vectorStoreId() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OpenAIInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (if (numRequests.asKnown().isPresent) 1 else 0) + + object_.let { + if (it == JsonValue.from("organization.usage.file_searches.result")) 1 + else 0 + } + + (if (apiKeyId.asKnown().isPresent) 1 else 0) + + (if (projectId.asKnown().isPresent) 1 else 0) + + (if (userId.asKnown().isPresent) 1 else 0) + + (if (vectorStoreId.asKnown().isPresent) 1 else 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is OrganizationUsageFileSearchesResult && + numRequests == other.numRequests && + object_ == other.object_ && + apiKeyId == other.apiKeyId && + projectId == other.projectId && + userId == other.userId && + vectorStoreId == other.vectorStoreId && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + numRequests, + object_, + apiKeyId, + projectId, + userId, + vectorStoreId, + additionalProperties, + ) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "OrganizationUsageFileSearchesResult{numRequests=$numRequests, object_=$object_, apiKeyId=$apiKeyId, projectId=$projectId, userId=$userId, vectorStoreId=$vectorStoreId, additionalProperties=$additionalProperties}" + } + + /** The aggregated web search calls usage details of the specific time bucket. */ + class OrganizationUsageWebSearchesResult + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val numModelRequests: JsonField, + private val numRequests: JsonField, + private val object_: JsonValue, + private val apiKeyId: JsonField, + private val contextLevel: JsonField, + private val model: JsonField, + private val projectId: JsonField, + private val userId: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("num_model_requests") + @ExcludeMissing + numModelRequests: JsonField = JsonMissing.of(), + @JsonProperty("num_requests") + @ExcludeMissing + numRequests: JsonField = JsonMissing.of(), + @JsonProperty("object") @ExcludeMissing object_: JsonValue = JsonMissing.of(), + @JsonProperty("api_key_id") + @ExcludeMissing + apiKeyId: JsonField = JsonMissing.of(), + @JsonProperty("context_level") + @ExcludeMissing + contextLevel: JsonField = JsonMissing.of(), + @JsonProperty("model") + @ExcludeMissing + model: JsonField = JsonMissing.of(), + @JsonProperty("project_id") + @ExcludeMissing + projectId: JsonField = JsonMissing.of(), + @JsonProperty("user_id") + @ExcludeMissing + userId: JsonField = JsonMissing.of(), + ) : this( + numModelRequests, + numRequests, + object_, + apiKeyId, + contextLevel, + model, + projectId, + userId, + mutableMapOf(), + ) + + /** + * The count of model requests. + * + * @throws OpenAIInvalidDataException 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 numModelRequests(): Long = numModelRequests.getRequired("num_model_requests") + + /** + * The count of web search calls. + * + * @throws OpenAIInvalidDataException 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 numRequests(): Long = numRequests.getRequired("num_requests") + + /** + * Expected to always return the following: + * ```java + * JsonValue.from("organization.usage.web_searches.result") + * ``` + * + * However, this method can be useful for debugging and logging (e.g. if the server + * responded with an unexpected value). + */ + @JsonProperty("object") @ExcludeMissing fun _object_(): JsonValue = object_ + + /** + * When `group_by=api_key_id`, this field provides the API key ID of the grouped + * usage result. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun apiKeyId(): Optional = apiKeyId.getOptional("api_key_id") + + /** + * When `group_by=context_level`, this field provides the search context size of the + * grouped usage result. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun contextLevel(): Optional = contextLevel.getOptional("context_level") + + /** + * When `group_by=model`, this field provides the model name of the grouped usage + * result. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun model(): Optional = model.getOptional("model") + + /** + * When `group_by=project_id`, this field provides the project ID of the grouped + * usage result. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun projectId(): Optional = projectId.getOptional("project_id") + + /** + * When `group_by=user_id`, this field provides the user ID of the grouped usage + * result. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun userId(): Optional = userId.getOptional("user_id") + + /** + * Returns the raw JSON value of [numModelRequests]. + * + * Unlike [numModelRequests], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("num_model_requests") + @ExcludeMissing + fun _numModelRequests(): JsonField = numModelRequests + + /** + * Returns the raw JSON value of [numRequests]. + * + * Unlike [numRequests], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("num_requests") + @ExcludeMissing + fun _numRequests(): JsonField = numRequests + + /** + * Returns the raw JSON value of [apiKeyId]. + * + * Unlike [apiKeyId], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("api_key_id") + @ExcludeMissing + fun _apiKeyId(): JsonField = apiKeyId + + /** + * Returns the raw JSON value of [contextLevel]. + * + * Unlike [contextLevel], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("context_level") + @ExcludeMissing + fun _contextLevel(): JsonField = contextLevel + + /** + * Returns the raw JSON value of [model]. + * + * Unlike [model], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("model") @ExcludeMissing fun _model(): JsonField = model + + /** + * 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 [userId]. + * + * Unlike [userId], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @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 = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of + * [OrganizationUsageWebSearchesResult]. + * + * The following fields are required: + * ```java + * .numModelRequests() + * .numRequests() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [OrganizationUsageWebSearchesResult]. */ + class Builder internal constructor() { + + private var numModelRequests: JsonField? = null + private var numRequests: JsonField? = null + private var object_: JsonValue = + JsonValue.from("organization.usage.web_searches.result") + private var apiKeyId: JsonField = JsonMissing.of() + private var contextLevel: JsonField = JsonMissing.of() + private var model: JsonField = JsonMissing.of() + private var projectId: JsonField = JsonMissing.of() + private var userId: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from( + organizationUsageWebSearchesResult: OrganizationUsageWebSearchesResult + ) = apply { + numModelRequests = organizationUsageWebSearchesResult.numModelRequests + numRequests = organizationUsageWebSearchesResult.numRequests + object_ = organizationUsageWebSearchesResult.object_ + apiKeyId = organizationUsageWebSearchesResult.apiKeyId + contextLevel = organizationUsageWebSearchesResult.contextLevel + model = organizationUsageWebSearchesResult.model + projectId = organizationUsageWebSearchesResult.projectId + userId = organizationUsageWebSearchesResult.userId + additionalProperties = + organizationUsageWebSearchesResult.additionalProperties.toMutableMap() + } + + /** The count of model requests. */ + fun numModelRequests(numModelRequests: Long) = + numModelRequests(JsonField.of(numModelRequests)) + + /** + * Sets [Builder.numModelRequests] to an arbitrary JSON value. + * + * You should usually call [Builder.numModelRequests] with a well-typed [Long] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun numModelRequests(numModelRequests: JsonField) = apply { + this.numModelRequests = numModelRequests + } + + /** The count of web search calls. */ + fun numRequests(numRequests: Long) = numRequests(JsonField.of(numRequests)) + + /** + * Sets [Builder.numRequests] to an arbitrary JSON value. + * + * You should usually call [Builder.numRequests] with a well-typed [Long] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun numRequests(numRequests: JsonField) = apply { + this.numRequests = numRequests + } + + /** + * Sets the field to an arbitrary JSON value. + * + * It is usually unnecessary to call this method because the field defaults to + * the following: + * ```java + * JsonValue.from("organization.usage.web_searches.result") + * ``` + * + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun object_(object_: JsonValue) = apply { this.object_ = object_ } + + /** + * When `group_by=api_key_id`, this field provides the API key ID of the grouped + * usage result. + */ + fun apiKeyId(apiKeyId: String?) = apiKeyId(JsonField.ofNullable(apiKeyId)) + + /** Alias for calling [Builder.apiKeyId] with `apiKeyId.orElse(null)`. */ + fun apiKeyId(apiKeyId: Optional) = apiKeyId(apiKeyId.getOrNull()) + + /** + * Sets [Builder.apiKeyId] to an arbitrary JSON value. + * + * You should usually call [Builder.apiKeyId] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun apiKeyId(apiKeyId: JsonField) = apply { this.apiKeyId = apiKeyId } + + /** + * When `group_by=context_level`, this field provides the search context size of + * the grouped usage result. + */ + fun contextLevel(contextLevel: String?) = + contextLevel(JsonField.ofNullable(contextLevel)) + + /** + * Alias for calling [Builder.contextLevel] with `contextLevel.orElse(null)`. + */ + fun contextLevel(contextLevel: Optional) = + contextLevel(contextLevel.getOrNull()) + + /** + * Sets [Builder.contextLevel] to an arbitrary JSON value. + * + * You should usually call [Builder.contextLevel] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun contextLevel(contextLevel: JsonField) = apply { + this.contextLevel = contextLevel + } + + /** + * When `group_by=model`, this field provides the model name of the grouped + * usage result. + */ + fun model(model: String?) = model(JsonField.ofNullable(model)) + + /** Alias for calling [Builder.model] with `model.orElse(null)`. */ + fun model(model: Optional) = model(model.getOrNull()) + + /** + * Sets [Builder.model] to an arbitrary JSON value. + * + * You should usually call [Builder.model] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun model(model: JsonField) = apply { this.model = model } + + /** + * When `group_by=project_id`, this field provides the project ID of the grouped + * usage result. + */ + fun projectId(projectId: String?) = projectId(JsonField.ofNullable(projectId)) + + /** Alias for calling [Builder.projectId] with `projectId.orElse(null)`. */ + fun projectId(projectId: Optional) = projectId(projectId.getOrNull()) + + /** + * 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 + } + + /** + * When `group_by=user_id`, this field provides the user ID of the grouped usage + * result. + */ + 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 } + + 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 [OrganizationUsageWebSearchesResult]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .numModelRequests() + * .numRequests() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): OrganizationUsageWebSearchesResult = + OrganizationUsageWebSearchesResult( + checkRequired("numModelRequests", numModelRequests), + checkRequired("numRequests", numRequests), + object_, + apiKeyId, + contextLevel, + model, + projectId, + userId, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing + * fields. + * + * @throws OpenAIInvalidDataException if any value type in this object doesn't match + * its expected type. + */ + fun validate(): OrganizationUsageWebSearchesResult = apply { + if (validated) { + return@apply + } + + numModelRequests() + numRequests() + _object_().let { + if (it != JsonValue.from("organization.usage.web_searches.result")) { + throw OpenAIInvalidDataException("'object_' is invalid, received $it") + } + } + apiKeyId() + contextLevel() + model() + projectId() + userId() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OpenAIInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (if (numModelRequests.asKnown().isPresent) 1 else 0) + + (if (numRequests.asKnown().isPresent) 1 else 0) + + object_.let { + if (it == JsonValue.from("organization.usage.web_searches.result")) 1 + else 0 + } + + (if (apiKeyId.asKnown().isPresent) 1 else 0) + + (if (contextLevel.asKnown().isPresent) 1 else 0) + + (if (model.asKnown().isPresent) 1 else 0) + + (if (projectId.asKnown().isPresent) 1 else 0) + + (if (userId.asKnown().isPresent) 1 else 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is OrganizationUsageWebSearchesResult && + numModelRequests == other.numModelRequests && + numRequests == other.numRequests && + object_ == other.object_ && + apiKeyId == other.apiKeyId && + contextLevel == other.contextLevel && + model == other.model && + projectId == other.projectId && + userId == other.userId && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + numModelRequests, + numRequests, + object_, + apiKeyId, + contextLevel, + model, + projectId, + userId, + additionalProperties, + ) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "OrganizationUsageWebSearchesResult{numModelRequests=$numModelRequests, numRequests=$numRequests, object_=$object_, apiKeyId=$apiKeyId, contextLevel=$contextLevel, model=$model, projectId=$projectId, userId=$userId, additionalProperties=$additionalProperties}" + } + /** The aggregated costs details of the specific time bucket. */ class OrganizationCostsResult @JsonCreator(mode = JsonCreator.Mode.DISABLED) diff --git a/openai-java-core/src/main/kotlin/com/openai/models/admin/organization/usage/UsageCodeInterpreterSessionsResponse.kt b/openai-java-core/src/main/kotlin/com/openai/models/admin/organization/usage/UsageCodeInterpreterSessionsResponse.kt index c7256b358..b3eea02e2 100644 --- a/openai-java-core/src/main/kotlin/com/openai/models/admin/organization/usage/UsageCodeInterpreterSessionsResponse.kt +++ b/openai-java-core/src/main/kotlin/com/openai/models/admin/organization/usage/UsageCodeInterpreterSessionsResponse.kt @@ -565,6 +565,36 @@ private constructor( .build() ) + /** + * Alias for calling [addResult] with + * `Result.ofOrganizationUsageFileSearches(organizationUsageFileSearches)`. + */ + fun addResult( + organizationUsageFileSearches: Result.OrganizationUsageFileSearchesResult + ) = addResult(Result.ofOrganizationUsageFileSearches(organizationUsageFileSearches)) + + /** + * Alias for calling [addResult] with the following: + * ```java + * Result.OrganizationUsageFileSearchesResult.builder() + * .numRequests(numRequests) + * .build() + * ``` + */ + fun addOrganizationUsageFileSearchesResult(numRequests: Long) = + addResult( + Result.OrganizationUsageFileSearchesResult.builder() + .numRequests(numRequests) + .build() + ) + + /** + * Alias for calling [addResult] with + * `Result.ofOrganizationUsageWebSearches(organizationUsageWebSearches)`. + */ + fun addResult(organizationUsageWebSearches: Result.OrganizationUsageWebSearchesResult) = + addResult(Result.ofOrganizationUsageWebSearches(organizationUsageWebSearches)) + /** * Alias for calling [addResult] with `Result.ofOrganizationCosts(organizationCosts)`. */ @@ -691,6 +721,8 @@ private constructor( private val organizationUsageCodeInterpreterSessions: OrganizationUsageCodeInterpreterSessionsResult? = null, + private val organizationUsageFileSearches: OrganizationUsageFileSearchesResult? = null, + private val organizationUsageWebSearches: OrganizationUsageWebSearchesResult? = null, private val organizationCosts: OrganizationCostsResult? = null, private val _json: JsonValue? = null, ) { @@ -731,6 +763,14 @@ private constructor( Optional = Optional.ofNullable(organizationUsageCodeInterpreterSessions) + /** The aggregated file search calls usage details of the specific time bucket. */ + fun organizationUsageFileSearches(): Optional = + Optional.ofNullable(organizationUsageFileSearches) + + /** The aggregated web search calls usage details of the specific time bucket. */ + fun organizationUsageWebSearches(): Optional = + Optional.ofNullable(organizationUsageWebSearches) + /** The aggregated costs details of the specific time bucket. */ fun organizationCosts(): Optional = Optional.ofNullable(organizationCosts) @@ -753,6 +793,10 @@ private constructor( fun isOrganizationUsageCodeInterpreterSessions(): Boolean = organizationUsageCodeInterpreterSessions != null + fun isOrganizationUsageFileSearches(): Boolean = organizationUsageFileSearches != null + + fun isOrganizationUsageWebSearches(): Boolean = organizationUsageWebSearches != null + fun isOrganizationCosts(): Boolean = organizationCosts != null /** The aggregated completions usage details of the specific time bucket. */ @@ -795,6 +839,14 @@ private constructor( "organizationUsageCodeInterpreterSessions" ) + /** The aggregated file search calls usage details of the specific time bucket. */ + fun asOrganizationUsageFileSearches(): OrganizationUsageFileSearchesResult = + organizationUsageFileSearches.getOrThrow("organizationUsageFileSearches") + + /** The aggregated web search calls usage details of the specific time bucket. */ + fun asOrganizationUsageWebSearches(): OrganizationUsageWebSearchesResult = + organizationUsageWebSearches.getOrThrow("organizationUsageWebSearches") + /** The aggregated costs details of the specific time bucket. */ fun asOrganizationCosts(): OrganizationCostsResult = organizationCosts.getOrThrow("organizationCosts") @@ -853,6 +905,10 @@ private constructor( visitor.visitOrganizationUsageCodeInterpreterSessions( organizationUsageCodeInterpreterSessions ) + organizationUsageFileSearches != null -> + visitor.visitOrganizationUsageFileSearches(organizationUsageFileSearches) + organizationUsageWebSearches != null -> + visitor.visitOrganizationUsageWebSearches(organizationUsageWebSearches) organizationCosts != null -> visitor.visitOrganizationCosts(organizationCosts) else -> visitor.unknown(_json) } @@ -926,6 +982,18 @@ private constructor( organizationUsageCodeInterpreterSessions.validate() } + override fun visitOrganizationUsageFileSearches( + organizationUsageFileSearches: OrganizationUsageFileSearchesResult + ) { + organizationUsageFileSearches.validate() + } + + override fun visitOrganizationUsageWebSearches( + organizationUsageWebSearches: OrganizationUsageWebSearchesResult + ) { + organizationUsageWebSearches.validate() + } + override fun visitOrganizationCosts( organizationCosts: OrganizationCostsResult ) { @@ -988,6 +1056,14 @@ private constructor( OrganizationUsageCodeInterpreterSessionsResult ) = organizationUsageCodeInterpreterSessions.validity() + override fun visitOrganizationUsageFileSearches( + organizationUsageFileSearches: OrganizationUsageFileSearchesResult + ) = organizationUsageFileSearches.validity() + + override fun visitOrganizationUsageWebSearches( + organizationUsageWebSearches: OrganizationUsageWebSearchesResult + ) = organizationUsageWebSearches.validity() + override fun visitOrganizationCosts( organizationCosts: OrganizationCostsResult ) = organizationCosts.validity() @@ -1012,6 +1088,8 @@ private constructor( organizationUsageVectorStores == other.organizationUsageVectorStores && organizationUsageCodeInterpreterSessions == other.organizationUsageCodeInterpreterSessions && + organizationUsageFileSearches == other.organizationUsageFileSearches && + organizationUsageWebSearches == other.organizationUsageWebSearches && organizationCosts == other.organizationCosts } @@ -1025,6 +1103,8 @@ private constructor( organizationUsageAudioTranscriptions, organizationUsageVectorStores, organizationUsageCodeInterpreterSessions, + organizationUsageFileSearches, + organizationUsageWebSearches, organizationCosts, ) @@ -1046,6 +1126,10 @@ private constructor( "Result{organizationUsageVectorStores=$organizationUsageVectorStores}" organizationUsageCodeInterpreterSessions != null -> "Result{organizationUsageCodeInterpreterSessions=$organizationUsageCodeInterpreterSessions}" + organizationUsageFileSearches != null -> + "Result{organizationUsageFileSearches=$organizationUsageFileSearches}" + organizationUsageWebSearches != null -> + "Result{organizationUsageWebSearches=$organizationUsageWebSearches}" organizationCosts != null -> "Result{organizationCosts=$organizationCosts}" _json != null -> "Result{_unknown=$_json}" else -> throw IllegalStateException("Invalid Result") @@ -1114,6 +1198,18 @@ private constructor( organizationUsageCodeInterpreterSessions ) + /** The aggregated file search calls usage details of the specific time bucket. */ + @JvmStatic + fun ofOrganizationUsageFileSearches( + organizationUsageFileSearches: OrganizationUsageFileSearchesResult + ) = Result(organizationUsageFileSearches = organizationUsageFileSearches) + + /** The aggregated web search calls usage details of the specific time bucket. */ + @JvmStatic + fun ofOrganizationUsageWebSearches( + organizationUsageWebSearches: OrganizationUsageWebSearchesResult + ) = Result(organizationUsageWebSearches = organizationUsageWebSearches) + /** The aggregated costs details of the specific time bucket. */ @JvmStatic fun ofOrganizationCosts(organizationCosts: OrganizationCostsResult) = @@ -1171,6 +1267,16 @@ private constructor( OrganizationUsageCodeInterpreterSessionsResult ): T + /** The aggregated file search calls usage details of the specific time bucket. */ + fun visitOrganizationUsageFileSearches( + organizationUsageFileSearches: OrganizationUsageFileSearchesResult + ): T + + /** The aggregated web search calls usage details of the specific time bucket. */ + fun visitOrganizationUsageWebSearches( + organizationUsageWebSearches: OrganizationUsageWebSearchesResult + ): T + /** The aggregated costs details of the specific time bucket. */ fun visitOrganizationCosts(organizationCosts: OrganizationCostsResult): T @@ -1266,6 +1372,22 @@ private constructor( ) } ?: Result(_json = json) } + "organization.usage.file_searches.result" -> { + return tryDeserialize( + node, + jacksonTypeRef(), + ) + ?.let { Result(organizationUsageFileSearches = it, _json = json) } + ?: Result(_json = json) + } + "organization.usage.web_searches.result" -> { + return tryDeserialize( + node, + jacksonTypeRef(), + ) + ?.let { Result(organizationUsageWebSearches = it, _json = json) } + ?: Result(_json = json) + } "organization.costs.result" -> { return tryDeserialize(node, jacksonTypeRef()) ?.let { Result(organizationCosts = it, _json = json) } @@ -1301,6 +1423,10 @@ private constructor( generator.writeObject(value.organizationUsageVectorStores) value.organizationUsageCodeInterpreterSessions != null -> generator.writeObject(value.organizationUsageCodeInterpreterSessions) + value.organizationUsageFileSearches != null -> + generator.writeObject(value.organizationUsageFileSearches) + value.organizationUsageWebSearches != null -> + generator.writeObject(value.organizationUsageWebSearches) value.organizationCosts != null -> generator.writeObject(value.organizationCosts) value._json != null -> generator.writeObject(value._json) @@ -5166,6 +5292,981 @@ private constructor( "OrganizationUsageCodeInterpreterSessionsResult{numSessions=$numSessions, object_=$object_, projectId=$projectId, additionalProperties=$additionalProperties}" } + /** The aggregated file search calls usage details of the specific time bucket. */ + class OrganizationUsageFileSearchesResult + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val numRequests: JsonField, + private val object_: JsonValue, + private val apiKeyId: JsonField, + private val projectId: JsonField, + private val userId: JsonField, + private val vectorStoreId: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("num_requests") + @ExcludeMissing + numRequests: JsonField = JsonMissing.of(), + @JsonProperty("object") @ExcludeMissing object_: JsonValue = JsonMissing.of(), + @JsonProperty("api_key_id") + @ExcludeMissing + apiKeyId: JsonField = JsonMissing.of(), + @JsonProperty("project_id") + @ExcludeMissing + projectId: JsonField = JsonMissing.of(), + @JsonProperty("user_id") + @ExcludeMissing + userId: JsonField = JsonMissing.of(), + @JsonProperty("vector_store_id") + @ExcludeMissing + vectorStoreId: JsonField = JsonMissing.of(), + ) : this( + numRequests, + object_, + apiKeyId, + projectId, + userId, + vectorStoreId, + mutableMapOf(), + ) + + /** + * The count of file search calls. + * + * @throws OpenAIInvalidDataException 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 numRequests(): Long = numRequests.getRequired("num_requests") + + /** + * Expected to always return the following: + * ```java + * JsonValue.from("organization.usage.file_searches.result") + * ``` + * + * However, this method can be useful for debugging and logging (e.g. if the server + * responded with an unexpected value). + */ + @JsonProperty("object") @ExcludeMissing fun _object_(): JsonValue = object_ + + /** + * When `group_by=api_key_id`, this field provides the API key ID of the grouped + * usage result. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun apiKeyId(): Optional = apiKeyId.getOptional("api_key_id") + + /** + * When `group_by=project_id`, this field provides the project ID of the grouped + * usage result. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun projectId(): Optional = projectId.getOptional("project_id") + + /** + * When `group_by=user_id`, this field provides the user ID of the grouped usage + * result. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun userId(): Optional = userId.getOptional("user_id") + + /** + * When `group_by=vector_store_id`, this field provides the vector store ID of the + * grouped usage result. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun vectorStoreId(): Optional = vectorStoreId.getOptional("vector_store_id") + + /** + * Returns the raw JSON value of [numRequests]. + * + * Unlike [numRequests], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("num_requests") + @ExcludeMissing + fun _numRequests(): JsonField = numRequests + + /** + * Returns the raw JSON value of [apiKeyId]. + * + * Unlike [apiKeyId], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("api_key_id") + @ExcludeMissing + fun _apiKeyId(): JsonField = apiKeyId + + /** + * 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 [userId]. + * + * Unlike [userId], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("user_id") @ExcludeMissing fun _userId(): JsonField = userId + + /** + * Returns the raw JSON value of [vectorStoreId]. + * + * Unlike [vectorStoreId], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("vector_store_id") + @ExcludeMissing + fun _vectorStoreId(): JsonField = vectorStoreId + + @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 + * [OrganizationUsageFileSearchesResult]. + * + * The following fields are required: + * ```java + * .numRequests() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [OrganizationUsageFileSearchesResult]. */ + class Builder internal constructor() { + + private var numRequests: JsonField? = null + private var object_: JsonValue = + JsonValue.from("organization.usage.file_searches.result") + private var apiKeyId: JsonField = JsonMissing.of() + private var projectId: JsonField = JsonMissing.of() + private var userId: JsonField = JsonMissing.of() + private var vectorStoreId: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from( + organizationUsageFileSearchesResult: OrganizationUsageFileSearchesResult + ) = apply { + numRequests = organizationUsageFileSearchesResult.numRequests + object_ = organizationUsageFileSearchesResult.object_ + apiKeyId = organizationUsageFileSearchesResult.apiKeyId + projectId = organizationUsageFileSearchesResult.projectId + userId = organizationUsageFileSearchesResult.userId + vectorStoreId = organizationUsageFileSearchesResult.vectorStoreId + additionalProperties = + organizationUsageFileSearchesResult.additionalProperties.toMutableMap() + } + + /** The count of file search calls. */ + fun numRequests(numRequests: Long) = numRequests(JsonField.of(numRequests)) + + /** + * Sets [Builder.numRequests] to an arbitrary JSON value. + * + * You should usually call [Builder.numRequests] with a well-typed [Long] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun numRequests(numRequests: JsonField) = apply { + this.numRequests = numRequests + } + + /** + * Sets the field to an arbitrary JSON value. + * + * It is usually unnecessary to call this method because the field defaults to + * the following: + * ```java + * JsonValue.from("organization.usage.file_searches.result") + * ``` + * + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun object_(object_: JsonValue) = apply { this.object_ = object_ } + + /** + * When `group_by=api_key_id`, this field provides the API key ID of the grouped + * usage result. + */ + fun apiKeyId(apiKeyId: String?) = apiKeyId(JsonField.ofNullable(apiKeyId)) + + /** Alias for calling [Builder.apiKeyId] with `apiKeyId.orElse(null)`. */ + fun apiKeyId(apiKeyId: Optional) = apiKeyId(apiKeyId.getOrNull()) + + /** + * Sets [Builder.apiKeyId] to an arbitrary JSON value. + * + * You should usually call [Builder.apiKeyId] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun apiKeyId(apiKeyId: JsonField) = apply { this.apiKeyId = apiKeyId } + + /** + * When `group_by=project_id`, this field provides the project ID of the grouped + * usage result. + */ + fun projectId(projectId: String?) = projectId(JsonField.ofNullable(projectId)) + + /** Alias for calling [Builder.projectId] with `projectId.orElse(null)`. */ + fun projectId(projectId: Optional) = projectId(projectId.getOrNull()) + + /** + * 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 + } + + /** + * When `group_by=user_id`, this field provides the user ID of the grouped usage + * result. + */ + 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 } + + /** + * When `group_by=vector_store_id`, this field provides the vector store ID of + * the grouped usage result. + */ + fun vectorStoreId(vectorStoreId: String?) = + vectorStoreId(JsonField.ofNullable(vectorStoreId)) + + /** + * Alias for calling [Builder.vectorStoreId] with `vectorStoreId.orElse(null)`. + */ + fun vectorStoreId(vectorStoreId: Optional) = + vectorStoreId(vectorStoreId.getOrNull()) + + /** + * Sets [Builder.vectorStoreId] to an arbitrary JSON value. + * + * You should usually call [Builder.vectorStoreId] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun vectorStoreId(vectorStoreId: JsonField) = apply { + this.vectorStoreId = vectorStoreId + } + + 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 [OrganizationUsageFileSearchesResult]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .numRequests() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): OrganizationUsageFileSearchesResult = + OrganizationUsageFileSearchesResult( + checkRequired("numRequests", numRequests), + object_, + apiKeyId, + projectId, + userId, + vectorStoreId, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing + * fields. + * + * @throws OpenAIInvalidDataException if any value type in this object doesn't match + * its expected type. + */ + fun validate(): OrganizationUsageFileSearchesResult = apply { + if (validated) { + return@apply + } + + numRequests() + _object_().let { + if (it != JsonValue.from("organization.usage.file_searches.result")) { + throw OpenAIInvalidDataException("'object_' is invalid, received $it") + } + } + apiKeyId() + projectId() + userId() + vectorStoreId() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OpenAIInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (if (numRequests.asKnown().isPresent) 1 else 0) + + object_.let { + if (it == JsonValue.from("organization.usage.file_searches.result")) 1 + else 0 + } + + (if (apiKeyId.asKnown().isPresent) 1 else 0) + + (if (projectId.asKnown().isPresent) 1 else 0) + + (if (userId.asKnown().isPresent) 1 else 0) + + (if (vectorStoreId.asKnown().isPresent) 1 else 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is OrganizationUsageFileSearchesResult && + numRequests == other.numRequests && + object_ == other.object_ && + apiKeyId == other.apiKeyId && + projectId == other.projectId && + userId == other.userId && + vectorStoreId == other.vectorStoreId && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + numRequests, + object_, + apiKeyId, + projectId, + userId, + vectorStoreId, + additionalProperties, + ) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "OrganizationUsageFileSearchesResult{numRequests=$numRequests, object_=$object_, apiKeyId=$apiKeyId, projectId=$projectId, userId=$userId, vectorStoreId=$vectorStoreId, additionalProperties=$additionalProperties}" + } + + /** The aggregated web search calls usage details of the specific time bucket. */ + class OrganizationUsageWebSearchesResult + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val numModelRequests: JsonField, + private val numRequests: JsonField, + private val object_: JsonValue, + private val apiKeyId: JsonField, + private val contextLevel: JsonField, + private val model: JsonField, + private val projectId: JsonField, + private val userId: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("num_model_requests") + @ExcludeMissing + numModelRequests: JsonField = JsonMissing.of(), + @JsonProperty("num_requests") + @ExcludeMissing + numRequests: JsonField = JsonMissing.of(), + @JsonProperty("object") @ExcludeMissing object_: JsonValue = JsonMissing.of(), + @JsonProperty("api_key_id") + @ExcludeMissing + apiKeyId: JsonField = JsonMissing.of(), + @JsonProperty("context_level") + @ExcludeMissing + contextLevel: JsonField = JsonMissing.of(), + @JsonProperty("model") + @ExcludeMissing + model: JsonField = JsonMissing.of(), + @JsonProperty("project_id") + @ExcludeMissing + projectId: JsonField = JsonMissing.of(), + @JsonProperty("user_id") + @ExcludeMissing + userId: JsonField = JsonMissing.of(), + ) : this( + numModelRequests, + numRequests, + object_, + apiKeyId, + contextLevel, + model, + projectId, + userId, + mutableMapOf(), + ) + + /** + * The count of model requests. + * + * @throws OpenAIInvalidDataException 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 numModelRequests(): Long = numModelRequests.getRequired("num_model_requests") + + /** + * The count of web search calls. + * + * @throws OpenAIInvalidDataException 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 numRequests(): Long = numRequests.getRequired("num_requests") + + /** + * Expected to always return the following: + * ```java + * JsonValue.from("organization.usage.web_searches.result") + * ``` + * + * However, this method can be useful for debugging and logging (e.g. if the server + * responded with an unexpected value). + */ + @JsonProperty("object") @ExcludeMissing fun _object_(): JsonValue = object_ + + /** + * When `group_by=api_key_id`, this field provides the API key ID of the grouped + * usage result. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun apiKeyId(): Optional = apiKeyId.getOptional("api_key_id") + + /** + * When `group_by=context_level`, this field provides the search context size of the + * grouped usage result. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun contextLevel(): Optional = contextLevel.getOptional("context_level") + + /** + * When `group_by=model`, this field provides the model name of the grouped usage + * result. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun model(): Optional = model.getOptional("model") + + /** + * When `group_by=project_id`, this field provides the project ID of the grouped + * usage result. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun projectId(): Optional = projectId.getOptional("project_id") + + /** + * When `group_by=user_id`, this field provides the user ID of the grouped usage + * result. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun userId(): Optional = userId.getOptional("user_id") + + /** + * Returns the raw JSON value of [numModelRequests]. + * + * Unlike [numModelRequests], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("num_model_requests") + @ExcludeMissing + fun _numModelRequests(): JsonField = numModelRequests + + /** + * Returns the raw JSON value of [numRequests]. + * + * Unlike [numRequests], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("num_requests") + @ExcludeMissing + fun _numRequests(): JsonField = numRequests + + /** + * Returns the raw JSON value of [apiKeyId]. + * + * Unlike [apiKeyId], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("api_key_id") + @ExcludeMissing + fun _apiKeyId(): JsonField = apiKeyId + + /** + * Returns the raw JSON value of [contextLevel]. + * + * Unlike [contextLevel], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("context_level") + @ExcludeMissing + fun _contextLevel(): JsonField = contextLevel + + /** + * Returns the raw JSON value of [model]. + * + * Unlike [model], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("model") @ExcludeMissing fun _model(): JsonField = model + + /** + * 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 [userId]. + * + * Unlike [userId], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @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 = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of + * [OrganizationUsageWebSearchesResult]. + * + * The following fields are required: + * ```java + * .numModelRequests() + * .numRequests() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [OrganizationUsageWebSearchesResult]. */ + class Builder internal constructor() { + + private var numModelRequests: JsonField? = null + private var numRequests: JsonField? = null + private var object_: JsonValue = + JsonValue.from("organization.usage.web_searches.result") + private var apiKeyId: JsonField = JsonMissing.of() + private var contextLevel: JsonField = JsonMissing.of() + private var model: JsonField = JsonMissing.of() + private var projectId: JsonField = JsonMissing.of() + private var userId: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from( + organizationUsageWebSearchesResult: OrganizationUsageWebSearchesResult + ) = apply { + numModelRequests = organizationUsageWebSearchesResult.numModelRequests + numRequests = organizationUsageWebSearchesResult.numRequests + object_ = organizationUsageWebSearchesResult.object_ + apiKeyId = organizationUsageWebSearchesResult.apiKeyId + contextLevel = organizationUsageWebSearchesResult.contextLevel + model = organizationUsageWebSearchesResult.model + projectId = organizationUsageWebSearchesResult.projectId + userId = organizationUsageWebSearchesResult.userId + additionalProperties = + organizationUsageWebSearchesResult.additionalProperties.toMutableMap() + } + + /** The count of model requests. */ + fun numModelRequests(numModelRequests: Long) = + numModelRequests(JsonField.of(numModelRequests)) + + /** + * Sets [Builder.numModelRequests] to an arbitrary JSON value. + * + * You should usually call [Builder.numModelRequests] with a well-typed [Long] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun numModelRequests(numModelRequests: JsonField) = apply { + this.numModelRequests = numModelRequests + } + + /** The count of web search calls. */ + fun numRequests(numRequests: Long) = numRequests(JsonField.of(numRequests)) + + /** + * Sets [Builder.numRequests] to an arbitrary JSON value. + * + * You should usually call [Builder.numRequests] with a well-typed [Long] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun numRequests(numRequests: JsonField) = apply { + this.numRequests = numRequests + } + + /** + * Sets the field to an arbitrary JSON value. + * + * It is usually unnecessary to call this method because the field defaults to + * the following: + * ```java + * JsonValue.from("organization.usage.web_searches.result") + * ``` + * + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun object_(object_: JsonValue) = apply { this.object_ = object_ } + + /** + * When `group_by=api_key_id`, this field provides the API key ID of the grouped + * usage result. + */ + fun apiKeyId(apiKeyId: String?) = apiKeyId(JsonField.ofNullable(apiKeyId)) + + /** Alias for calling [Builder.apiKeyId] with `apiKeyId.orElse(null)`. */ + fun apiKeyId(apiKeyId: Optional) = apiKeyId(apiKeyId.getOrNull()) + + /** + * Sets [Builder.apiKeyId] to an arbitrary JSON value. + * + * You should usually call [Builder.apiKeyId] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun apiKeyId(apiKeyId: JsonField) = apply { this.apiKeyId = apiKeyId } + + /** + * When `group_by=context_level`, this field provides the search context size of + * the grouped usage result. + */ + fun contextLevel(contextLevel: String?) = + contextLevel(JsonField.ofNullable(contextLevel)) + + /** + * Alias for calling [Builder.contextLevel] with `contextLevel.orElse(null)`. + */ + fun contextLevel(contextLevel: Optional) = + contextLevel(contextLevel.getOrNull()) + + /** + * Sets [Builder.contextLevel] to an arbitrary JSON value. + * + * You should usually call [Builder.contextLevel] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun contextLevel(contextLevel: JsonField) = apply { + this.contextLevel = contextLevel + } + + /** + * When `group_by=model`, this field provides the model name of the grouped + * usage result. + */ + fun model(model: String?) = model(JsonField.ofNullable(model)) + + /** Alias for calling [Builder.model] with `model.orElse(null)`. */ + fun model(model: Optional) = model(model.getOrNull()) + + /** + * Sets [Builder.model] to an arbitrary JSON value. + * + * You should usually call [Builder.model] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun model(model: JsonField) = apply { this.model = model } + + /** + * When `group_by=project_id`, this field provides the project ID of the grouped + * usage result. + */ + fun projectId(projectId: String?) = projectId(JsonField.ofNullable(projectId)) + + /** Alias for calling [Builder.projectId] with `projectId.orElse(null)`. */ + fun projectId(projectId: Optional) = projectId(projectId.getOrNull()) + + /** + * 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 + } + + /** + * When `group_by=user_id`, this field provides the user ID of the grouped usage + * result. + */ + 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 } + + 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 [OrganizationUsageWebSearchesResult]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .numModelRequests() + * .numRequests() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): OrganizationUsageWebSearchesResult = + OrganizationUsageWebSearchesResult( + checkRequired("numModelRequests", numModelRequests), + checkRequired("numRequests", numRequests), + object_, + apiKeyId, + contextLevel, + model, + projectId, + userId, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing + * fields. + * + * @throws OpenAIInvalidDataException if any value type in this object doesn't match + * its expected type. + */ + fun validate(): OrganizationUsageWebSearchesResult = apply { + if (validated) { + return@apply + } + + numModelRequests() + numRequests() + _object_().let { + if (it != JsonValue.from("organization.usage.web_searches.result")) { + throw OpenAIInvalidDataException("'object_' is invalid, received $it") + } + } + apiKeyId() + contextLevel() + model() + projectId() + userId() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OpenAIInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (if (numModelRequests.asKnown().isPresent) 1 else 0) + + (if (numRequests.asKnown().isPresent) 1 else 0) + + object_.let { + if (it == JsonValue.from("organization.usage.web_searches.result")) 1 + else 0 + } + + (if (apiKeyId.asKnown().isPresent) 1 else 0) + + (if (contextLevel.asKnown().isPresent) 1 else 0) + + (if (model.asKnown().isPresent) 1 else 0) + + (if (projectId.asKnown().isPresent) 1 else 0) + + (if (userId.asKnown().isPresent) 1 else 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is OrganizationUsageWebSearchesResult && + numModelRequests == other.numModelRequests && + numRequests == other.numRequests && + object_ == other.object_ && + apiKeyId == other.apiKeyId && + contextLevel == other.contextLevel && + model == other.model && + projectId == other.projectId && + userId == other.userId && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + numModelRequests, + numRequests, + object_, + apiKeyId, + contextLevel, + model, + projectId, + userId, + additionalProperties, + ) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "OrganizationUsageWebSearchesResult{numModelRequests=$numModelRequests, numRequests=$numRequests, object_=$object_, apiKeyId=$apiKeyId, contextLevel=$contextLevel, model=$model, projectId=$projectId, userId=$userId, additionalProperties=$additionalProperties}" + } + /** The aggregated costs details of the specific time bucket. */ class OrganizationCostsResult @JsonCreator(mode = JsonCreator.Mode.DISABLED) diff --git a/openai-java-core/src/main/kotlin/com/openai/models/admin/organization/usage/UsageCompletionsResponse.kt b/openai-java-core/src/main/kotlin/com/openai/models/admin/organization/usage/UsageCompletionsResponse.kt index e376b595b..04d418d88 100644 --- a/openai-java-core/src/main/kotlin/com/openai/models/admin/organization/usage/UsageCompletionsResponse.kt +++ b/openai-java-core/src/main/kotlin/com/openai/models/admin/organization/usage/UsageCompletionsResponse.kt @@ -561,6 +561,36 @@ private constructor( .build() ) + /** + * Alias for calling [addResult] with + * `Result.ofOrganizationUsageFileSearches(organizationUsageFileSearches)`. + */ + fun addResult( + organizationUsageFileSearches: Result.OrganizationUsageFileSearchesResult + ) = addResult(Result.ofOrganizationUsageFileSearches(organizationUsageFileSearches)) + + /** + * Alias for calling [addResult] with the following: + * ```java + * Result.OrganizationUsageFileSearchesResult.builder() + * .numRequests(numRequests) + * .build() + * ``` + */ + fun addOrganizationUsageFileSearchesResult(numRequests: Long) = + addResult( + Result.OrganizationUsageFileSearchesResult.builder() + .numRequests(numRequests) + .build() + ) + + /** + * Alias for calling [addResult] with + * `Result.ofOrganizationUsageWebSearches(organizationUsageWebSearches)`. + */ + fun addResult(organizationUsageWebSearches: Result.OrganizationUsageWebSearchesResult) = + addResult(Result.ofOrganizationUsageWebSearches(organizationUsageWebSearches)) + /** * Alias for calling [addResult] with `Result.ofOrganizationCosts(organizationCosts)`. */ @@ -687,6 +717,8 @@ private constructor( private val organizationUsageCodeInterpreterSessions: OrganizationUsageCodeInterpreterSessionsResult? = null, + private val organizationUsageFileSearches: OrganizationUsageFileSearchesResult? = null, + private val organizationUsageWebSearches: OrganizationUsageWebSearchesResult? = null, private val organizationCosts: OrganizationCostsResult? = null, private val _json: JsonValue? = null, ) { @@ -727,6 +759,14 @@ private constructor( Optional = Optional.ofNullable(organizationUsageCodeInterpreterSessions) + /** The aggregated file search calls usage details of the specific time bucket. */ + fun organizationUsageFileSearches(): Optional = + Optional.ofNullable(organizationUsageFileSearches) + + /** The aggregated web search calls usage details of the specific time bucket. */ + fun organizationUsageWebSearches(): Optional = + Optional.ofNullable(organizationUsageWebSearches) + /** The aggregated costs details of the specific time bucket. */ fun organizationCosts(): Optional = Optional.ofNullable(organizationCosts) @@ -749,6 +789,10 @@ private constructor( fun isOrganizationUsageCodeInterpreterSessions(): Boolean = organizationUsageCodeInterpreterSessions != null + fun isOrganizationUsageFileSearches(): Boolean = organizationUsageFileSearches != null + + fun isOrganizationUsageWebSearches(): Boolean = organizationUsageWebSearches != null + fun isOrganizationCosts(): Boolean = organizationCosts != null /** The aggregated completions usage details of the specific time bucket. */ @@ -791,6 +835,14 @@ private constructor( "organizationUsageCodeInterpreterSessions" ) + /** The aggregated file search calls usage details of the specific time bucket. */ + fun asOrganizationUsageFileSearches(): OrganizationUsageFileSearchesResult = + organizationUsageFileSearches.getOrThrow("organizationUsageFileSearches") + + /** The aggregated web search calls usage details of the specific time bucket. */ + fun asOrganizationUsageWebSearches(): OrganizationUsageWebSearchesResult = + organizationUsageWebSearches.getOrThrow("organizationUsageWebSearches") + /** The aggregated costs details of the specific time bucket. */ fun asOrganizationCosts(): OrganizationCostsResult = organizationCosts.getOrThrow("organizationCosts") @@ -849,6 +901,10 @@ private constructor( visitor.visitOrganizationUsageCodeInterpreterSessions( organizationUsageCodeInterpreterSessions ) + organizationUsageFileSearches != null -> + visitor.visitOrganizationUsageFileSearches(organizationUsageFileSearches) + organizationUsageWebSearches != null -> + visitor.visitOrganizationUsageWebSearches(organizationUsageWebSearches) organizationCosts != null -> visitor.visitOrganizationCosts(organizationCosts) else -> visitor.unknown(_json) } @@ -922,6 +978,18 @@ private constructor( organizationUsageCodeInterpreterSessions.validate() } + override fun visitOrganizationUsageFileSearches( + organizationUsageFileSearches: OrganizationUsageFileSearchesResult + ) { + organizationUsageFileSearches.validate() + } + + override fun visitOrganizationUsageWebSearches( + organizationUsageWebSearches: OrganizationUsageWebSearchesResult + ) { + organizationUsageWebSearches.validate() + } + override fun visitOrganizationCosts( organizationCosts: OrganizationCostsResult ) { @@ -984,6 +1052,14 @@ private constructor( OrganizationUsageCodeInterpreterSessionsResult ) = organizationUsageCodeInterpreterSessions.validity() + override fun visitOrganizationUsageFileSearches( + organizationUsageFileSearches: OrganizationUsageFileSearchesResult + ) = organizationUsageFileSearches.validity() + + override fun visitOrganizationUsageWebSearches( + organizationUsageWebSearches: OrganizationUsageWebSearchesResult + ) = organizationUsageWebSearches.validity() + override fun visitOrganizationCosts( organizationCosts: OrganizationCostsResult ) = organizationCosts.validity() @@ -1008,6 +1084,8 @@ private constructor( organizationUsageVectorStores == other.organizationUsageVectorStores && organizationUsageCodeInterpreterSessions == other.organizationUsageCodeInterpreterSessions && + organizationUsageFileSearches == other.organizationUsageFileSearches && + organizationUsageWebSearches == other.organizationUsageWebSearches && organizationCosts == other.organizationCosts } @@ -1021,6 +1099,8 @@ private constructor( organizationUsageAudioTranscriptions, organizationUsageVectorStores, organizationUsageCodeInterpreterSessions, + organizationUsageFileSearches, + organizationUsageWebSearches, organizationCosts, ) @@ -1042,6 +1122,10 @@ private constructor( "Result{organizationUsageVectorStores=$organizationUsageVectorStores}" organizationUsageCodeInterpreterSessions != null -> "Result{organizationUsageCodeInterpreterSessions=$organizationUsageCodeInterpreterSessions}" + organizationUsageFileSearches != null -> + "Result{organizationUsageFileSearches=$organizationUsageFileSearches}" + organizationUsageWebSearches != null -> + "Result{organizationUsageWebSearches=$organizationUsageWebSearches}" organizationCosts != null -> "Result{organizationCosts=$organizationCosts}" _json != null -> "Result{_unknown=$_json}" else -> throw IllegalStateException("Invalid Result") @@ -1110,6 +1194,18 @@ private constructor( organizationUsageCodeInterpreterSessions ) + /** The aggregated file search calls usage details of the specific time bucket. */ + @JvmStatic + fun ofOrganizationUsageFileSearches( + organizationUsageFileSearches: OrganizationUsageFileSearchesResult + ) = Result(organizationUsageFileSearches = organizationUsageFileSearches) + + /** The aggregated web search calls usage details of the specific time bucket. */ + @JvmStatic + fun ofOrganizationUsageWebSearches( + organizationUsageWebSearches: OrganizationUsageWebSearchesResult + ) = Result(organizationUsageWebSearches = organizationUsageWebSearches) + /** The aggregated costs details of the specific time bucket. */ @JvmStatic fun ofOrganizationCosts(organizationCosts: OrganizationCostsResult) = @@ -1167,6 +1263,16 @@ private constructor( OrganizationUsageCodeInterpreterSessionsResult ): T + /** The aggregated file search calls usage details of the specific time bucket. */ + fun visitOrganizationUsageFileSearches( + organizationUsageFileSearches: OrganizationUsageFileSearchesResult + ): T + + /** The aggregated web search calls usage details of the specific time bucket. */ + fun visitOrganizationUsageWebSearches( + organizationUsageWebSearches: OrganizationUsageWebSearchesResult + ): T + /** The aggregated costs details of the specific time bucket. */ fun visitOrganizationCosts(organizationCosts: OrganizationCostsResult): T @@ -1262,6 +1368,22 @@ private constructor( ) } ?: Result(_json = json) } + "organization.usage.file_searches.result" -> { + return tryDeserialize( + node, + jacksonTypeRef(), + ) + ?.let { Result(organizationUsageFileSearches = it, _json = json) } + ?: Result(_json = json) + } + "organization.usage.web_searches.result" -> { + return tryDeserialize( + node, + jacksonTypeRef(), + ) + ?.let { Result(organizationUsageWebSearches = it, _json = json) } + ?: Result(_json = json) + } "organization.costs.result" -> { return tryDeserialize(node, jacksonTypeRef()) ?.let { Result(organizationCosts = it, _json = json) } @@ -1297,6 +1419,10 @@ private constructor( generator.writeObject(value.organizationUsageVectorStores) value.organizationUsageCodeInterpreterSessions != null -> generator.writeObject(value.organizationUsageCodeInterpreterSessions) + value.organizationUsageFileSearches != null -> + generator.writeObject(value.organizationUsageFileSearches) + value.organizationUsageWebSearches != null -> + generator.writeObject(value.organizationUsageWebSearches) value.organizationCosts != null -> generator.writeObject(value.organizationCosts) value._json != null -> generator.writeObject(value._json) @@ -5162,6 +5288,981 @@ private constructor( "OrganizationUsageCodeInterpreterSessionsResult{numSessions=$numSessions, object_=$object_, projectId=$projectId, additionalProperties=$additionalProperties}" } + /** The aggregated file search calls usage details of the specific time bucket. */ + class OrganizationUsageFileSearchesResult + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val numRequests: JsonField, + private val object_: JsonValue, + private val apiKeyId: JsonField, + private val projectId: JsonField, + private val userId: JsonField, + private val vectorStoreId: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("num_requests") + @ExcludeMissing + numRequests: JsonField = JsonMissing.of(), + @JsonProperty("object") @ExcludeMissing object_: JsonValue = JsonMissing.of(), + @JsonProperty("api_key_id") + @ExcludeMissing + apiKeyId: JsonField = JsonMissing.of(), + @JsonProperty("project_id") + @ExcludeMissing + projectId: JsonField = JsonMissing.of(), + @JsonProperty("user_id") + @ExcludeMissing + userId: JsonField = JsonMissing.of(), + @JsonProperty("vector_store_id") + @ExcludeMissing + vectorStoreId: JsonField = JsonMissing.of(), + ) : this( + numRequests, + object_, + apiKeyId, + projectId, + userId, + vectorStoreId, + mutableMapOf(), + ) + + /** + * The count of file search calls. + * + * @throws OpenAIInvalidDataException 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 numRequests(): Long = numRequests.getRequired("num_requests") + + /** + * Expected to always return the following: + * ```java + * JsonValue.from("organization.usage.file_searches.result") + * ``` + * + * However, this method can be useful for debugging and logging (e.g. if the server + * responded with an unexpected value). + */ + @JsonProperty("object") @ExcludeMissing fun _object_(): JsonValue = object_ + + /** + * When `group_by=api_key_id`, this field provides the API key ID of the grouped + * usage result. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun apiKeyId(): Optional = apiKeyId.getOptional("api_key_id") + + /** + * When `group_by=project_id`, this field provides the project ID of the grouped + * usage result. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun projectId(): Optional = projectId.getOptional("project_id") + + /** + * When `group_by=user_id`, this field provides the user ID of the grouped usage + * result. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun userId(): Optional = userId.getOptional("user_id") + + /** + * When `group_by=vector_store_id`, this field provides the vector store ID of the + * grouped usage result. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun vectorStoreId(): Optional = vectorStoreId.getOptional("vector_store_id") + + /** + * Returns the raw JSON value of [numRequests]. + * + * Unlike [numRequests], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("num_requests") + @ExcludeMissing + fun _numRequests(): JsonField = numRequests + + /** + * Returns the raw JSON value of [apiKeyId]. + * + * Unlike [apiKeyId], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("api_key_id") + @ExcludeMissing + fun _apiKeyId(): JsonField = apiKeyId + + /** + * 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 [userId]. + * + * Unlike [userId], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("user_id") @ExcludeMissing fun _userId(): JsonField = userId + + /** + * Returns the raw JSON value of [vectorStoreId]. + * + * Unlike [vectorStoreId], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("vector_store_id") + @ExcludeMissing + fun _vectorStoreId(): JsonField = vectorStoreId + + @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 + * [OrganizationUsageFileSearchesResult]. + * + * The following fields are required: + * ```java + * .numRequests() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [OrganizationUsageFileSearchesResult]. */ + class Builder internal constructor() { + + private var numRequests: JsonField? = null + private var object_: JsonValue = + JsonValue.from("organization.usage.file_searches.result") + private var apiKeyId: JsonField = JsonMissing.of() + private var projectId: JsonField = JsonMissing.of() + private var userId: JsonField = JsonMissing.of() + private var vectorStoreId: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from( + organizationUsageFileSearchesResult: OrganizationUsageFileSearchesResult + ) = apply { + numRequests = organizationUsageFileSearchesResult.numRequests + object_ = organizationUsageFileSearchesResult.object_ + apiKeyId = organizationUsageFileSearchesResult.apiKeyId + projectId = organizationUsageFileSearchesResult.projectId + userId = organizationUsageFileSearchesResult.userId + vectorStoreId = organizationUsageFileSearchesResult.vectorStoreId + additionalProperties = + organizationUsageFileSearchesResult.additionalProperties.toMutableMap() + } + + /** The count of file search calls. */ + fun numRequests(numRequests: Long) = numRequests(JsonField.of(numRequests)) + + /** + * Sets [Builder.numRequests] to an arbitrary JSON value. + * + * You should usually call [Builder.numRequests] with a well-typed [Long] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun numRequests(numRequests: JsonField) = apply { + this.numRequests = numRequests + } + + /** + * Sets the field to an arbitrary JSON value. + * + * It is usually unnecessary to call this method because the field defaults to + * the following: + * ```java + * JsonValue.from("organization.usage.file_searches.result") + * ``` + * + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun object_(object_: JsonValue) = apply { this.object_ = object_ } + + /** + * When `group_by=api_key_id`, this field provides the API key ID of the grouped + * usage result. + */ + fun apiKeyId(apiKeyId: String?) = apiKeyId(JsonField.ofNullable(apiKeyId)) + + /** Alias for calling [Builder.apiKeyId] with `apiKeyId.orElse(null)`. */ + fun apiKeyId(apiKeyId: Optional) = apiKeyId(apiKeyId.getOrNull()) + + /** + * Sets [Builder.apiKeyId] to an arbitrary JSON value. + * + * You should usually call [Builder.apiKeyId] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun apiKeyId(apiKeyId: JsonField) = apply { this.apiKeyId = apiKeyId } + + /** + * When `group_by=project_id`, this field provides the project ID of the grouped + * usage result. + */ + fun projectId(projectId: String?) = projectId(JsonField.ofNullable(projectId)) + + /** Alias for calling [Builder.projectId] with `projectId.orElse(null)`. */ + fun projectId(projectId: Optional) = projectId(projectId.getOrNull()) + + /** + * 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 + } + + /** + * When `group_by=user_id`, this field provides the user ID of the grouped usage + * result. + */ + 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 } + + /** + * When `group_by=vector_store_id`, this field provides the vector store ID of + * the grouped usage result. + */ + fun vectorStoreId(vectorStoreId: String?) = + vectorStoreId(JsonField.ofNullable(vectorStoreId)) + + /** + * Alias for calling [Builder.vectorStoreId] with `vectorStoreId.orElse(null)`. + */ + fun vectorStoreId(vectorStoreId: Optional) = + vectorStoreId(vectorStoreId.getOrNull()) + + /** + * Sets [Builder.vectorStoreId] to an arbitrary JSON value. + * + * You should usually call [Builder.vectorStoreId] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun vectorStoreId(vectorStoreId: JsonField) = apply { + this.vectorStoreId = vectorStoreId + } + + 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 [OrganizationUsageFileSearchesResult]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .numRequests() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): OrganizationUsageFileSearchesResult = + OrganizationUsageFileSearchesResult( + checkRequired("numRequests", numRequests), + object_, + apiKeyId, + projectId, + userId, + vectorStoreId, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing + * fields. + * + * @throws OpenAIInvalidDataException if any value type in this object doesn't match + * its expected type. + */ + fun validate(): OrganizationUsageFileSearchesResult = apply { + if (validated) { + return@apply + } + + numRequests() + _object_().let { + if (it != JsonValue.from("organization.usage.file_searches.result")) { + throw OpenAIInvalidDataException("'object_' is invalid, received $it") + } + } + apiKeyId() + projectId() + userId() + vectorStoreId() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OpenAIInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (if (numRequests.asKnown().isPresent) 1 else 0) + + object_.let { + if (it == JsonValue.from("organization.usage.file_searches.result")) 1 + else 0 + } + + (if (apiKeyId.asKnown().isPresent) 1 else 0) + + (if (projectId.asKnown().isPresent) 1 else 0) + + (if (userId.asKnown().isPresent) 1 else 0) + + (if (vectorStoreId.asKnown().isPresent) 1 else 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is OrganizationUsageFileSearchesResult && + numRequests == other.numRequests && + object_ == other.object_ && + apiKeyId == other.apiKeyId && + projectId == other.projectId && + userId == other.userId && + vectorStoreId == other.vectorStoreId && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + numRequests, + object_, + apiKeyId, + projectId, + userId, + vectorStoreId, + additionalProperties, + ) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "OrganizationUsageFileSearchesResult{numRequests=$numRequests, object_=$object_, apiKeyId=$apiKeyId, projectId=$projectId, userId=$userId, vectorStoreId=$vectorStoreId, additionalProperties=$additionalProperties}" + } + + /** The aggregated web search calls usage details of the specific time bucket. */ + class OrganizationUsageWebSearchesResult + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val numModelRequests: JsonField, + private val numRequests: JsonField, + private val object_: JsonValue, + private val apiKeyId: JsonField, + private val contextLevel: JsonField, + private val model: JsonField, + private val projectId: JsonField, + private val userId: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("num_model_requests") + @ExcludeMissing + numModelRequests: JsonField = JsonMissing.of(), + @JsonProperty("num_requests") + @ExcludeMissing + numRequests: JsonField = JsonMissing.of(), + @JsonProperty("object") @ExcludeMissing object_: JsonValue = JsonMissing.of(), + @JsonProperty("api_key_id") + @ExcludeMissing + apiKeyId: JsonField = JsonMissing.of(), + @JsonProperty("context_level") + @ExcludeMissing + contextLevel: JsonField = JsonMissing.of(), + @JsonProperty("model") + @ExcludeMissing + model: JsonField = JsonMissing.of(), + @JsonProperty("project_id") + @ExcludeMissing + projectId: JsonField = JsonMissing.of(), + @JsonProperty("user_id") + @ExcludeMissing + userId: JsonField = JsonMissing.of(), + ) : this( + numModelRequests, + numRequests, + object_, + apiKeyId, + contextLevel, + model, + projectId, + userId, + mutableMapOf(), + ) + + /** + * The count of model requests. + * + * @throws OpenAIInvalidDataException 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 numModelRequests(): Long = numModelRequests.getRequired("num_model_requests") + + /** + * The count of web search calls. + * + * @throws OpenAIInvalidDataException 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 numRequests(): Long = numRequests.getRequired("num_requests") + + /** + * Expected to always return the following: + * ```java + * JsonValue.from("organization.usage.web_searches.result") + * ``` + * + * However, this method can be useful for debugging and logging (e.g. if the server + * responded with an unexpected value). + */ + @JsonProperty("object") @ExcludeMissing fun _object_(): JsonValue = object_ + + /** + * When `group_by=api_key_id`, this field provides the API key ID of the grouped + * usage result. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun apiKeyId(): Optional = apiKeyId.getOptional("api_key_id") + + /** + * When `group_by=context_level`, this field provides the search context size of the + * grouped usage result. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun contextLevel(): Optional = contextLevel.getOptional("context_level") + + /** + * When `group_by=model`, this field provides the model name of the grouped usage + * result. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun model(): Optional = model.getOptional("model") + + /** + * When `group_by=project_id`, this field provides the project ID of the grouped + * usage result. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun projectId(): Optional = projectId.getOptional("project_id") + + /** + * When `group_by=user_id`, this field provides the user ID of the grouped usage + * result. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun userId(): Optional = userId.getOptional("user_id") + + /** + * Returns the raw JSON value of [numModelRequests]. + * + * Unlike [numModelRequests], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("num_model_requests") + @ExcludeMissing + fun _numModelRequests(): JsonField = numModelRequests + + /** + * Returns the raw JSON value of [numRequests]. + * + * Unlike [numRequests], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("num_requests") + @ExcludeMissing + fun _numRequests(): JsonField = numRequests + + /** + * Returns the raw JSON value of [apiKeyId]. + * + * Unlike [apiKeyId], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("api_key_id") + @ExcludeMissing + fun _apiKeyId(): JsonField = apiKeyId + + /** + * Returns the raw JSON value of [contextLevel]. + * + * Unlike [contextLevel], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("context_level") + @ExcludeMissing + fun _contextLevel(): JsonField = contextLevel + + /** + * Returns the raw JSON value of [model]. + * + * Unlike [model], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("model") @ExcludeMissing fun _model(): JsonField = model + + /** + * 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 [userId]. + * + * Unlike [userId], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @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 = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of + * [OrganizationUsageWebSearchesResult]. + * + * The following fields are required: + * ```java + * .numModelRequests() + * .numRequests() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [OrganizationUsageWebSearchesResult]. */ + class Builder internal constructor() { + + private var numModelRequests: JsonField? = null + private var numRequests: JsonField? = null + private var object_: JsonValue = + JsonValue.from("organization.usage.web_searches.result") + private var apiKeyId: JsonField = JsonMissing.of() + private var contextLevel: JsonField = JsonMissing.of() + private var model: JsonField = JsonMissing.of() + private var projectId: JsonField = JsonMissing.of() + private var userId: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from( + organizationUsageWebSearchesResult: OrganizationUsageWebSearchesResult + ) = apply { + numModelRequests = organizationUsageWebSearchesResult.numModelRequests + numRequests = organizationUsageWebSearchesResult.numRequests + object_ = organizationUsageWebSearchesResult.object_ + apiKeyId = organizationUsageWebSearchesResult.apiKeyId + contextLevel = organizationUsageWebSearchesResult.contextLevel + model = organizationUsageWebSearchesResult.model + projectId = organizationUsageWebSearchesResult.projectId + userId = organizationUsageWebSearchesResult.userId + additionalProperties = + organizationUsageWebSearchesResult.additionalProperties.toMutableMap() + } + + /** The count of model requests. */ + fun numModelRequests(numModelRequests: Long) = + numModelRequests(JsonField.of(numModelRequests)) + + /** + * Sets [Builder.numModelRequests] to an arbitrary JSON value. + * + * You should usually call [Builder.numModelRequests] with a well-typed [Long] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun numModelRequests(numModelRequests: JsonField) = apply { + this.numModelRequests = numModelRequests + } + + /** The count of web search calls. */ + fun numRequests(numRequests: Long) = numRequests(JsonField.of(numRequests)) + + /** + * Sets [Builder.numRequests] to an arbitrary JSON value. + * + * You should usually call [Builder.numRequests] with a well-typed [Long] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun numRequests(numRequests: JsonField) = apply { + this.numRequests = numRequests + } + + /** + * Sets the field to an arbitrary JSON value. + * + * It is usually unnecessary to call this method because the field defaults to + * the following: + * ```java + * JsonValue.from("organization.usage.web_searches.result") + * ``` + * + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun object_(object_: JsonValue) = apply { this.object_ = object_ } + + /** + * When `group_by=api_key_id`, this field provides the API key ID of the grouped + * usage result. + */ + fun apiKeyId(apiKeyId: String?) = apiKeyId(JsonField.ofNullable(apiKeyId)) + + /** Alias for calling [Builder.apiKeyId] with `apiKeyId.orElse(null)`. */ + fun apiKeyId(apiKeyId: Optional) = apiKeyId(apiKeyId.getOrNull()) + + /** + * Sets [Builder.apiKeyId] to an arbitrary JSON value. + * + * You should usually call [Builder.apiKeyId] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun apiKeyId(apiKeyId: JsonField) = apply { this.apiKeyId = apiKeyId } + + /** + * When `group_by=context_level`, this field provides the search context size of + * the grouped usage result. + */ + fun contextLevel(contextLevel: String?) = + contextLevel(JsonField.ofNullable(contextLevel)) + + /** + * Alias for calling [Builder.contextLevel] with `contextLevel.orElse(null)`. + */ + fun contextLevel(contextLevel: Optional) = + contextLevel(contextLevel.getOrNull()) + + /** + * Sets [Builder.contextLevel] to an arbitrary JSON value. + * + * You should usually call [Builder.contextLevel] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun contextLevel(contextLevel: JsonField) = apply { + this.contextLevel = contextLevel + } + + /** + * When `group_by=model`, this field provides the model name of the grouped + * usage result. + */ + fun model(model: String?) = model(JsonField.ofNullable(model)) + + /** Alias for calling [Builder.model] with `model.orElse(null)`. */ + fun model(model: Optional) = model(model.getOrNull()) + + /** + * Sets [Builder.model] to an arbitrary JSON value. + * + * You should usually call [Builder.model] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun model(model: JsonField) = apply { this.model = model } + + /** + * When `group_by=project_id`, this field provides the project ID of the grouped + * usage result. + */ + fun projectId(projectId: String?) = projectId(JsonField.ofNullable(projectId)) + + /** Alias for calling [Builder.projectId] with `projectId.orElse(null)`. */ + fun projectId(projectId: Optional) = projectId(projectId.getOrNull()) + + /** + * 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 + } + + /** + * When `group_by=user_id`, this field provides the user ID of the grouped usage + * result. + */ + 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 } + + 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 [OrganizationUsageWebSearchesResult]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .numModelRequests() + * .numRequests() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): OrganizationUsageWebSearchesResult = + OrganizationUsageWebSearchesResult( + checkRequired("numModelRequests", numModelRequests), + checkRequired("numRequests", numRequests), + object_, + apiKeyId, + contextLevel, + model, + projectId, + userId, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing + * fields. + * + * @throws OpenAIInvalidDataException if any value type in this object doesn't match + * its expected type. + */ + fun validate(): OrganizationUsageWebSearchesResult = apply { + if (validated) { + return@apply + } + + numModelRequests() + numRequests() + _object_().let { + if (it != JsonValue.from("organization.usage.web_searches.result")) { + throw OpenAIInvalidDataException("'object_' is invalid, received $it") + } + } + apiKeyId() + contextLevel() + model() + projectId() + userId() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OpenAIInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (if (numModelRequests.asKnown().isPresent) 1 else 0) + + (if (numRequests.asKnown().isPresent) 1 else 0) + + object_.let { + if (it == JsonValue.from("organization.usage.web_searches.result")) 1 + else 0 + } + + (if (apiKeyId.asKnown().isPresent) 1 else 0) + + (if (contextLevel.asKnown().isPresent) 1 else 0) + + (if (model.asKnown().isPresent) 1 else 0) + + (if (projectId.asKnown().isPresent) 1 else 0) + + (if (userId.asKnown().isPresent) 1 else 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is OrganizationUsageWebSearchesResult && + numModelRequests == other.numModelRequests && + numRequests == other.numRequests && + object_ == other.object_ && + apiKeyId == other.apiKeyId && + contextLevel == other.contextLevel && + model == other.model && + projectId == other.projectId && + userId == other.userId && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + numModelRequests, + numRequests, + object_, + apiKeyId, + contextLevel, + model, + projectId, + userId, + additionalProperties, + ) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "OrganizationUsageWebSearchesResult{numModelRequests=$numModelRequests, numRequests=$numRequests, object_=$object_, apiKeyId=$apiKeyId, contextLevel=$contextLevel, model=$model, projectId=$projectId, userId=$userId, additionalProperties=$additionalProperties}" + } + /** The aggregated costs details of the specific time bucket. */ class OrganizationCostsResult @JsonCreator(mode = JsonCreator.Mode.DISABLED) diff --git a/openai-java-core/src/main/kotlin/com/openai/models/admin/organization/usage/UsageCostsResponse.kt b/openai-java-core/src/main/kotlin/com/openai/models/admin/organization/usage/UsageCostsResponse.kt index 54be7a20e..760f89b5c 100644 --- a/openai-java-core/src/main/kotlin/com/openai/models/admin/organization/usage/UsageCostsResponse.kt +++ b/openai-java-core/src/main/kotlin/com/openai/models/admin/organization/usage/UsageCostsResponse.kt @@ -561,6 +561,36 @@ private constructor( .build() ) + /** + * Alias for calling [addResult] with + * `Result.ofOrganizationUsageFileSearches(organizationUsageFileSearches)`. + */ + fun addResult( + organizationUsageFileSearches: Result.OrganizationUsageFileSearchesResult + ) = addResult(Result.ofOrganizationUsageFileSearches(organizationUsageFileSearches)) + + /** + * Alias for calling [addResult] with the following: + * ```java + * Result.OrganizationUsageFileSearchesResult.builder() + * .numRequests(numRequests) + * .build() + * ``` + */ + fun addOrganizationUsageFileSearchesResult(numRequests: Long) = + addResult( + Result.OrganizationUsageFileSearchesResult.builder() + .numRequests(numRequests) + .build() + ) + + /** + * Alias for calling [addResult] with + * `Result.ofOrganizationUsageWebSearches(organizationUsageWebSearches)`. + */ + fun addResult(organizationUsageWebSearches: Result.OrganizationUsageWebSearchesResult) = + addResult(Result.ofOrganizationUsageWebSearches(organizationUsageWebSearches)) + /** * Alias for calling [addResult] with `Result.ofOrganizationCosts(organizationCosts)`. */ @@ -687,6 +717,8 @@ private constructor( private val organizationUsageCodeInterpreterSessions: OrganizationUsageCodeInterpreterSessionsResult? = null, + private val organizationUsageFileSearches: OrganizationUsageFileSearchesResult? = null, + private val organizationUsageWebSearches: OrganizationUsageWebSearchesResult? = null, private val organizationCosts: OrganizationCostsResult? = null, private val _json: JsonValue? = null, ) { @@ -727,6 +759,14 @@ private constructor( Optional = Optional.ofNullable(organizationUsageCodeInterpreterSessions) + /** The aggregated file search calls usage details of the specific time bucket. */ + fun organizationUsageFileSearches(): Optional = + Optional.ofNullable(organizationUsageFileSearches) + + /** The aggregated web search calls usage details of the specific time bucket. */ + fun organizationUsageWebSearches(): Optional = + Optional.ofNullable(organizationUsageWebSearches) + /** The aggregated costs details of the specific time bucket. */ fun organizationCosts(): Optional = Optional.ofNullable(organizationCosts) @@ -749,6 +789,10 @@ private constructor( fun isOrganizationUsageCodeInterpreterSessions(): Boolean = organizationUsageCodeInterpreterSessions != null + fun isOrganizationUsageFileSearches(): Boolean = organizationUsageFileSearches != null + + fun isOrganizationUsageWebSearches(): Boolean = organizationUsageWebSearches != null + fun isOrganizationCosts(): Boolean = organizationCosts != null /** The aggregated completions usage details of the specific time bucket. */ @@ -791,6 +835,14 @@ private constructor( "organizationUsageCodeInterpreterSessions" ) + /** The aggregated file search calls usage details of the specific time bucket. */ + fun asOrganizationUsageFileSearches(): OrganizationUsageFileSearchesResult = + organizationUsageFileSearches.getOrThrow("organizationUsageFileSearches") + + /** The aggregated web search calls usage details of the specific time bucket. */ + fun asOrganizationUsageWebSearches(): OrganizationUsageWebSearchesResult = + organizationUsageWebSearches.getOrThrow("organizationUsageWebSearches") + /** The aggregated costs details of the specific time bucket. */ fun asOrganizationCosts(): OrganizationCostsResult = organizationCosts.getOrThrow("organizationCosts") @@ -849,6 +901,10 @@ private constructor( visitor.visitOrganizationUsageCodeInterpreterSessions( organizationUsageCodeInterpreterSessions ) + organizationUsageFileSearches != null -> + visitor.visitOrganizationUsageFileSearches(organizationUsageFileSearches) + organizationUsageWebSearches != null -> + visitor.visitOrganizationUsageWebSearches(organizationUsageWebSearches) organizationCosts != null -> visitor.visitOrganizationCosts(organizationCosts) else -> visitor.unknown(_json) } @@ -922,6 +978,18 @@ private constructor( organizationUsageCodeInterpreterSessions.validate() } + override fun visitOrganizationUsageFileSearches( + organizationUsageFileSearches: OrganizationUsageFileSearchesResult + ) { + organizationUsageFileSearches.validate() + } + + override fun visitOrganizationUsageWebSearches( + organizationUsageWebSearches: OrganizationUsageWebSearchesResult + ) { + organizationUsageWebSearches.validate() + } + override fun visitOrganizationCosts( organizationCosts: OrganizationCostsResult ) { @@ -984,6 +1052,14 @@ private constructor( OrganizationUsageCodeInterpreterSessionsResult ) = organizationUsageCodeInterpreterSessions.validity() + override fun visitOrganizationUsageFileSearches( + organizationUsageFileSearches: OrganizationUsageFileSearchesResult + ) = organizationUsageFileSearches.validity() + + override fun visitOrganizationUsageWebSearches( + organizationUsageWebSearches: OrganizationUsageWebSearchesResult + ) = organizationUsageWebSearches.validity() + override fun visitOrganizationCosts( organizationCosts: OrganizationCostsResult ) = organizationCosts.validity() @@ -1008,6 +1084,8 @@ private constructor( organizationUsageVectorStores == other.organizationUsageVectorStores && organizationUsageCodeInterpreterSessions == other.organizationUsageCodeInterpreterSessions && + organizationUsageFileSearches == other.organizationUsageFileSearches && + organizationUsageWebSearches == other.organizationUsageWebSearches && organizationCosts == other.organizationCosts } @@ -1021,6 +1099,8 @@ private constructor( organizationUsageAudioTranscriptions, organizationUsageVectorStores, organizationUsageCodeInterpreterSessions, + organizationUsageFileSearches, + organizationUsageWebSearches, organizationCosts, ) @@ -1042,6 +1122,10 @@ private constructor( "Result{organizationUsageVectorStores=$organizationUsageVectorStores}" organizationUsageCodeInterpreterSessions != null -> "Result{organizationUsageCodeInterpreterSessions=$organizationUsageCodeInterpreterSessions}" + organizationUsageFileSearches != null -> + "Result{organizationUsageFileSearches=$organizationUsageFileSearches}" + organizationUsageWebSearches != null -> + "Result{organizationUsageWebSearches=$organizationUsageWebSearches}" organizationCosts != null -> "Result{organizationCosts=$organizationCosts}" _json != null -> "Result{_unknown=$_json}" else -> throw IllegalStateException("Invalid Result") @@ -1110,6 +1194,18 @@ private constructor( organizationUsageCodeInterpreterSessions ) + /** The aggregated file search calls usage details of the specific time bucket. */ + @JvmStatic + fun ofOrganizationUsageFileSearches( + organizationUsageFileSearches: OrganizationUsageFileSearchesResult + ) = Result(organizationUsageFileSearches = organizationUsageFileSearches) + + /** The aggregated web search calls usage details of the specific time bucket. */ + @JvmStatic + fun ofOrganizationUsageWebSearches( + organizationUsageWebSearches: OrganizationUsageWebSearchesResult + ) = Result(organizationUsageWebSearches = organizationUsageWebSearches) + /** The aggregated costs details of the specific time bucket. */ @JvmStatic fun ofOrganizationCosts(organizationCosts: OrganizationCostsResult) = @@ -1167,6 +1263,16 @@ private constructor( OrganizationUsageCodeInterpreterSessionsResult ): T + /** The aggregated file search calls usage details of the specific time bucket. */ + fun visitOrganizationUsageFileSearches( + organizationUsageFileSearches: OrganizationUsageFileSearchesResult + ): T + + /** The aggregated web search calls usage details of the specific time bucket. */ + fun visitOrganizationUsageWebSearches( + organizationUsageWebSearches: OrganizationUsageWebSearchesResult + ): T + /** The aggregated costs details of the specific time bucket. */ fun visitOrganizationCosts(organizationCosts: OrganizationCostsResult): T @@ -1262,6 +1368,22 @@ private constructor( ) } ?: Result(_json = json) } + "organization.usage.file_searches.result" -> { + return tryDeserialize( + node, + jacksonTypeRef(), + ) + ?.let { Result(organizationUsageFileSearches = it, _json = json) } + ?: Result(_json = json) + } + "organization.usage.web_searches.result" -> { + return tryDeserialize( + node, + jacksonTypeRef(), + ) + ?.let { Result(organizationUsageWebSearches = it, _json = json) } + ?: Result(_json = json) + } "organization.costs.result" -> { return tryDeserialize(node, jacksonTypeRef()) ?.let { Result(organizationCosts = it, _json = json) } @@ -1297,6 +1419,10 @@ private constructor( generator.writeObject(value.organizationUsageVectorStores) value.organizationUsageCodeInterpreterSessions != null -> generator.writeObject(value.organizationUsageCodeInterpreterSessions) + value.organizationUsageFileSearches != null -> + generator.writeObject(value.organizationUsageFileSearches) + value.organizationUsageWebSearches != null -> + generator.writeObject(value.organizationUsageWebSearches) value.organizationCosts != null -> generator.writeObject(value.organizationCosts) value._json != null -> generator.writeObject(value._json) @@ -5162,6 +5288,981 @@ private constructor( "OrganizationUsageCodeInterpreterSessionsResult{numSessions=$numSessions, object_=$object_, projectId=$projectId, additionalProperties=$additionalProperties}" } + /** The aggregated file search calls usage details of the specific time bucket. */ + class OrganizationUsageFileSearchesResult + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val numRequests: JsonField, + private val object_: JsonValue, + private val apiKeyId: JsonField, + private val projectId: JsonField, + private val userId: JsonField, + private val vectorStoreId: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("num_requests") + @ExcludeMissing + numRequests: JsonField = JsonMissing.of(), + @JsonProperty("object") @ExcludeMissing object_: JsonValue = JsonMissing.of(), + @JsonProperty("api_key_id") + @ExcludeMissing + apiKeyId: JsonField = JsonMissing.of(), + @JsonProperty("project_id") + @ExcludeMissing + projectId: JsonField = JsonMissing.of(), + @JsonProperty("user_id") + @ExcludeMissing + userId: JsonField = JsonMissing.of(), + @JsonProperty("vector_store_id") + @ExcludeMissing + vectorStoreId: JsonField = JsonMissing.of(), + ) : this( + numRequests, + object_, + apiKeyId, + projectId, + userId, + vectorStoreId, + mutableMapOf(), + ) + + /** + * The count of file search calls. + * + * @throws OpenAIInvalidDataException 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 numRequests(): Long = numRequests.getRequired("num_requests") + + /** + * Expected to always return the following: + * ```java + * JsonValue.from("organization.usage.file_searches.result") + * ``` + * + * However, this method can be useful for debugging and logging (e.g. if the server + * responded with an unexpected value). + */ + @JsonProperty("object") @ExcludeMissing fun _object_(): JsonValue = object_ + + /** + * When `group_by=api_key_id`, this field provides the API key ID of the grouped + * usage result. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun apiKeyId(): Optional = apiKeyId.getOptional("api_key_id") + + /** + * When `group_by=project_id`, this field provides the project ID of the grouped + * usage result. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun projectId(): Optional = projectId.getOptional("project_id") + + /** + * When `group_by=user_id`, this field provides the user ID of the grouped usage + * result. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun userId(): Optional = userId.getOptional("user_id") + + /** + * When `group_by=vector_store_id`, this field provides the vector store ID of the + * grouped usage result. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun vectorStoreId(): Optional = vectorStoreId.getOptional("vector_store_id") + + /** + * Returns the raw JSON value of [numRequests]. + * + * Unlike [numRequests], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("num_requests") + @ExcludeMissing + fun _numRequests(): JsonField = numRequests + + /** + * Returns the raw JSON value of [apiKeyId]. + * + * Unlike [apiKeyId], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("api_key_id") + @ExcludeMissing + fun _apiKeyId(): JsonField = apiKeyId + + /** + * 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 [userId]. + * + * Unlike [userId], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("user_id") @ExcludeMissing fun _userId(): JsonField = userId + + /** + * Returns the raw JSON value of [vectorStoreId]. + * + * Unlike [vectorStoreId], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("vector_store_id") + @ExcludeMissing + fun _vectorStoreId(): JsonField = vectorStoreId + + @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 + * [OrganizationUsageFileSearchesResult]. + * + * The following fields are required: + * ```java + * .numRequests() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [OrganizationUsageFileSearchesResult]. */ + class Builder internal constructor() { + + private var numRequests: JsonField? = null + private var object_: JsonValue = + JsonValue.from("organization.usage.file_searches.result") + private var apiKeyId: JsonField = JsonMissing.of() + private var projectId: JsonField = JsonMissing.of() + private var userId: JsonField = JsonMissing.of() + private var vectorStoreId: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from( + organizationUsageFileSearchesResult: OrganizationUsageFileSearchesResult + ) = apply { + numRequests = organizationUsageFileSearchesResult.numRequests + object_ = organizationUsageFileSearchesResult.object_ + apiKeyId = organizationUsageFileSearchesResult.apiKeyId + projectId = organizationUsageFileSearchesResult.projectId + userId = organizationUsageFileSearchesResult.userId + vectorStoreId = organizationUsageFileSearchesResult.vectorStoreId + additionalProperties = + organizationUsageFileSearchesResult.additionalProperties.toMutableMap() + } + + /** The count of file search calls. */ + fun numRequests(numRequests: Long) = numRequests(JsonField.of(numRequests)) + + /** + * Sets [Builder.numRequests] to an arbitrary JSON value. + * + * You should usually call [Builder.numRequests] with a well-typed [Long] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun numRequests(numRequests: JsonField) = apply { + this.numRequests = numRequests + } + + /** + * Sets the field to an arbitrary JSON value. + * + * It is usually unnecessary to call this method because the field defaults to + * the following: + * ```java + * JsonValue.from("organization.usage.file_searches.result") + * ``` + * + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun object_(object_: JsonValue) = apply { this.object_ = object_ } + + /** + * When `group_by=api_key_id`, this field provides the API key ID of the grouped + * usage result. + */ + fun apiKeyId(apiKeyId: String?) = apiKeyId(JsonField.ofNullable(apiKeyId)) + + /** Alias for calling [Builder.apiKeyId] with `apiKeyId.orElse(null)`. */ + fun apiKeyId(apiKeyId: Optional) = apiKeyId(apiKeyId.getOrNull()) + + /** + * Sets [Builder.apiKeyId] to an arbitrary JSON value. + * + * You should usually call [Builder.apiKeyId] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun apiKeyId(apiKeyId: JsonField) = apply { this.apiKeyId = apiKeyId } + + /** + * When `group_by=project_id`, this field provides the project ID of the grouped + * usage result. + */ + fun projectId(projectId: String?) = projectId(JsonField.ofNullable(projectId)) + + /** Alias for calling [Builder.projectId] with `projectId.orElse(null)`. */ + fun projectId(projectId: Optional) = projectId(projectId.getOrNull()) + + /** + * 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 + } + + /** + * When `group_by=user_id`, this field provides the user ID of the grouped usage + * result. + */ + 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 } + + /** + * When `group_by=vector_store_id`, this field provides the vector store ID of + * the grouped usage result. + */ + fun vectorStoreId(vectorStoreId: String?) = + vectorStoreId(JsonField.ofNullable(vectorStoreId)) + + /** + * Alias for calling [Builder.vectorStoreId] with `vectorStoreId.orElse(null)`. + */ + fun vectorStoreId(vectorStoreId: Optional) = + vectorStoreId(vectorStoreId.getOrNull()) + + /** + * Sets [Builder.vectorStoreId] to an arbitrary JSON value. + * + * You should usually call [Builder.vectorStoreId] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun vectorStoreId(vectorStoreId: JsonField) = apply { + this.vectorStoreId = vectorStoreId + } + + 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 [OrganizationUsageFileSearchesResult]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .numRequests() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): OrganizationUsageFileSearchesResult = + OrganizationUsageFileSearchesResult( + checkRequired("numRequests", numRequests), + object_, + apiKeyId, + projectId, + userId, + vectorStoreId, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing + * fields. + * + * @throws OpenAIInvalidDataException if any value type in this object doesn't match + * its expected type. + */ + fun validate(): OrganizationUsageFileSearchesResult = apply { + if (validated) { + return@apply + } + + numRequests() + _object_().let { + if (it != JsonValue.from("organization.usage.file_searches.result")) { + throw OpenAIInvalidDataException("'object_' is invalid, received $it") + } + } + apiKeyId() + projectId() + userId() + vectorStoreId() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OpenAIInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (if (numRequests.asKnown().isPresent) 1 else 0) + + object_.let { + if (it == JsonValue.from("organization.usage.file_searches.result")) 1 + else 0 + } + + (if (apiKeyId.asKnown().isPresent) 1 else 0) + + (if (projectId.asKnown().isPresent) 1 else 0) + + (if (userId.asKnown().isPresent) 1 else 0) + + (if (vectorStoreId.asKnown().isPresent) 1 else 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is OrganizationUsageFileSearchesResult && + numRequests == other.numRequests && + object_ == other.object_ && + apiKeyId == other.apiKeyId && + projectId == other.projectId && + userId == other.userId && + vectorStoreId == other.vectorStoreId && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + numRequests, + object_, + apiKeyId, + projectId, + userId, + vectorStoreId, + additionalProperties, + ) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "OrganizationUsageFileSearchesResult{numRequests=$numRequests, object_=$object_, apiKeyId=$apiKeyId, projectId=$projectId, userId=$userId, vectorStoreId=$vectorStoreId, additionalProperties=$additionalProperties}" + } + + /** The aggregated web search calls usage details of the specific time bucket. */ + class OrganizationUsageWebSearchesResult + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val numModelRequests: JsonField, + private val numRequests: JsonField, + private val object_: JsonValue, + private val apiKeyId: JsonField, + private val contextLevel: JsonField, + private val model: JsonField, + private val projectId: JsonField, + private val userId: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("num_model_requests") + @ExcludeMissing + numModelRequests: JsonField = JsonMissing.of(), + @JsonProperty("num_requests") + @ExcludeMissing + numRequests: JsonField = JsonMissing.of(), + @JsonProperty("object") @ExcludeMissing object_: JsonValue = JsonMissing.of(), + @JsonProperty("api_key_id") + @ExcludeMissing + apiKeyId: JsonField = JsonMissing.of(), + @JsonProperty("context_level") + @ExcludeMissing + contextLevel: JsonField = JsonMissing.of(), + @JsonProperty("model") + @ExcludeMissing + model: JsonField = JsonMissing.of(), + @JsonProperty("project_id") + @ExcludeMissing + projectId: JsonField = JsonMissing.of(), + @JsonProperty("user_id") + @ExcludeMissing + userId: JsonField = JsonMissing.of(), + ) : this( + numModelRequests, + numRequests, + object_, + apiKeyId, + contextLevel, + model, + projectId, + userId, + mutableMapOf(), + ) + + /** + * The count of model requests. + * + * @throws OpenAIInvalidDataException 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 numModelRequests(): Long = numModelRequests.getRequired("num_model_requests") + + /** + * The count of web search calls. + * + * @throws OpenAIInvalidDataException 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 numRequests(): Long = numRequests.getRequired("num_requests") + + /** + * Expected to always return the following: + * ```java + * JsonValue.from("organization.usage.web_searches.result") + * ``` + * + * However, this method can be useful for debugging and logging (e.g. if the server + * responded with an unexpected value). + */ + @JsonProperty("object") @ExcludeMissing fun _object_(): JsonValue = object_ + + /** + * When `group_by=api_key_id`, this field provides the API key ID of the grouped + * usage result. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun apiKeyId(): Optional = apiKeyId.getOptional("api_key_id") + + /** + * When `group_by=context_level`, this field provides the search context size of the + * grouped usage result. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun contextLevel(): Optional = contextLevel.getOptional("context_level") + + /** + * When `group_by=model`, this field provides the model name of the grouped usage + * result. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun model(): Optional = model.getOptional("model") + + /** + * When `group_by=project_id`, this field provides the project ID of the grouped + * usage result. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun projectId(): Optional = projectId.getOptional("project_id") + + /** + * When `group_by=user_id`, this field provides the user ID of the grouped usage + * result. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun userId(): Optional = userId.getOptional("user_id") + + /** + * Returns the raw JSON value of [numModelRequests]. + * + * Unlike [numModelRequests], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("num_model_requests") + @ExcludeMissing + fun _numModelRequests(): JsonField = numModelRequests + + /** + * Returns the raw JSON value of [numRequests]. + * + * Unlike [numRequests], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("num_requests") + @ExcludeMissing + fun _numRequests(): JsonField = numRequests + + /** + * Returns the raw JSON value of [apiKeyId]. + * + * Unlike [apiKeyId], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("api_key_id") + @ExcludeMissing + fun _apiKeyId(): JsonField = apiKeyId + + /** + * Returns the raw JSON value of [contextLevel]. + * + * Unlike [contextLevel], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("context_level") + @ExcludeMissing + fun _contextLevel(): JsonField = contextLevel + + /** + * Returns the raw JSON value of [model]. + * + * Unlike [model], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("model") @ExcludeMissing fun _model(): JsonField = model + + /** + * 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 [userId]. + * + * Unlike [userId], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @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 = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of + * [OrganizationUsageWebSearchesResult]. + * + * The following fields are required: + * ```java + * .numModelRequests() + * .numRequests() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [OrganizationUsageWebSearchesResult]. */ + class Builder internal constructor() { + + private var numModelRequests: JsonField? = null + private var numRequests: JsonField? = null + private var object_: JsonValue = + JsonValue.from("organization.usage.web_searches.result") + private var apiKeyId: JsonField = JsonMissing.of() + private var contextLevel: JsonField = JsonMissing.of() + private var model: JsonField = JsonMissing.of() + private var projectId: JsonField = JsonMissing.of() + private var userId: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from( + organizationUsageWebSearchesResult: OrganizationUsageWebSearchesResult + ) = apply { + numModelRequests = organizationUsageWebSearchesResult.numModelRequests + numRequests = organizationUsageWebSearchesResult.numRequests + object_ = organizationUsageWebSearchesResult.object_ + apiKeyId = organizationUsageWebSearchesResult.apiKeyId + contextLevel = organizationUsageWebSearchesResult.contextLevel + model = organizationUsageWebSearchesResult.model + projectId = organizationUsageWebSearchesResult.projectId + userId = organizationUsageWebSearchesResult.userId + additionalProperties = + organizationUsageWebSearchesResult.additionalProperties.toMutableMap() + } + + /** The count of model requests. */ + fun numModelRequests(numModelRequests: Long) = + numModelRequests(JsonField.of(numModelRequests)) + + /** + * Sets [Builder.numModelRequests] to an arbitrary JSON value. + * + * You should usually call [Builder.numModelRequests] with a well-typed [Long] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun numModelRequests(numModelRequests: JsonField) = apply { + this.numModelRequests = numModelRequests + } + + /** The count of web search calls. */ + fun numRequests(numRequests: Long) = numRequests(JsonField.of(numRequests)) + + /** + * Sets [Builder.numRequests] to an arbitrary JSON value. + * + * You should usually call [Builder.numRequests] with a well-typed [Long] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun numRequests(numRequests: JsonField) = apply { + this.numRequests = numRequests + } + + /** + * Sets the field to an arbitrary JSON value. + * + * It is usually unnecessary to call this method because the field defaults to + * the following: + * ```java + * JsonValue.from("organization.usage.web_searches.result") + * ``` + * + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun object_(object_: JsonValue) = apply { this.object_ = object_ } + + /** + * When `group_by=api_key_id`, this field provides the API key ID of the grouped + * usage result. + */ + fun apiKeyId(apiKeyId: String?) = apiKeyId(JsonField.ofNullable(apiKeyId)) + + /** Alias for calling [Builder.apiKeyId] with `apiKeyId.orElse(null)`. */ + fun apiKeyId(apiKeyId: Optional) = apiKeyId(apiKeyId.getOrNull()) + + /** + * Sets [Builder.apiKeyId] to an arbitrary JSON value. + * + * You should usually call [Builder.apiKeyId] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun apiKeyId(apiKeyId: JsonField) = apply { this.apiKeyId = apiKeyId } + + /** + * When `group_by=context_level`, this field provides the search context size of + * the grouped usage result. + */ + fun contextLevel(contextLevel: String?) = + contextLevel(JsonField.ofNullable(contextLevel)) + + /** + * Alias for calling [Builder.contextLevel] with `contextLevel.orElse(null)`. + */ + fun contextLevel(contextLevel: Optional) = + contextLevel(contextLevel.getOrNull()) + + /** + * Sets [Builder.contextLevel] to an arbitrary JSON value. + * + * You should usually call [Builder.contextLevel] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun contextLevel(contextLevel: JsonField) = apply { + this.contextLevel = contextLevel + } + + /** + * When `group_by=model`, this field provides the model name of the grouped + * usage result. + */ + fun model(model: String?) = model(JsonField.ofNullable(model)) + + /** Alias for calling [Builder.model] with `model.orElse(null)`. */ + fun model(model: Optional) = model(model.getOrNull()) + + /** + * Sets [Builder.model] to an arbitrary JSON value. + * + * You should usually call [Builder.model] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun model(model: JsonField) = apply { this.model = model } + + /** + * When `group_by=project_id`, this field provides the project ID of the grouped + * usage result. + */ + fun projectId(projectId: String?) = projectId(JsonField.ofNullable(projectId)) + + /** Alias for calling [Builder.projectId] with `projectId.orElse(null)`. */ + fun projectId(projectId: Optional) = projectId(projectId.getOrNull()) + + /** + * 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 + } + + /** + * When `group_by=user_id`, this field provides the user ID of the grouped usage + * result. + */ + 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 } + + 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 [OrganizationUsageWebSearchesResult]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .numModelRequests() + * .numRequests() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): OrganizationUsageWebSearchesResult = + OrganizationUsageWebSearchesResult( + checkRequired("numModelRequests", numModelRequests), + checkRequired("numRequests", numRequests), + object_, + apiKeyId, + contextLevel, + model, + projectId, + userId, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing + * fields. + * + * @throws OpenAIInvalidDataException if any value type in this object doesn't match + * its expected type. + */ + fun validate(): OrganizationUsageWebSearchesResult = apply { + if (validated) { + return@apply + } + + numModelRequests() + numRequests() + _object_().let { + if (it != JsonValue.from("organization.usage.web_searches.result")) { + throw OpenAIInvalidDataException("'object_' is invalid, received $it") + } + } + apiKeyId() + contextLevel() + model() + projectId() + userId() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OpenAIInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (if (numModelRequests.asKnown().isPresent) 1 else 0) + + (if (numRequests.asKnown().isPresent) 1 else 0) + + object_.let { + if (it == JsonValue.from("organization.usage.web_searches.result")) 1 + else 0 + } + + (if (apiKeyId.asKnown().isPresent) 1 else 0) + + (if (contextLevel.asKnown().isPresent) 1 else 0) + + (if (model.asKnown().isPresent) 1 else 0) + + (if (projectId.asKnown().isPresent) 1 else 0) + + (if (userId.asKnown().isPresent) 1 else 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is OrganizationUsageWebSearchesResult && + numModelRequests == other.numModelRequests && + numRequests == other.numRequests && + object_ == other.object_ && + apiKeyId == other.apiKeyId && + contextLevel == other.contextLevel && + model == other.model && + projectId == other.projectId && + userId == other.userId && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + numModelRequests, + numRequests, + object_, + apiKeyId, + contextLevel, + model, + projectId, + userId, + additionalProperties, + ) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "OrganizationUsageWebSearchesResult{numModelRequests=$numModelRequests, numRequests=$numRequests, object_=$object_, apiKeyId=$apiKeyId, contextLevel=$contextLevel, model=$model, projectId=$projectId, userId=$userId, additionalProperties=$additionalProperties}" + } + /** The aggregated costs details of the specific time bucket. */ class OrganizationCostsResult @JsonCreator(mode = JsonCreator.Mode.DISABLED) diff --git a/openai-java-core/src/main/kotlin/com/openai/models/admin/organization/usage/UsageEmbeddingsResponse.kt b/openai-java-core/src/main/kotlin/com/openai/models/admin/organization/usage/UsageEmbeddingsResponse.kt index 20b293ad4..88472bb36 100644 --- a/openai-java-core/src/main/kotlin/com/openai/models/admin/organization/usage/UsageEmbeddingsResponse.kt +++ b/openai-java-core/src/main/kotlin/com/openai/models/admin/organization/usage/UsageEmbeddingsResponse.kt @@ -561,6 +561,36 @@ private constructor( .build() ) + /** + * Alias for calling [addResult] with + * `Result.ofOrganizationUsageFileSearches(organizationUsageFileSearches)`. + */ + fun addResult( + organizationUsageFileSearches: Result.OrganizationUsageFileSearchesResult + ) = addResult(Result.ofOrganizationUsageFileSearches(organizationUsageFileSearches)) + + /** + * Alias for calling [addResult] with the following: + * ```java + * Result.OrganizationUsageFileSearchesResult.builder() + * .numRequests(numRequests) + * .build() + * ``` + */ + fun addOrganizationUsageFileSearchesResult(numRequests: Long) = + addResult( + Result.OrganizationUsageFileSearchesResult.builder() + .numRequests(numRequests) + .build() + ) + + /** + * Alias for calling [addResult] with + * `Result.ofOrganizationUsageWebSearches(organizationUsageWebSearches)`. + */ + fun addResult(organizationUsageWebSearches: Result.OrganizationUsageWebSearchesResult) = + addResult(Result.ofOrganizationUsageWebSearches(organizationUsageWebSearches)) + /** * Alias for calling [addResult] with `Result.ofOrganizationCosts(organizationCosts)`. */ @@ -687,6 +717,8 @@ private constructor( private val organizationUsageCodeInterpreterSessions: OrganizationUsageCodeInterpreterSessionsResult? = null, + private val organizationUsageFileSearches: OrganizationUsageFileSearchesResult? = null, + private val organizationUsageWebSearches: OrganizationUsageWebSearchesResult? = null, private val organizationCosts: OrganizationCostsResult? = null, private val _json: JsonValue? = null, ) { @@ -727,6 +759,14 @@ private constructor( Optional = Optional.ofNullable(organizationUsageCodeInterpreterSessions) + /** The aggregated file search calls usage details of the specific time bucket. */ + fun organizationUsageFileSearches(): Optional = + Optional.ofNullable(organizationUsageFileSearches) + + /** The aggregated web search calls usage details of the specific time bucket. */ + fun organizationUsageWebSearches(): Optional = + Optional.ofNullable(organizationUsageWebSearches) + /** The aggregated costs details of the specific time bucket. */ fun organizationCosts(): Optional = Optional.ofNullable(organizationCosts) @@ -749,6 +789,10 @@ private constructor( fun isOrganizationUsageCodeInterpreterSessions(): Boolean = organizationUsageCodeInterpreterSessions != null + fun isOrganizationUsageFileSearches(): Boolean = organizationUsageFileSearches != null + + fun isOrganizationUsageWebSearches(): Boolean = organizationUsageWebSearches != null + fun isOrganizationCosts(): Boolean = organizationCosts != null /** The aggregated completions usage details of the specific time bucket. */ @@ -791,6 +835,14 @@ private constructor( "organizationUsageCodeInterpreterSessions" ) + /** The aggregated file search calls usage details of the specific time bucket. */ + fun asOrganizationUsageFileSearches(): OrganizationUsageFileSearchesResult = + organizationUsageFileSearches.getOrThrow("organizationUsageFileSearches") + + /** The aggregated web search calls usage details of the specific time bucket. */ + fun asOrganizationUsageWebSearches(): OrganizationUsageWebSearchesResult = + organizationUsageWebSearches.getOrThrow("organizationUsageWebSearches") + /** The aggregated costs details of the specific time bucket. */ fun asOrganizationCosts(): OrganizationCostsResult = organizationCosts.getOrThrow("organizationCosts") @@ -849,6 +901,10 @@ private constructor( visitor.visitOrganizationUsageCodeInterpreterSessions( organizationUsageCodeInterpreterSessions ) + organizationUsageFileSearches != null -> + visitor.visitOrganizationUsageFileSearches(organizationUsageFileSearches) + organizationUsageWebSearches != null -> + visitor.visitOrganizationUsageWebSearches(organizationUsageWebSearches) organizationCosts != null -> visitor.visitOrganizationCosts(organizationCosts) else -> visitor.unknown(_json) } @@ -922,6 +978,18 @@ private constructor( organizationUsageCodeInterpreterSessions.validate() } + override fun visitOrganizationUsageFileSearches( + organizationUsageFileSearches: OrganizationUsageFileSearchesResult + ) { + organizationUsageFileSearches.validate() + } + + override fun visitOrganizationUsageWebSearches( + organizationUsageWebSearches: OrganizationUsageWebSearchesResult + ) { + organizationUsageWebSearches.validate() + } + override fun visitOrganizationCosts( organizationCosts: OrganizationCostsResult ) { @@ -984,6 +1052,14 @@ private constructor( OrganizationUsageCodeInterpreterSessionsResult ) = organizationUsageCodeInterpreterSessions.validity() + override fun visitOrganizationUsageFileSearches( + organizationUsageFileSearches: OrganizationUsageFileSearchesResult + ) = organizationUsageFileSearches.validity() + + override fun visitOrganizationUsageWebSearches( + organizationUsageWebSearches: OrganizationUsageWebSearchesResult + ) = organizationUsageWebSearches.validity() + override fun visitOrganizationCosts( organizationCosts: OrganizationCostsResult ) = organizationCosts.validity() @@ -1008,6 +1084,8 @@ private constructor( organizationUsageVectorStores == other.organizationUsageVectorStores && organizationUsageCodeInterpreterSessions == other.organizationUsageCodeInterpreterSessions && + organizationUsageFileSearches == other.organizationUsageFileSearches && + organizationUsageWebSearches == other.organizationUsageWebSearches && organizationCosts == other.organizationCosts } @@ -1021,6 +1099,8 @@ private constructor( organizationUsageAudioTranscriptions, organizationUsageVectorStores, organizationUsageCodeInterpreterSessions, + organizationUsageFileSearches, + organizationUsageWebSearches, organizationCosts, ) @@ -1042,6 +1122,10 @@ private constructor( "Result{organizationUsageVectorStores=$organizationUsageVectorStores}" organizationUsageCodeInterpreterSessions != null -> "Result{organizationUsageCodeInterpreterSessions=$organizationUsageCodeInterpreterSessions}" + organizationUsageFileSearches != null -> + "Result{organizationUsageFileSearches=$organizationUsageFileSearches}" + organizationUsageWebSearches != null -> + "Result{organizationUsageWebSearches=$organizationUsageWebSearches}" organizationCosts != null -> "Result{organizationCosts=$organizationCosts}" _json != null -> "Result{_unknown=$_json}" else -> throw IllegalStateException("Invalid Result") @@ -1110,6 +1194,18 @@ private constructor( organizationUsageCodeInterpreterSessions ) + /** The aggregated file search calls usage details of the specific time bucket. */ + @JvmStatic + fun ofOrganizationUsageFileSearches( + organizationUsageFileSearches: OrganizationUsageFileSearchesResult + ) = Result(organizationUsageFileSearches = organizationUsageFileSearches) + + /** The aggregated web search calls usage details of the specific time bucket. */ + @JvmStatic + fun ofOrganizationUsageWebSearches( + organizationUsageWebSearches: OrganizationUsageWebSearchesResult + ) = Result(organizationUsageWebSearches = organizationUsageWebSearches) + /** The aggregated costs details of the specific time bucket. */ @JvmStatic fun ofOrganizationCosts(organizationCosts: OrganizationCostsResult) = @@ -1167,6 +1263,16 @@ private constructor( OrganizationUsageCodeInterpreterSessionsResult ): T + /** The aggregated file search calls usage details of the specific time bucket. */ + fun visitOrganizationUsageFileSearches( + organizationUsageFileSearches: OrganizationUsageFileSearchesResult + ): T + + /** The aggregated web search calls usage details of the specific time bucket. */ + fun visitOrganizationUsageWebSearches( + organizationUsageWebSearches: OrganizationUsageWebSearchesResult + ): T + /** The aggregated costs details of the specific time bucket. */ fun visitOrganizationCosts(organizationCosts: OrganizationCostsResult): T @@ -1262,6 +1368,22 @@ private constructor( ) } ?: Result(_json = json) } + "organization.usage.file_searches.result" -> { + return tryDeserialize( + node, + jacksonTypeRef(), + ) + ?.let { Result(organizationUsageFileSearches = it, _json = json) } + ?: Result(_json = json) + } + "organization.usage.web_searches.result" -> { + return tryDeserialize( + node, + jacksonTypeRef(), + ) + ?.let { Result(organizationUsageWebSearches = it, _json = json) } + ?: Result(_json = json) + } "organization.costs.result" -> { return tryDeserialize(node, jacksonTypeRef()) ?.let { Result(organizationCosts = it, _json = json) } @@ -1297,6 +1419,10 @@ private constructor( generator.writeObject(value.organizationUsageVectorStores) value.organizationUsageCodeInterpreterSessions != null -> generator.writeObject(value.organizationUsageCodeInterpreterSessions) + value.organizationUsageFileSearches != null -> + generator.writeObject(value.organizationUsageFileSearches) + value.organizationUsageWebSearches != null -> + generator.writeObject(value.organizationUsageWebSearches) value.organizationCosts != null -> generator.writeObject(value.organizationCosts) value._json != null -> generator.writeObject(value._json) @@ -5162,6 +5288,981 @@ private constructor( "OrganizationUsageCodeInterpreterSessionsResult{numSessions=$numSessions, object_=$object_, projectId=$projectId, additionalProperties=$additionalProperties}" } + /** The aggregated file search calls usage details of the specific time bucket. */ + class OrganizationUsageFileSearchesResult + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val numRequests: JsonField, + private val object_: JsonValue, + private val apiKeyId: JsonField, + private val projectId: JsonField, + private val userId: JsonField, + private val vectorStoreId: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("num_requests") + @ExcludeMissing + numRequests: JsonField = JsonMissing.of(), + @JsonProperty("object") @ExcludeMissing object_: JsonValue = JsonMissing.of(), + @JsonProperty("api_key_id") + @ExcludeMissing + apiKeyId: JsonField = JsonMissing.of(), + @JsonProperty("project_id") + @ExcludeMissing + projectId: JsonField = JsonMissing.of(), + @JsonProperty("user_id") + @ExcludeMissing + userId: JsonField = JsonMissing.of(), + @JsonProperty("vector_store_id") + @ExcludeMissing + vectorStoreId: JsonField = JsonMissing.of(), + ) : this( + numRequests, + object_, + apiKeyId, + projectId, + userId, + vectorStoreId, + mutableMapOf(), + ) + + /** + * The count of file search calls. + * + * @throws OpenAIInvalidDataException 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 numRequests(): Long = numRequests.getRequired("num_requests") + + /** + * Expected to always return the following: + * ```java + * JsonValue.from("organization.usage.file_searches.result") + * ``` + * + * However, this method can be useful for debugging and logging (e.g. if the server + * responded with an unexpected value). + */ + @JsonProperty("object") @ExcludeMissing fun _object_(): JsonValue = object_ + + /** + * When `group_by=api_key_id`, this field provides the API key ID of the grouped + * usage result. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun apiKeyId(): Optional = apiKeyId.getOptional("api_key_id") + + /** + * When `group_by=project_id`, this field provides the project ID of the grouped + * usage result. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun projectId(): Optional = projectId.getOptional("project_id") + + /** + * When `group_by=user_id`, this field provides the user ID of the grouped usage + * result. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun userId(): Optional = userId.getOptional("user_id") + + /** + * When `group_by=vector_store_id`, this field provides the vector store ID of the + * grouped usage result. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun vectorStoreId(): Optional = vectorStoreId.getOptional("vector_store_id") + + /** + * Returns the raw JSON value of [numRequests]. + * + * Unlike [numRequests], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("num_requests") + @ExcludeMissing + fun _numRequests(): JsonField = numRequests + + /** + * Returns the raw JSON value of [apiKeyId]. + * + * Unlike [apiKeyId], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("api_key_id") + @ExcludeMissing + fun _apiKeyId(): JsonField = apiKeyId + + /** + * 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 [userId]. + * + * Unlike [userId], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("user_id") @ExcludeMissing fun _userId(): JsonField = userId + + /** + * Returns the raw JSON value of [vectorStoreId]. + * + * Unlike [vectorStoreId], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("vector_store_id") + @ExcludeMissing + fun _vectorStoreId(): JsonField = vectorStoreId + + @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 + * [OrganizationUsageFileSearchesResult]. + * + * The following fields are required: + * ```java + * .numRequests() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [OrganizationUsageFileSearchesResult]. */ + class Builder internal constructor() { + + private var numRequests: JsonField? = null + private var object_: JsonValue = + JsonValue.from("organization.usage.file_searches.result") + private var apiKeyId: JsonField = JsonMissing.of() + private var projectId: JsonField = JsonMissing.of() + private var userId: JsonField = JsonMissing.of() + private var vectorStoreId: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from( + organizationUsageFileSearchesResult: OrganizationUsageFileSearchesResult + ) = apply { + numRequests = organizationUsageFileSearchesResult.numRequests + object_ = organizationUsageFileSearchesResult.object_ + apiKeyId = organizationUsageFileSearchesResult.apiKeyId + projectId = organizationUsageFileSearchesResult.projectId + userId = organizationUsageFileSearchesResult.userId + vectorStoreId = organizationUsageFileSearchesResult.vectorStoreId + additionalProperties = + organizationUsageFileSearchesResult.additionalProperties.toMutableMap() + } + + /** The count of file search calls. */ + fun numRequests(numRequests: Long) = numRequests(JsonField.of(numRequests)) + + /** + * Sets [Builder.numRequests] to an arbitrary JSON value. + * + * You should usually call [Builder.numRequests] with a well-typed [Long] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun numRequests(numRequests: JsonField) = apply { + this.numRequests = numRequests + } + + /** + * Sets the field to an arbitrary JSON value. + * + * It is usually unnecessary to call this method because the field defaults to + * the following: + * ```java + * JsonValue.from("organization.usage.file_searches.result") + * ``` + * + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun object_(object_: JsonValue) = apply { this.object_ = object_ } + + /** + * When `group_by=api_key_id`, this field provides the API key ID of the grouped + * usage result. + */ + fun apiKeyId(apiKeyId: String?) = apiKeyId(JsonField.ofNullable(apiKeyId)) + + /** Alias for calling [Builder.apiKeyId] with `apiKeyId.orElse(null)`. */ + fun apiKeyId(apiKeyId: Optional) = apiKeyId(apiKeyId.getOrNull()) + + /** + * Sets [Builder.apiKeyId] to an arbitrary JSON value. + * + * You should usually call [Builder.apiKeyId] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun apiKeyId(apiKeyId: JsonField) = apply { this.apiKeyId = apiKeyId } + + /** + * When `group_by=project_id`, this field provides the project ID of the grouped + * usage result. + */ + fun projectId(projectId: String?) = projectId(JsonField.ofNullable(projectId)) + + /** Alias for calling [Builder.projectId] with `projectId.orElse(null)`. */ + fun projectId(projectId: Optional) = projectId(projectId.getOrNull()) + + /** + * 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 + } + + /** + * When `group_by=user_id`, this field provides the user ID of the grouped usage + * result. + */ + 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 } + + /** + * When `group_by=vector_store_id`, this field provides the vector store ID of + * the grouped usage result. + */ + fun vectorStoreId(vectorStoreId: String?) = + vectorStoreId(JsonField.ofNullable(vectorStoreId)) + + /** + * Alias for calling [Builder.vectorStoreId] with `vectorStoreId.orElse(null)`. + */ + fun vectorStoreId(vectorStoreId: Optional) = + vectorStoreId(vectorStoreId.getOrNull()) + + /** + * Sets [Builder.vectorStoreId] to an arbitrary JSON value. + * + * You should usually call [Builder.vectorStoreId] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun vectorStoreId(vectorStoreId: JsonField) = apply { + this.vectorStoreId = vectorStoreId + } + + 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 [OrganizationUsageFileSearchesResult]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .numRequests() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): OrganizationUsageFileSearchesResult = + OrganizationUsageFileSearchesResult( + checkRequired("numRequests", numRequests), + object_, + apiKeyId, + projectId, + userId, + vectorStoreId, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing + * fields. + * + * @throws OpenAIInvalidDataException if any value type in this object doesn't match + * its expected type. + */ + fun validate(): OrganizationUsageFileSearchesResult = apply { + if (validated) { + return@apply + } + + numRequests() + _object_().let { + if (it != JsonValue.from("organization.usage.file_searches.result")) { + throw OpenAIInvalidDataException("'object_' is invalid, received $it") + } + } + apiKeyId() + projectId() + userId() + vectorStoreId() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OpenAIInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (if (numRequests.asKnown().isPresent) 1 else 0) + + object_.let { + if (it == JsonValue.from("organization.usage.file_searches.result")) 1 + else 0 + } + + (if (apiKeyId.asKnown().isPresent) 1 else 0) + + (if (projectId.asKnown().isPresent) 1 else 0) + + (if (userId.asKnown().isPresent) 1 else 0) + + (if (vectorStoreId.asKnown().isPresent) 1 else 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is OrganizationUsageFileSearchesResult && + numRequests == other.numRequests && + object_ == other.object_ && + apiKeyId == other.apiKeyId && + projectId == other.projectId && + userId == other.userId && + vectorStoreId == other.vectorStoreId && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + numRequests, + object_, + apiKeyId, + projectId, + userId, + vectorStoreId, + additionalProperties, + ) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "OrganizationUsageFileSearchesResult{numRequests=$numRequests, object_=$object_, apiKeyId=$apiKeyId, projectId=$projectId, userId=$userId, vectorStoreId=$vectorStoreId, additionalProperties=$additionalProperties}" + } + + /** The aggregated web search calls usage details of the specific time bucket. */ + class OrganizationUsageWebSearchesResult + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val numModelRequests: JsonField, + private val numRequests: JsonField, + private val object_: JsonValue, + private val apiKeyId: JsonField, + private val contextLevel: JsonField, + private val model: JsonField, + private val projectId: JsonField, + private val userId: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("num_model_requests") + @ExcludeMissing + numModelRequests: JsonField = JsonMissing.of(), + @JsonProperty("num_requests") + @ExcludeMissing + numRequests: JsonField = JsonMissing.of(), + @JsonProperty("object") @ExcludeMissing object_: JsonValue = JsonMissing.of(), + @JsonProperty("api_key_id") + @ExcludeMissing + apiKeyId: JsonField = JsonMissing.of(), + @JsonProperty("context_level") + @ExcludeMissing + contextLevel: JsonField = JsonMissing.of(), + @JsonProperty("model") + @ExcludeMissing + model: JsonField = JsonMissing.of(), + @JsonProperty("project_id") + @ExcludeMissing + projectId: JsonField = JsonMissing.of(), + @JsonProperty("user_id") + @ExcludeMissing + userId: JsonField = JsonMissing.of(), + ) : this( + numModelRequests, + numRequests, + object_, + apiKeyId, + contextLevel, + model, + projectId, + userId, + mutableMapOf(), + ) + + /** + * The count of model requests. + * + * @throws OpenAIInvalidDataException 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 numModelRequests(): Long = numModelRequests.getRequired("num_model_requests") + + /** + * The count of web search calls. + * + * @throws OpenAIInvalidDataException 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 numRequests(): Long = numRequests.getRequired("num_requests") + + /** + * Expected to always return the following: + * ```java + * JsonValue.from("organization.usage.web_searches.result") + * ``` + * + * However, this method can be useful for debugging and logging (e.g. if the server + * responded with an unexpected value). + */ + @JsonProperty("object") @ExcludeMissing fun _object_(): JsonValue = object_ + + /** + * When `group_by=api_key_id`, this field provides the API key ID of the grouped + * usage result. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun apiKeyId(): Optional = apiKeyId.getOptional("api_key_id") + + /** + * When `group_by=context_level`, this field provides the search context size of the + * grouped usage result. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun contextLevel(): Optional = contextLevel.getOptional("context_level") + + /** + * When `group_by=model`, this field provides the model name of the grouped usage + * result. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun model(): Optional = model.getOptional("model") + + /** + * When `group_by=project_id`, this field provides the project ID of the grouped + * usage result. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun projectId(): Optional = projectId.getOptional("project_id") + + /** + * When `group_by=user_id`, this field provides the user ID of the grouped usage + * result. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun userId(): Optional = userId.getOptional("user_id") + + /** + * Returns the raw JSON value of [numModelRequests]. + * + * Unlike [numModelRequests], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("num_model_requests") + @ExcludeMissing + fun _numModelRequests(): JsonField = numModelRequests + + /** + * Returns the raw JSON value of [numRequests]. + * + * Unlike [numRequests], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("num_requests") + @ExcludeMissing + fun _numRequests(): JsonField = numRequests + + /** + * Returns the raw JSON value of [apiKeyId]. + * + * Unlike [apiKeyId], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("api_key_id") + @ExcludeMissing + fun _apiKeyId(): JsonField = apiKeyId + + /** + * Returns the raw JSON value of [contextLevel]. + * + * Unlike [contextLevel], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("context_level") + @ExcludeMissing + fun _contextLevel(): JsonField = contextLevel + + /** + * Returns the raw JSON value of [model]. + * + * Unlike [model], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("model") @ExcludeMissing fun _model(): JsonField = model + + /** + * 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 [userId]. + * + * Unlike [userId], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @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 = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of + * [OrganizationUsageWebSearchesResult]. + * + * The following fields are required: + * ```java + * .numModelRequests() + * .numRequests() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [OrganizationUsageWebSearchesResult]. */ + class Builder internal constructor() { + + private var numModelRequests: JsonField? = null + private var numRequests: JsonField? = null + private var object_: JsonValue = + JsonValue.from("organization.usage.web_searches.result") + private var apiKeyId: JsonField = JsonMissing.of() + private var contextLevel: JsonField = JsonMissing.of() + private var model: JsonField = JsonMissing.of() + private var projectId: JsonField = JsonMissing.of() + private var userId: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from( + organizationUsageWebSearchesResult: OrganizationUsageWebSearchesResult + ) = apply { + numModelRequests = organizationUsageWebSearchesResult.numModelRequests + numRequests = organizationUsageWebSearchesResult.numRequests + object_ = organizationUsageWebSearchesResult.object_ + apiKeyId = organizationUsageWebSearchesResult.apiKeyId + contextLevel = organizationUsageWebSearchesResult.contextLevel + model = organizationUsageWebSearchesResult.model + projectId = organizationUsageWebSearchesResult.projectId + userId = organizationUsageWebSearchesResult.userId + additionalProperties = + organizationUsageWebSearchesResult.additionalProperties.toMutableMap() + } + + /** The count of model requests. */ + fun numModelRequests(numModelRequests: Long) = + numModelRequests(JsonField.of(numModelRequests)) + + /** + * Sets [Builder.numModelRequests] to an arbitrary JSON value. + * + * You should usually call [Builder.numModelRequests] with a well-typed [Long] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun numModelRequests(numModelRequests: JsonField) = apply { + this.numModelRequests = numModelRequests + } + + /** The count of web search calls. */ + fun numRequests(numRequests: Long) = numRequests(JsonField.of(numRequests)) + + /** + * Sets [Builder.numRequests] to an arbitrary JSON value. + * + * You should usually call [Builder.numRequests] with a well-typed [Long] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun numRequests(numRequests: JsonField) = apply { + this.numRequests = numRequests + } + + /** + * Sets the field to an arbitrary JSON value. + * + * It is usually unnecessary to call this method because the field defaults to + * the following: + * ```java + * JsonValue.from("organization.usage.web_searches.result") + * ``` + * + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun object_(object_: JsonValue) = apply { this.object_ = object_ } + + /** + * When `group_by=api_key_id`, this field provides the API key ID of the grouped + * usage result. + */ + fun apiKeyId(apiKeyId: String?) = apiKeyId(JsonField.ofNullable(apiKeyId)) + + /** Alias for calling [Builder.apiKeyId] with `apiKeyId.orElse(null)`. */ + fun apiKeyId(apiKeyId: Optional) = apiKeyId(apiKeyId.getOrNull()) + + /** + * Sets [Builder.apiKeyId] to an arbitrary JSON value. + * + * You should usually call [Builder.apiKeyId] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun apiKeyId(apiKeyId: JsonField) = apply { this.apiKeyId = apiKeyId } + + /** + * When `group_by=context_level`, this field provides the search context size of + * the grouped usage result. + */ + fun contextLevel(contextLevel: String?) = + contextLevel(JsonField.ofNullable(contextLevel)) + + /** + * Alias for calling [Builder.contextLevel] with `contextLevel.orElse(null)`. + */ + fun contextLevel(contextLevel: Optional) = + contextLevel(contextLevel.getOrNull()) + + /** + * Sets [Builder.contextLevel] to an arbitrary JSON value. + * + * You should usually call [Builder.contextLevel] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun contextLevel(contextLevel: JsonField) = apply { + this.contextLevel = contextLevel + } + + /** + * When `group_by=model`, this field provides the model name of the grouped + * usage result. + */ + fun model(model: String?) = model(JsonField.ofNullable(model)) + + /** Alias for calling [Builder.model] with `model.orElse(null)`. */ + fun model(model: Optional) = model(model.getOrNull()) + + /** + * Sets [Builder.model] to an arbitrary JSON value. + * + * You should usually call [Builder.model] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun model(model: JsonField) = apply { this.model = model } + + /** + * When `group_by=project_id`, this field provides the project ID of the grouped + * usage result. + */ + fun projectId(projectId: String?) = projectId(JsonField.ofNullable(projectId)) + + /** Alias for calling [Builder.projectId] with `projectId.orElse(null)`. */ + fun projectId(projectId: Optional) = projectId(projectId.getOrNull()) + + /** + * 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 + } + + /** + * When `group_by=user_id`, this field provides the user ID of the grouped usage + * result. + */ + 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 } + + 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 [OrganizationUsageWebSearchesResult]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .numModelRequests() + * .numRequests() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): OrganizationUsageWebSearchesResult = + OrganizationUsageWebSearchesResult( + checkRequired("numModelRequests", numModelRequests), + checkRequired("numRequests", numRequests), + object_, + apiKeyId, + contextLevel, + model, + projectId, + userId, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing + * fields. + * + * @throws OpenAIInvalidDataException if any value type in this object doesn't match + * its expected type. + */ + fun validate(): OrganizationUsageWebSearchesResult = apply { + if (validated) { + return@apply + } + + numModelRequests() + numRequests() + _object_().let { + if (it != JsonValue.from("organization.usage.web_searches.result")) { + throw OpenAIInvalidDataException("'object_' is invalid, received $it") + } + } + apiKeyId() + contextLevel() + model() + projectId() + userId() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OpenAIInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (if (numModelRequests.asKnown().isPresent) 1 else 0) + + (if (numRequests.asKnown().isPresent) 1 else 0) + + object_.let { + if (it == JsonValue.from("organization.usage.web_searches.result")) 1 + else 0 + } + + (if (apiKeyId.asKnown().isPresent) 1 else 0) + + (if (contextLevel.asKnown().isPresent) 1 else 0) + + (if (model.asKnown().isPresent) 1 else 0) + + (if (projectId.asKnown().isPresent) 1 else 0) + + (if (userId.asKnown().isPresent) 1 else 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is OrganizationUsageWebSearchesResult && + numModelRequests == other.numModelRequests && + numRequests == other.numRequests && + object_ == other.object_ && + apiKeyId == other.apiKeyId && + contextLevel == other.contextLevel && + model == other.model && + projectId == other.projectId && + userId == other.userId && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + numModelRequests, + numRequests, + object_, + apiKeyId, + contextLevel, + model, + projectId, + userId, + additionalProperties, + ) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "OrganizationUsageWebSearchesResult{numModelRequests=$numModelRequests, numRequests=$numRequests, object_=$object_, apiKeyId=$apiKeyId, contextLevel=$contextLevel, model=$model, projectId=$projectId, userId=$userId, additionalProperties=$additionalProperties}" + } + /** The aggregated costs details of the specific time bucket. */ class OrganizationCostsResult @JsonCreator(mode = JsonCreator.Mode.DISABLED) diff --git a/openai-java-core/src/main/kotlin/com/openai/models/admin/organization/usage/UsageImagesResponse.kt b/openai-java-core/src/main/kotlin/com/openai/models/admin/organization/usage/UsageImagesResponse.kt index f9b1a23de..5d531f2f2 100644 --- a/openai-java-core/src/main/kotlin/com/openai/models/admin/organization/usage/UsageImagesResponse.kt +++ b/openai-java-core/src/main/kotlin/com/openai/models/admin/organization/usage/UsageImagesResponse.kt @@ -561,6 +561,36 @@ private constructor( .build() ) + /** + * Alias for calling [addResult] with + * `Result.ofOrganizationUsageFileSearches(organizationUsageFileSearches)`. + */ + fun addResult( + organizationUsageFileSearches: Result.OrganizationUsageFileSearchesResult + ) = addResult(Result.ofOrganizationUsageFileSearches(organizationUsageFileSearches)) + + /** + * Alias for calling [addResult] with the following: + * ```java + * Result.OrganizationUsageFileSearchesResult.builder() + * .numRequests(numRequests) + * .build() + * ``` + */ + fun addOrganizationUsageFileSearchesResult(numRequests: Long) = + addResult( + Result.OrganizationUsageFileSearchesResult.builder() + .numRequests(numRequests) + .build() + ) + + /** + * Alias for calling [addResult] with + * `Result.ofOrganizationUsageWebSearches(organizationUsageWebSearches)`. + */ + fun addResult(organizationUsageWebSearches: Result.OrganizationUsageWebSearchesResult) = + addResult(Result.ofOrganizationUsageWebSearches(organizationUsageWebSearches)) + /** * Alias for calling [addResult] with `Result.ofOrganizationCosts(organizationCosts)`. */ @@ -687,6 +717,8 @@ private constructor( private val organizationUsageCodeInterpreterSessions: OrganizationUsageCodeInterpreterSessionsResult? = null, + private val organizationUsageFileSearches: OrganizationUsageFileSearchesResult? = null, + private val organizationUsageWebSearches: OrganizationUsageWebSearchesResult? = null, private val organizationCosts: OrganizationCostsResult? = null, private val _json: JsonValue? = null, ) { @@ -727,6 +759,14 @@ private constructor( Optional = Optional.ofNullable(organizationUsageCodeInterpreterSessions) + /** The aggregated file search calls usage details of the specific time bucket. */ + fun organizationUsageFileSearches(): Optional = + Optional.ofNullable(organizationUsageFileSearches) + + /** The aggregated web search calls usage details of the specific time bucket. */ + fun organizationUsageWebSearches(): Optional = + Optional.ofNullable(organizationUsageWebSearches) + /** The aggregated costs details of the specific time bucket. */ fun organizationCosts(): Optional = Optional.ofNullable(organizationCosts) @@ -749,6 +789,10 @@ private constructor( fun isOrganizationUsageCodeInterpreterSessions(): Boolean = organizationUsageCodeInterpreterSessions != null + fun isOrganizationUsageFileSearches(): Boolean = organizationUsageFileSearches != null + + fun isOrganizationUsageWebSearches(): Boolean = organizationUsageWebSearches != null + fun isOrganizationCosts(): Boolean = organizationCosts != null /** The aggregated completions usage details of the specific time bucket. */ @@ -791,6 +835,14 @@ private constructor( "organizationUsageCodeInterpreterSessions" ) + /** The aggregated file search calls usage details of the specific time bucket. */ + fun asOrganizationUsageFileSearches(): OrganizationUsageFileSearchesResult = + organizationUsageFileSearches.getOrThrow("organizationUsageFileSearches") + + /** The aggregated web search calls usage details of the specific time bucket. */ + fun asOrganizationUsageWebSearches(): OrganizationUsageWebSearchesResult = + organizationUsageWebSearches.getOrThrow("organizationUsageWebSearches") + /** The aggregated costs details of the specific time bucket. */ fun asOrganizationCosts(): OrganizationCostsResult = organizationCosts.getOrThrow("organizationCosts") @@ -849,6 +901,10 @@ private constructor( visitor.visitOrganizationUsageCodeInterpreterSessions( organizationUsageCodeInterpreterSessions ) + organizationUsageFileSearches != null -> + visitor.visitOrganizationUsageFileSearches(organizationUsageFileSearches) + organizationUsageWebSearches != null -> + visitor.visitOrganizationUsageWebSearches(organizationUsageWebSearches) organizationCosts != null -> visitor.visitOrganizationCosts(organizationCosts) else -> visitor.unknown(_json) } @@ -922,6 +978,18 @@ private constructor( organizationUsageCodeInterpreterSessions.validate() } + override fun visitOrganizationUsageFileSearches( + organizationUsageFileSearches: OrganizationUsageFileSearchesResult + ) { + organizationUsageFileSearches.validate() + } + + override fun visitOrganizationUsageWebSearches( + organizationUsageWebSearches: OrganizationUsageWebSearchesResult + ) { + organizationUsageWebSearches.validate() + } + override fun visitOrganizationCosts( organizationCosts: OrganizationCostsResult ) { @@ -984,6 +1052,14 @@ private constructor( OrganizationUsageCodeInterpreterSessionsResult ) = organizationUsageCodeInterpreterSessions.validity() + override fun visitOrganizationUsageFileSearches( + organizationUsageFileSearches: OrganizationUsageFileSearchesResult + ) = organizationUsageFileSearches.validity() + + override fun visitOrganizationUsageWebSearches( + organizationUsageWebSearches: OrganizationUsageWebSearchesResult + ) = organizationUsageWebSearches.validity() + override fun visitOrganizationCosts( organizationCosts: OrganizationCostsResult ) = organizationCosts.validity() @@ -1008,6 +1084,8 @@ private constructor( organizationUsageVectorStores == other.organizationUsageVectorStores && organizationUsageCodeInterpreterSessions == other.organizationUsageCodeInterpreterSessions && + organizationUsageFileSearches == other.organizationUsageFileSearches && + organizationUsageWebSearches == other.organizationUsageWebSearches && organizationCosts == other.organizationCosts } @@ -1021,6 +1099,8 @@ private constructor( organizationUsageAudioTranscriptions, organizationUsageVectorStores, organizationUsageCodeInterpreterSessions, + organizationUsageFileSearches, + organizationUsageWebSearches, organizationCosts, ) @@ -1042,6 +1122,10 @@ private constructor( "Result{organizationUsageVectorStores=$organizationUsageVectorStores}" organizationUsageCodeInterpreterSessions != null -> "Result{organizationUsageCodeInterpreterSessions=$organizationUsageCodeInterpreterSessions}" + organizationUsageFileSearches != null -> + "Result{organizationUsageFileSearches=$organizationUsageFileSearches}" + organizationUsageWebSearches != null -> + "Result{organizationUsageWebSearches=$organizationUsageWebSearches}" organizationCosts != null -> "Result{organizationCosts=$organizationCosts}" _json != null -> "Result{_unknown=$_json}" else -> throw IllegalStateException("Invalid Result") @@ -1110,6 +1194,18 @@ private constructor( organizationUsageCodeInterpreterSessions ) + /** The aggregated file search calls usage details of the specific time bucket. */ + @JvmStatic + fun ofOrganizationUsageFileSearches( + organizationUsageFileSearches: OrganizationUsageFileSearchesResult + ) = Result(organizationUsageFileSearches = organizationUsageFileSearches) + + /** The aggregated web search calls usage details of the specific time bucket. */ + @JvmStatic + fun ofOrganizationUsageWebSearches( + organizationUsageWebSearches: OrganizationUsageWebSearchesResult + ) = Result(organizationUsageWebSearches = organizationUsageWebSearches) + /** The aggregated costs details of the specific time bucket. */ @JvmStatic fun ofOrganizationCosts(organizationCosts: OrganizationCostsResult) = @@ -1167,6 +1263,16 @@ private constructor( OrganizationUsageCodeInterpreterSessionsResult ): T + /** The aggregated file search calls usage details of the specific time bucket. */ + fun visitOrganizationUsageFileSearches( + organizationUsageFileSearches: OrganizationUsageFileSearchesResult + ): T + + /** The aggregated web search calls usage details of the specific time bucket. */ + fun visitOrganizationUsageWebSearches( + organizationUsageWebSearches: OrganizationUsageWebSearchesResult + ): T + /** The aggregated costs details of the specific time bucket. */ fun visitOrganizationCosts(organizationCosts: OrganizationCostsResult): T @@ -1262,6 +1368,22 @@ private constructor( ) } ?: Result(_json = json) } + "organization.usage.file_searches.result" -> { + return tryDeserialize( + node, + jacksonTypeRef(), + ) + ?.let { Result(organizationUsageFileSearches = it, _json = json) } + ?: Result(_json = json) + } + "organization.usage.web_searches.result" -> { + return tryDeserialize( + node, + jacksonTypeRef(), + ) + ?.let { Result(organizationUsageWebSearches = it, _json = json) } + ?: Result(_json = json) + } "organization.costs.result" -> { return tryDeserialize(node, jacksonTypeRef()) ?.let { Result(organizationCosts = it, _json = json) } @@ -1297,6 +1419,10 @@ private constructor( generator.writeObject(value.organizationUsageVectorStores) value.organizationUsageCodeInterpreterSessions != null -> generator.writeObject(value.organizationUsageCodeInterpreterSessions) + value.organizationUsageFileSearches != null -> + generator.writeObject(value.organizationUsageFileSearches) + value.organizationUsageWebSearches != null -> + generator.writeObject(value.organizationUsageWebSearches) value.organizationCosts != null -> generator.writeObject(value.organizationCosts) value._json != null -> generator.writeObject(value._json) @@ -5162,6 +5288,981 @@ private constructor( "OrganizationUsageCodeInterpreterSessionsResult{numSessions=$numSessions, object_=$object_, projectId=$projectId, additionalProperties=$additionalProperties}" } + /** The aggregated file search calls usage details of the specific time bucket. */ + class OrganizationUsageFileSearchesResult + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val numRequests: JsonField, + private val object_: JsonValue, + private val apiKeyId: JsonField, + private val projectId: JsonField, + private val userId: JsonField, + private val vectorStoreId: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("num_requests") + @ExcludeMissing + numRequests: JsonField = JsonMissing.of(), + @JsonProperty("object") @ExcludeMissing object_: JsonValue = JsonMissing.of(), + @JsonProperty("api_key_id") + @ExcludeMissing + apiKeyId: JsonField = JsonMissing.of(), + @JsonProperty("project_id") + @ExcludeMissing + projectId: JsonField = JsonMissing.of(), + @JsonProperty("user_id") + @ExcludeMissing + userId: JsonField = JsonMissing.of(), + @JsonProperty("vector_store_id") + @ExcludeMissing + vectorStoreId: JsonField = JsonMissing.of(), + ) : this( + numRequests, + object_, + apiKeyId, + projectId, + userId, + vectorStoreId, + mutableMapOf(), + ) + + /** + * The count of file search calls. + * + * @throws OpenAIInvalidDataException 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 numRequests(): Long = numRequests.getRequired("num_requests") + + /** + * Expected to always return the following: + * ```java + * JsonValue.from("organization.usage.file_searches.result") + * ``` + * + * However, this method can be useful for debugging and logging (e.g. if the server + * responded with an unexpected value). + */ + @JsonProperty("object") @ExcludeMissing fun _object_(): JsonValue = object_ + + /** + * When `group_by=api_key_id`, this field provides the API key ID of the grouped + * usage result. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun apiKeyId(): Optional = apiKeyId.getOptional("api_key_id") + + /** + * When `group_by=project_id`, this field provides the project ID of the grouped + * usage result. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun projectId(): Optional = projectId.getOptional("project_id") + + /** + * When `group_by=user_id`, this field provides the user ID of the grouped usage + * result. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun userId(): Optional = userId.getOptional("user_id") + + /** + * When `group_by=vector_store_id`, this field provides the vector store ID of the + * grouped usage result. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun vectorStoreId(): Optional = vectorStoreId.getOptional("vector_store_id") + + /** + * Returns the raw JSON value of [numRequests]. + * + * Unlike [numRequests], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("num_requests") + @ExcludeMissing + fun _numRequests(): JsonField = numRequests + + /** + * Returns the raw JSON value of [apiKeyId]. + * + * Unlike [apiKeyId], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("api_key_id") + @ExcludeMissing + fun _apiKeyId(): JsonField = apiKeyId + + /** + * 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 [userId]. + * + * Unlike [userId], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("user_id") @ExcludeMissing fun _userId(): JsonField = userId + + /** + * Returns the raw JSON value of [vectorStoreId]. + * + * Unlike [vectorStoreId], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("vector_store_id") + @ExcludeMissing + fun _vectorStoreId(): JsonField = vectorStoreId + + @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 + * [OrganizationUsageFileSearchesResult]. + * + * The following fields are required: + * ```java + * .numRequests() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [OrganizationUsageFileSearchesResult]. */ + class Builder internal constructor() { + + private var numRequests: JsonField? = null + private var object_: JsonValue = + JsonValue.from("organization.usage.file_searches.result") + private var apiKeyId: JsonField = JsonMissing.of() + private var projectId: JsonField = JsonMissing.of() + private var userId: JsonField = JsonMissing.of() + private var vectorStoreId: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from( + organizationUsageFileSearchesResult: OrganizationUsageFileSearchesResult + ) = apply { + numRequests = organizationUsageFileSearchesResult.numRequests + object_ = organizationUsageFileSearchesResult.object_ + apiKeyId = organizationUsageFileSearchesResult.apiKeyId + projectId = organizationUsageFileSearchesResult.projectId + userId = organizationUsageFileSearchesResult.userId + vectorStoreId = organizationUsageFileSearchesResult.vectorStoreId + additionalProperties = + organizationUsageFileSearchesResult.additionalProperties.toMutableMap() + } + + /** The count of file search calls. */ + fun numRequests(numRequests: Long) = numRequests(JsonField.of(numRequests)) + + /** + * Sets [Builder.numRequests] to an arbitrary JSON value. + * + * You should usually call [Builder.numRequests] with a well-typed [Long] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun numRequests(numRequests: JsonField) = apply { + this.numRequests = numRequests + } + + /** + * Sets the field to an arbitrary JSON value. + * + * It is usually unnecessary to call this method because the field defaults to + * the following: + * ```java + * JsonValue.from("organization.usage.file_searches.result") + * ``` + * + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun object_(object_: JsonValue) = apply { this.object_ = object_ } + + /** + * When `group_by=api_key_id`, this field provides the API key ID of the grouped + * usage result. + */ + fun apiKeyId(apiKeyId: String?) = apiKeyId(JsonField.ofNullable(apiKeyId)) + + /** Alias for calling [Builder.apiKeyId] with `apiKeyId.orElse(null)`. */ + fun apiKeyId(apiKeyId: Optional) = apiKeyId(apiKeyId.getOrNull()) + + /** + * Sets [Builder.apiKeyId] to an arbitrary JSON value. + * + * You should usually call [Builder.apiKeyId] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun apiKeyId(apiKeyId: JsonField) = apply { this.apiKeyId = apiKeyId } + + /** + * When `group_by=project_id`, this field provides the project ID of the grouped + * usage result. + */ + fun projectId(projectId: String?) = projectId(JsonField.ofNullable(projectId)) + + /** Alias for calling [Builder.projectId] with `projectId.orElse(null)`. */ + fun projectId(projectId: Optional) = projectId(projectId.getOrNull()) + + /** + * 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 + } + + /** + * When `group_by=user_id`, this field provides the user ID of the grouped usage + * result. + */ + 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 } + + /** + * When `group_by=vector_store_id`, this field provides the vector store ID of + * the grouped usage result. + */ + fun vectorStoreId(vectorStoreId: String?) = + vectorStoreId(JsonField.ofNullable(vectorStoreId)) + + /** + * Alias for calling [Builder.vectorStoreId] with `vectorStoreId.orElse(null)`. + */ + fun vectorStoreId(vectorStoreId: Optional) = + vectorStoreId(vectorStoreId.getOrNull()) + + /** + * Sets [Builder.vectorStoreId] to an arbitrary JSON value. + * + * You should usually call [Builder.vectorStoreId] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun vectorStoreId(vectorStoreId: JsonField) = apply { + this.vectorStoreId = vectorStoreId + } + + 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 [OrganizationUsageFileSearchesResult]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .numRequests() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): OrganizationUsageFileSearchesResult = + OrganizationUsageFileSearchesResult( + checkRequired("numRequests", numRequests), + object_, + apiKeyId, + projectId, + userId, + vectorStoreId, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing + * fields. + * + * @throws OpenAIInvalidDataException if any value type in this object doesn't match + * its expected type. + */ + fun validate(): OrganizationUsageFileSearchesResult = apply { + if (validated) { + return@apply + } + + numRequests() + _object_().let { + if (it != JsonValue.from("organization.usage.file_searches.result")) { + throw OpenAIInvalidDataException("'object_' is invalid, received $it") + } + } + apiKeyId() + projectId() + userId() + vectorStoreId() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OpenAIInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (if (numRequests.asKnown().isPresent) 1 else 0) + + object_.let { + if (it == JsonValue.from("organization.usage.file_searches.result")) 1 + else 0 + } + + (if (apiKeyId.asKnown().isPresent) 1 else 0) + + (if (projectId.asKnown().isPresent) 1 else 0) + + (if (userId.asKnown().isPresent) 1 else 0) + + (if (vectorStoreId.asKnown().isPresent) 1 else 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is OrganizationUsageFileSearchesResult && + numRequests == other.numRequests && + object_ == other.object_ && + apiKeyId == other.apiKeyId && + projectId == other.projectId && + userId == other.userId && + vectorStoreId == other.vectorStoreId && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + numRequests, + object_, + apiKeyId, + projectId, + userId, + vectorStoreId, + additionalProperties, + ) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "OrganizationUsageFileSearchesResult{numRequests=$numRequests, object_=$object_, apiKeyId=$apiKeyId, projectId=$projectId, userId=$userId, vectorStoreId=$vectorStoreId, additionalProperties=$additionalProperties}" + } + + /** The aggregated web search calls usage details of the specific time bucket. */ + class OrganizationUsageWebSearchesResult + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val numModelRequests: JsonField, + private val numRequests: JsonField, + private val object_: JsonValue, + private val apiKeyId: JsonField, + private val contextLevel: JsonField, + private val model: JsonField, + private val projectId: JsonField, + private val userId: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("num_model_requests") + @ExcludeMissing + numModelRequests: JsonField = JsonMissing.of(), + @JsonProperty("num_requests") + @ExcludeMissing + numRequests: JsonField = JsonMissing.of(), + @JsonProperty("object") @ExcludeMissing object_: JsonValue = JsonMissing.of(), + @JsonProperty("api_key_id") + @ExcludeMissing + apiKeyId: JsonField = JsonMissing.of(), + @JsonProperty("context_level") + @ExcludeMissing + contextLevel: JsonField = JsonMissing.of(), + @JsonProperty("model") + @ExcludeMissing + model: JsonField = JsonMissing.of(), + @JsonProperty("project_id") + @ExcludeMissing + projectId: JsonField = JsonMissing.of(), + @JsonProperty("user_id") + @ExcludeMissing + userId: JsonField = JsonMissing.of(), + ) : this( + numModelRequests, + numRequests, + object_, + apiKeyId, + contextLevel, + model, + projectId, + userId, + mutableMapOf(), + ) + + /** + * The count of model requests. + * + * @throws OpenAIInvalidDataException 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 numModelRequests(): Long = numModelRequests.getRequired("num_model_requests") + + /** + * The count of web search calls. + * + * @throws OpenAIInvalidDataException 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 numRequests(): Long = numRequests.getRequired("num_requests") + + /** + * Expected to always return the following: + * ```java + * JsonValue.from("organization.usage.web_searches.result") + * ``` + * + * However, this method can be useful for debugging and logging (e.g. if the server + * responded with an unexpected value). + */ + @JsonProperty("object") @ExcludeMissing fun _object_(): JsonValue = object_ + + /** + * When `group_by=api_key_id`, this field provides the API key ID of the grouped + * usage result. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun apiKeyId(): Optional = apiKeyId.getOptional("api_key_id") + + /** + * When `group_by=context_level`, this field provides the search context size of the + * grouped usage result. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun contextLevel(): Optional = contextLevel.getOptional("context_level") + + /** + * When `group_by=model`, this field provides the model name of the grouped usage + * result. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun model(): Optional = model.getOptional("model") + + /** + * When `group_by=project_id`, this field provides the project ID of the grouped + * usage result. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun projectId(): Optional = projectId.getOptional("project_id") + + /** + * When `group_by=user_id`, this field provides the user ID of the grouped usage + * result. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun userId(): Optional = userId.getOptional("user_id") + + /** + * Returns the raw JSON value of [numModelRequests]. + * + * Unlike [numModelRequests], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("num_model_requests") + @ExcludeMissing + fun _numModelRequests(): JsonField = numModelRequests + + /** + * Returns the raw JSON value of [numRequests]. + * + * Unlike [numRequests], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("num_requests") + @ExcludeMissing + fun _numRequests(): JsonField = numRequests + + /** + * Returns the raw JSON value of [apiKeyId]. + * + * Unlike [apiKeyId], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("api_key_id") + @ExcludeMissing + fun _apiKeyId(): JsonField = apiKeyId + + /** + * Returns the raw JSON value of [contextLevel]. + * + * Unlike [contextLevel], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("context_level") + @ExcludeMissing + fun _contextLevel(): JsonField = contextLevel + + /** + * Returns the raw JSON value of [model]. + * + * Unlike [model], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("model") @ExcludeMissing fun _model(): JsonField = model + + /** + * 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 [userId]. + * + * Unlike [userId], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @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 = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of + * [OrganizationUsageWebSearchesResult]. + * + * The following fields are required: + * ```java + * .numModelRequests() + * .numRequests() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [OrganizationUsageWebSearchesResult]. */ + class Builder internal constructor() { + + private var numModelRequests: JsonField? = null + private var numRequests: JsonField? = null + private var object_: JsonValue = + JsonValue.from("organization.usage.web_searches.result") + private var apiKeyId: JsonField = JsonMissing.of() + private var contextLevel: JsonField = JsonMissing.of() + private var model: JsonField = JsonMissing.of() + private var projectId: JsonField = JsonMissing.of() + private var userId: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from( + organizationUsageWebSearchesResult: OrganizationUsageWebSearchesResult + ) = apply { + numModelRequests = organizationUsageWebSearchesResult.numModelRequests + numRequests = organizationUsageWebSearchesResult.numRequests + object_ = organizationUsageWebSearchesResult.object_ + apiKeyId = organizationUsageWebSearchesResult.apiKeyId + contextLevel = organizationUsageWebSearchesResult.contextLevel + model = organizationUsageWebSearchesResult.model + projectId = organizationUsageWebSearchesResult.projectId + userId = organizationUsageWebSearchesResult.userId + additionalProperties = + organizationUsageWebSearchesResult.additionalProperties.toMutableMap() + } + + /** The count of model requests. */ + fun numModelRequests(numModelRequests: Long) = + numModelRequests(JsonField.of(numModelRequests)) + + /** + * Sets [Builder.numModelRequests] to an arbitrary JSON value. + * + * You should usually call [Builder.numModelRequests] with a well-typed [Long] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun numModelRequests(numModelRequests: JsonField) = apply { + this.numModelRequests = numModelRequests + } + + /** The count of web search calls. */ + fun numRequests(numRequests: Long) = numRequests(JsonField.of(numRequests)) + + /** + * Sets [Builder.numRequests] to an arbitrary JSON value. + * + * You should usually call [Builder.numRequests] with a well-typed [Long] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun numRequests(numRequests: JsonField) = apply { + this.numRequests = numRequests + } + + /** + * Sets the field to an arbitrary JSON value. + * + * It is usually unnecessary to call this method because the field defaults to + * the following: + * ```java + * JsonValue.from("organization.usage.web_searches.result") + * ``` + * + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun object_(object_: JsonValue) = apply { this.object_ = object_ } + + /** + * When `group_by=api_key_id`, this field provides the API key ID of the grouped + * usage result. + */ + fun apiKeyId(apiKeyId: String?) = apiKeyId(JsonField.ofNullable(apiKeyId)) + + /** Alias for calling [Builder.apiKeyId] with `apiKeyId.orElse(null)`. */ + fun apiKeyId(apiKeyId: Optional) = apiKeyId(apiKeyId.getOrNull()) + + /** + * Sets [Builder.apiKeyId] to an arbitrary JSON value. + * + * You should usually call [Builder.apiKeyId] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun apiKeyId(apiKeyId: JsonField) = apply { this.apiKeyId = apiKeyId } + + /** + * When `group_by=context_level`, this field provides the search context size of + * the grouped usage result. + */ + fun contextLevel(contextLevel: String?) = + contextLevel(JsonField.ofNullable(contextLevel)) + + /** + * Alias for calling [Builder.contextLevel] with `contextLevel.orElse(null)`. + */ + fun contextLevel(contextLevel: Optional) = + contextLevel(contextLevel.getOrNull()) + + /** + * Sets [Builder.contextLevel] to an arbitrary JSON value. + * + * You should usually call [Builder.contextLevel] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun contextLevel(contextLevel: JsonField) = apply { + this.contextLevel = contextLevel + } + + /** + * When `group_by=model`, this field provides the model name of the grouped + * usage result. + */ + fun model(model: String?) = model(JsonField.ofNullable(model)) + + /** Alias for calling [Builder.model] with `model.orElse(null)`. */ + fun model(model: Optional) = model(model.getOrNull()) + + /** + * Sets [Builder.model] to an arbitrary JSON value. + * + * You should usually call [Builder.model] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun model(model: JsonField) = apply { this.model = model } + + /** + * When `group_by=project_id`, this field provides the project ID of the grouped + * usage result. + */ + fun projectId(projectId: String?) = projectId(JsonField.ofNullable(projectId)) + + /** Alias for calling [Builder.projectId] with `projectId.orElse(null)`. */ + fun projectId(projectId: Optional) = projectId(projectId.getOrNull()) + + /** + * 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 + } + + /** + * When `group_by=user_id`, this field provides the user ID of the grouped usage + * result. + */ + 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 } + + 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 [OrganizationUsageWebSearchesResult]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .numModelRequests() + * .numRequests() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): OrganizationUsageWebSearchesResult = + OrganizationUsageWebSearchesResult( + checkRequired("numModelRequests", numModelRequests), + checkRequired("numRequests", numRequests), + object_, + apiKeyId, + contextLevel, + model, + projectId, + userId, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing + * fields. + * + * @throws OpenAIInvalidDataException if any value type in this object doesn't match + * its expected type. + */ + fun validate(): OrganizationUsageWebSearchesResult = apply { + if (validated) { + return@apply + } + + numModelRequests() + numRequests() + _object_().let { + if (it != JsonValue.from("organization.usage.web_searches.result")) { + throw OpenAIInvalidDataException("'object_' is invalid, received $it") + } + } + apiKeyId() + contextLevel() + model() + projectId() + userId() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OpenAIInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (if (numModelRequests.asKnown().isPresent) 1 else 0) + + (if (numRequests.asKnown().isPresent) 1 else 0) + + object_.let { + if (it == JsonValue.from("organization.usage.web_searches.result")) 1 + else 0 + } + + (if (apiKeyId.asKnown().isPresent) 1 else 0) + + (if (contextLevel.asKnown().isPresent) 1 else 0) + + (if (model.asKnown().isPresent) 1 else 0) + + (if (projectId.asKnown().isPresent) 1 else 0) + + (if (userId.asKnown().isPresent) 1 else 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is OrganizationUsageWebSearchesResult && + numModelRequests == other.numModelRequests && + numRequests == other.numRequests && + object_ == other.object_ && + apiKeyId == other.apiKeyId && + contextLevel == other.contextLevel && + model == other.model && + projectId == other.projectId && + userId == other.userId && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + numModelRequests, + numRequests, + object_, + apiKeyId, + contextLevel, + model, + projectId, + userId, + additionalProperties, + ) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "OrganizationUsageWebSearchesResult{numModelRequests=$numModelRequests, numRequests=$numRequests, object_=$object_, apiKeyId=$apiKeyId, contextLevel=$contextLevel, model=$model, projectId=$projectId, userId=$userId, additionalProperties=$additionalProperties}" + } + /** The aggregated costs details of the specific time bucket. */ class OrganizationCostsResult @JsonCreator(mode = JsonCreator.Mode.DISABLED) diff --git a/openai-java-core/src/main/kotlin/com/openai/models/admin/organization/usage/UsageModerationsResponse.kt b/openai-java-core/src/main/kotlin/com/openai/models/admin/organization/usage/UsageModerationsResponse.kt index 08efff6e6..5854221b3 100644 --- a/openai-java-core/src/main/kotlin/com/openai/models/admin/organization/usage/UsageModerationsResponse.kt +++ b/openai-java-core/src/main/kotlin/com/openai/models/admin/organization/usage/UsageModerationsResponse.kt @@ -561,6 +561,36 @@ private constructor( .build() ) + /** + * Alias for calling [addResult] with + * `Result.ofOrganizationUsageFileSearches(organizationUsageFileSearches)`. + */ + fun addResult( + organizationUsageFileSearches: Result.OrganizationUsageFileSearchesResult + ) = addResult(Result.ofOrganizationUsageFileSearches(organizationUsageFileSearches)) + + /** + * Alias for calling [addResult] with the following: + * ```java + * Result.OrganizationUsageFileSearchesResult.builder() + * .numRequests(numRequests) + * .build() + * ``` + */ + fun addOrganizationUsageFileSearchesResult(numRequests: Long) = + addResult( + Result.OrganizationUsageFileSearchesResult.builder() + .numRequests(numRequests) + .build() + ) + + /** + * Alias for calling [addResult] with + * `Result.ofOrganizationUsageWebSearches(organizationUsageWebSearches)`. + */ + fun addResult(organizationUsageWebSearches: Result.OrganizationUsageWebSearchesResult) = + addResult(Result.ofOrganizationUsageWebSearches(organizationUsageWebSearches)) + /** * Alias for calling [addResult] with `Result.ofOrganizationCosts(organizationCosts)`. */ @@ -687,6 +717,8 @@ private constructor( private val organizationUsageCodeInterpreterSessions: OrganizationUsageCodeInterpreterSessionsResult? = null, + private val organizationUsageFileSearches: OrganizationUsageFileSearchesResult? = null, + private val organizationUsageWebSearches: OrganizationUsageWebSearchesResult? = null, private val organizationCosts: OrganizationCostsResult? = null, private val _json: JsonValue? = null, ) { @@ -727,6 +759,14 @@ private constructor( Optional = Optional.ofNullable(organizationUsageCodeInterpreterSessions) + /** The aggregated file search calls usage details of the specific time bucket. */ + fun organizationUsageFileSearches(): Optional = + Optional.ofNullable(organizationUsageFileSearches) + + /** The aggregated web search calls usage details of the specific time bucket. */ + fun organizationUsageWebSearches(): Optional = + Optional.ofNullable(organizationUsageWebSearches) + /** The aggregated costs details of the specific time bucket. */ fun organizationCosts(): Optional = Optional.ofNullable(organizationCosts) @@ -749,6 +789,10 @@ private constructor( fun isOrganizationUsageCodeInterpreterSessions(): Boolean = organizationUsageCodeInterpreterSessions != null + fun isOrganizationUsageFileSearches(): Boolean = organizationUsageFileSearches != null + + fun isOrganizationUsageWebSearches(): Boolean = organizationUsageWebSearches != null + fun isOrganizationCosts(): Boolean = organizationCosts != null /** The aggregated completions usage details of the specific time bucket. */ @@ -791,6 +835,14 @@ private constructor( "organizationUsageCodeInterpreterSessions" ) + /** The aggregated file search calls usage details of the specific time bucket. */ + fun asOrganizationUsageFileSearches(): OrganizationUsageFileSearchesResult = + organizationUsageFileSearches.getOrThrow("organizationUsageFileSearches") + + /** The aggregated web search calls usage details of the specific time bucket. */ + fun asOrganizationUsageWebSearches(): OrganizationUsageWebSearchesResult = + organizationUsageWebSearches.getOrThrow("organizationUsageWebSearches") + /** The aggregated costs details of the specific time bucket. */ fun asOrganizationCosts(): OrganizationCostsResult = organizationCosts.getOrThrow("organizationCosts") @@ -849,6 +901,10 @@ private constructor( visitor.visitOrganizationUsageCodeInterpreterSessions( organizationUsageCodeInterpreterSessions ) + organizationUsageFileSearches != null -> + visitor.visitOrganizationUsageFileSearches(organizationUsageFileSearches) + organizationUsageWebSearches != null -> + visitor.visitOrganizationUsageWebSearches(organizationUsageWebSearches) organizationCosts != null -> visitor.visitOrganizationCosts(organizationCosts) else -> visitor.unknown(_json) } @@ -922,6 +978,18 @@ private constructor( organizationUsageCodeInterpreterSessions.validate() } + override fun visitOrganizationUsageFileSearches( + organizationUsageFileSearches: OrganizationUsageFileSearchesResult + ) { + organizationUsageFileSearches.validate() + } + + override fun visitOrganizationUsageWebSearches( + organizationUsageWebSearches: OrganizationUsageWebSearchesResult + ) { + organizationUsageWebSearches.validate() + } + override fun visitOrganizationCosts( organizationCosts: OrganizationCostsResult ) { @@ -984,6 +1052,14 @@ private constructor( OrganizationUsageCodeInterpreterSessionsResult ) = organizationUsageCodeInterpreterSessions.validity() + override fun visitOrganizationUsageFileSearches( + organizationUsageFileSearches: OrganizationUsageFileSearchesResult + ) = organizationUsageFileSearches.validity() + + override fun visitOrganizationUsageWebSearches( + organizationUsageWebSearches: OrganizationUsageWebSearchesResult + ) = organizationUsageWebSearches.validity() + override fun visitOrganizationCosts( organizationCosts: OrganizationCostsResult ) = organizationCosts.validity() @@ -1008,6 +1084,8 @@ private constructor( organizationUsageVectorStores == other.organizationUsageVectorStores && organizationUsageCodeInterpreterSessions == other.organizationUsageCodeInterpreterSessions && + organizationUsageFileSearches == other.organizationUsageFileSearches && + organizationUsageWebSearches == other.organizationUsageWebSearches && organizationCosts == other.organizationCosts } @@ -1021,6 +1099,8 @@ private constructor( organizationUsageAudioTranscriptions, organizationUsageVectorStores, organizationUsageCodeInterpreterSessions, + organizationUsageFileSearches, + organizationUsageWebSearches, organizationCosts, ) @@ -1042,6 +1122,10 @@ private constructor( "Result{organizationUsageVectorStores=$organizationUsageVectorStores}" organizationUsageCodeInterpreterSessions != null -> "Result{organizationUsageCodeInterpreterSessions=$organizationUsageCodeInterpreterSessions}" + organizationUsageFileSearches != null -> + "Result{organizationUsageFileSearches=$organizationUsageFileSearches}" + organizationUsageWebSearches != null -> + "Result{organizationUsageWebSearches=$organizationUsageWebSearches}" organizationCosts != null -> "Result{organizationCosts=$organizationCosts}" _json != null -> "Result{_unknown=$_json}" else -> throw IllegalStateException("Invalid Result") @@ -1110,6 +1194,18 @@ private constructor( organizationUsageCodeInterpreterSessions ) + /** The aggregated file search calls usage details of the specific time bucket. */ + @JvmStatic + fun ofOrganizationUsageFileSearches( + organizationUsageFileSearches: OrganizationUsageFileSearchesResult + ) = Result(organizationUsageFileSearches = organizationUsageFileSearches) + + /** The aggregated web search calls usage details of the specific time bucket. */ + @JvmStatic + fun ofOrganizationUsageWebSearches( + organizationUsageWebSearches: OrganizationUsageWebSearchesResult + ) = Result(organizationUsageWebSearches = organizationUsageWebSearches) + /** The aggregated costs details of the specific time bucket. */ @JvmStatic fun ofOrganizationCosts(organizationCosts: OrganizationCostsResult) = @@ -1167,6 +1263,16 @@ private constructor( OrganizationUsageCodeInterpreterSessionsResult ): T + /** The aggregated file search calls usage details of the specific time bucket. */ + fun visitOrganizationUsageFileSearches( + organizationUsageFileSearches: OrganizationUsageFileSearchesResult + ): T + + /** The aggregated web search calls usage details of the specific time bucket. */ + fun visitOrganizationUsageWebSearches( + organizationUsageWebSearches: OrganizationUsageWebSearchesResult + ): T + /** The aggregated costs details of the specific time bucket. */ fun visitOrganizationCosts(organizationCosts: OrganizationCostsResult): T @@ -1262,6 +1368,22 @@ private constructor( ) } ?: Result(_json = json) } + "organization.usage.file_searches.result" -> { + return tryDeserialize( + node, + jacksonTypeRef(), + ) + ?.let { Result(organizationUsageFileSearches = it, _json = json) } + ?: Result(_json = json) + } + "organization.usage.web_searches.result" -> { + return tryDeserialize( + node, + jacksonTypeRef(), + ) + ?.let { Result(organizationUsageWebSearches = it, _json = json) } + ?: Result(_json = json) + } "organization.costs.result" -> { return tryDeserialize(node, jacksonTypeRef()) ?.let { Result(organizationCosts = it, _json = json) } @@ -1297,6 +1419,10 @@ private constructor( generator.writeObject(value.organizationUsageVectorStores) value.organizationUsageCodeInterpreterSessions != null -> generator.writeObject(value.organizationUsageCodeInterpreterSessions) + value.organizationUsageFileSearches != null -> + generator.writeObject(value.organizationUsageFileSearches) + value.organizationUsageWebSearches != null -> + generator.writeObject(value.organizationUsageWebSearches) value.organizationCosts != null -> generator.writeObject(value.organizationCosts) value._json != null -> generator.writeObject(value._json) @@ -5162,6 +5288,981 @@ private constructor( "OrganizationUsageCodeInterpreterSessionsResult{numSessions=$numSessions, object_=$object_, projectId=$projectId, additionalProperties=$additionalProperties}" } + /** The aggregated file search calls usage details of the specific time bucket. */ + class OrganizationUsageFileSearchesResult + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val numRequests: JsonField, + private val object_: JsonValue, + private val apiKeyId: JsonField, + private val projectId: JsonField, + private val userId: JsonField, + private val vectorStoreId: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("num_requests") + @ExcludeMissing + numRequests: JsonField = JsonMissing.of(), + @JsonProperty("object") @ExcludeMissing object_: JsonValue = JsonMissing.of(), + @JsonProperty("api_key_id") + @ExcludeMissing + apiKeyId: JsonField = JsonMissing.of(), + @JsonProperty("project_id") + @ExcludeMissing + projectId: JsonField = JsonMissing.of(), + @JsonProperty("user_id") + @ExcludeMissing + userId: JsonField = JsonMissing.of(), + @JsonProperty("vector_store_id") + @ExcludeMissing + vectorStoreId: JsonField = JsonMissing.of(), + ) : this( + numRequests, + object_, + apiKeyId, + projectId, + userId, + vectorStoreId, + mutableMapOf(), + ) + + /** + * The count of file search calls. + * + * @throws OpenAIInvalidDataException 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 numRequests(): Long = numRequests.getRequired("num_requests") + + /** + * Expected to always return the following: + * ```java + * JsonValue.from("organization.usage.file_searches.result") + * ``` + * + * However, this method can be useful for debugging and logging (e.g. if the server + * responded with an unexpected value). + */ + @JsonProperty("object") @ExcludeMissing fun _object_(): JsonValue = object_ + + /** + * When `group_by=api_key_id`, this field provides the API key ID of the grouped + * usage result. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun apiKeyId(): Optional = apiKeyId.getOptional("api_key_id") + + /** + * When `group_by=project_id`, this field provides the project ID of the grouped + * usage result. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun projectId(): Optional = projectId.getOptional("project_id") + + /** + * When `group_by=user_id`, this field provides the user ID of the grouped usage + * result. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun userId(): Optional = userId.getOptional("user_id") + + /** + * When `group_by=vector_store_id`, this field provides the vector store ID of the + * grouped usage result. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun vectorStoreId(): Optional = vectorStoreId.getOptional("vector_store_id") + + /** + * Returns the raw JSON value of [numRequests]. + * + * Unlike [numRequests], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("num_requests") + @ExcludeMissing + fun _numRequests(): JsonField = numRequests + + /** + * Returns the raw JSON value of [apiKeyId]. + * + * Unlike [apiKeyId], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("api_key_id") + @ExcludeMissing + fun _apiKeyId(): JsonField = apiKeyId + + /** + * 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 [userId]. + * + * Unlike [userId], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("user_id") @ExcludeMissing fun _userId(): JsonField = userId + + /** + * Returns the raw JSON value of [vectorStoreId]. + * + * Unlike [vectorStoreId], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("vector_store_id") + @ExcludeMissing + fun _vectorStoreId(): JsonField = vectorStoreId + + @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 + * [OrganizationUsageFileSearchesResult]. + * + * The following fields are required: + * ```java + * .numRequests() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [OrganizationUsageFileSearchesResult]. */ + class Builder internal constructor() { + + private var numRequests: JsonField? = null + private var object_: JsonValue = + JsonValue.from("organization.usage.file_searches.result") + private var apiKeyId: JsonField = JsonMissing.of() + private var projectId: JsonField = JsonMissing.of() + private var userId: JsonField = JsonMissing.of() + private var vectorStoreId: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from( + organizationUsageFileSearchesResult: OrganizationUsageFileSearchesResult + ) = apply { + numRequests = organizationUsageFileSearchesResult.numRequests + object_ = organizationUsageFileSearchesResult.object_ + apiKeyId = organizationUsageFileSearchesResult.apiKeyId + projectId = organizationUsageFileSearchesResult.projectId + userId = organizationUsageFileSearchesResult.userId + vectorStoreId = organizationUsageFileSearchesResult.vectorStoreId + additionalProperties = + organizationUsageFileSearchesResult.additionalProperties.toMutableMap() + } + + /** The count of file search calls. */ + fun numRequests(numRequests: Long) = numRequests(JsonField.of(numRequests)) + + /** + * Sets [Builder.numRequests] to an arbitrary JSON value. + * + * You should usually call [Builder.numRequests] with a well-typed [Long] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun numRequests(numRequests: JsonField) = apply { + this.numRequests = numRequests + } + + /** + * Sets the field to an arbitrary JSON value. + * + * It is usually unnecessary to call this method because the field defaults to + * the following: + * ```java + * JsonValue.from("organization.usage.file_searches.result") + * ``` + * + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun object_(object_: JsonValue) = apply { this.object_ = object_ } + + /** + * When `group_by=api_key_id`, this field provides the API key ID of the grouped + * usage result. + */ + fun apiKeyId(apiKeyId: String?) = apiKeyId(JsonField.ofNullable(apiKeyId)) + + /** Alias for calling [Builder.apiKeyId] with `apiKeyId.orElse(null)`. */ + fun apiKeyId(apiKeyId: Optional) = apiKeyId(apiKeyId.getOrNull()) + + /** + * Sets [Builder.apiKeyId] to an arbitrary JSON value. + * + * You should usually call [Builder.apiKeyId] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun apiKeyId(apiKeyId: JsonField) = apply { this.apiKeyId = apiKeyId } + + /** + * When `group_by=project_id`, this field provides the project ID of the grouped + * usage result. + */ + fun projectId(projectId: String?) = projectId(JsonField.ofNullable(projectId)) + + /** Alias for calling [Builder.projectId] with `projectId.orElse(null)`. */ + fun projectId(projectId: Optional) = projectId(projectId.getOrNull()) + + /** + * 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 + } + + /** + * When `group_by=user_id`, this field provides the user ID of the grouped usage + * result. + */ + 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 } + + /** + * When `group_by=vector_store_id`, this field provides the vector store ID of + * the grouped usage result. + */ + fun vectorStoreId(vectorStoreId: String?) = + vectorStoreId(JsonField.ofNullable(vectorStoreId)) + + /** + * Alias for calling [Builder.vectorStoreId] with `vectorStoreId.orElse(null)`. + */ + fun vectorStoreId(vectorStoreId: Optional) = + vectorStoreId(vectorStoreId.getOrNull()) + + /** + * Sets [Builder.vectorStoreId] to an arbitrary JSON value. + * + * You should usually call [Builder.vectorStoreId] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun vectorStoreId(vectorStoreId: JsonField) = apply { + this.vectorStoreId = vectorStoreId + } + + 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 [OrganizationUsageFileSearchesResult]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .numRequests() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): OrganizationUsageFileSearchesResult = + OrganizationUsageFileSearchesResult( + checkRequired("numRequests", numRequests), + object_, + apiKeyId, + projectId, + userId, + vectorStoreId, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing + * fields. + * + * @throws OpenAIInvalidDataException if any value type in this object doesn't match + * its expected type. + */ + fun validate(): OrganizationUsageFileSearchesResult = apply { + if (validated) { + return@apply + } + + numRequests() + _object_().let { + if (it != JsonValue.from("organization.usage.file_searches.result")) { + throw OpenAIInvalidDataException("'object_' is invalid, received $it") + } + } + apiKeyId() + projectId() + userId() + vectorStoreId() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OpenAIInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (if (numRequests.asKnown().isPresent) 1 else 0) + + object_.let { + if (it == JsonValue.from("organization.usage.file_searches.result")) 1 + else 0 + } + + (if (apiKeyId.asKnown().isPresent) 1 else 0) + + (if (projectId.asKnown().isPresent) 1 else 0) + + (if (userId.asKnown().isPresent) 1 else 0) + + (if (vectorStoreId.asKnown().isPresent) 1 else 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is OrganizationUsageFileSearchesResult && + numRequests == other.numRequests && + object_ == other.object_ && + apiKeyId == other.apiKeyId && + projectId == other.projectId && + userId == other.userId && + vectorStoreId == other.vectorStoreId && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + numRequests, + object_, + apiKeyId, + projectId, + userId, + vectorStoreId, + additionalProperties, + ) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "OrganizationUsageFileSearchesResult{numRequests=$numRequests, object_=$object_, apiKeyId=$apiKeyId, projectId=$projectId, userId=$userId, vectorStoreId=$vectorStoreId, additionalProperties=$additionalProperties}" + } + + /** The aggregated web search calls usage details of the specific time bucket. */ + class OrganizationUsageWebSearchesResult + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val numModelRequests: JsonField, + private val numRequests: JsonField, + private val object_: JsonValue, + private val apiKeyId: JsonField, + private val contextLevel: JsonField, + private val model: JsonField, + private val projectId: JsonField, + private val userId: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("num_model_requests") + @ExcludeMissing + numModelRequests: JsonField = JsonMissing.of(), + @JsonProperty("num_requests") + @ExcludeMissing + numRequests: JsonField = JsonMissing.of(), + @JsonProperty("object") @ExcludeMissing object_: JsonValue = JsonMissing.of(), + @JsonProperty("api_key_id") + @ExcludeMissing + apiKeyId: JsonField = JsonMissing.of(), + @JsonProperty("context_level") + @ExcludeMissing + contextLevel: JsonField = JsonMissing.of(), + @JsonProperty("model") + @ExcludeMissing + model: JsonField = JsonMissing.of(), + @JsonProperty("project_id") + @ExcludeMissing + projectId: JsonField = JsonMissing.of(), + @JsonProperty("user_id") + @ExcludeMissing + userId: JsonField = JsonMissing.of(), + ) : this( + numModelRequests, + numRequests, + object_, + apiKeyId, + contextLevel, + model, + projectId, + userId, + mutableMapOf(), + ) + + /** + * The count of model requests. + * + * @throws OpenAIInvalidDataException 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 numModelRequests(): Long = numModelRequests.getRequired("num_model_requests") + + /** + * The count of web search calls. + * + * @throws OpenAIInvalidDataException 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 numRequests(): Long = numRequests.getRequired("num_requests") + + /** + * Expected to always return the following: + * ```java + * JsonValue.from("organization.usage.web_searches.result") + * ``` + * + * However, this method can be useful for debugging and logging (e.g. if the server + * responded with an unexpected value). + */ + @JsonProperty("object") @ExcludeMissing fun _object_(): JsonValue = object_ + + /** + * When `group_by=api_key_id`, this field provides the API key ID of the grouped + * usage result. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun apiKeyId(): Optional = apiKeyId.getOptional("api_key_id") + + /** + * When `group_by=context_level`, this field provides the search context size of the + * grouped usage result. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun contextLevel(): Optional = contextLevel.getOptional("context_level") + + /** + * When `group_by=model`, this field provides the model name of the grouped usage + * result. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun model(): Optional = model.getOptional("model") + + /** + * When `group_by=project_id`, this field provides the project ID of the grouped + * usage result. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun projectId(): Optional = projectId.getOptional("project_id") + + /** + * When `group_by=user_id`, this field provides the user ID of the grouped usage + * result. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun userId(): Optional = userId.getOptional("user_id") + + /** + * Returns the raw JSON value of [numModelRequests]. + * + * Unlike [numModelRequests], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("num_model_requests") + @ExcludeMissing + fun _numModelRequests(): JsonField = numModelRequests + + /** + * Returns the raw JSON value of [numRequests]. + * + * Unlike [numRequests], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("num_requests") + @ExcludeMissing + fun _numRequests(): JsonField = numRequests + + /** + * Returns the raw JSON value of [apiKeyId]. + * + * Unlike [apiKeyId], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("api_key_id") + @ExcludeMissing + fun _apiKeyId(): JsonField = apiKeyId + + /** + * Returns the raw JSON value of [contextLevel]. + * + * Unlike [contextLevel], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("context_level") + @ExcludeMissing + fun _contextLevel(): JsonField = contextLevel + + /** + * Returns the raw JSON value of [model]. + * + * Unlike [model], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("model") @ExcludeMissing fun _model(): JsonField = model + + /** + * 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 [userId]. + * + * Unlike [userId], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @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 = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of + * [OrganizationUsageWebSearchesResult]. + * + * The following fields are required: + * ```java + * .numModelRequests() + * .numRequests() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [OrganizationUsageWebSearchesResult]. */ + class Builder internal constructor() { + + private var numModelRequests: JsonField? = null + private var numRequests: JsonField? = null + private var object_: JsonValue = + JsonValue.from("organization.usage.web_searches.result") + private var apiKeyId: JsonField = JsonMissing.of() + private var contextLevel: JsonField = JsonMissing.of() + private var model: JsonField = JsonMissing.of() + private var projectId: JsonField = JsonMissing.of() + private var userId: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from( + organizationUsageWebSearchesResult: OrganizationUsageWebSearchesResult + ) = apply { + numModelRequests = organizationUsageWebSearchesResult.numModelRequests + numRequests = organizationUsageWebSearchesResult.numRequests + object_ = organizationUsageWebSearchesResult.object_ + apiKeyId = organizationUsageWebSearchesResult.apiKeyId + contextLevel = organizationUsageWebSearchesResult.contextLevel + model = organizationUsageWebSearchesResult.model + projectId = organizationUsageWebSearchesResult.projectId + userId = organizationUsageWebSearchesResult.userId + additionalProperties = + organizationUsageWebSearchesResult.additionalProperties.toMutableMap() + } + + /** The count of model requests. */ + fun numModelRequests(numModelRequests: Long) = + numModelRequests(JsonField.of(numModelRequests)) + + /** + * Sets [Builder.numModelRequests] to an arbitrary JSON value. + * + * You should usually call [Builder.numModelRequests] with a well-typed [Long] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun numModelRequests(numModelRequests: JsonField) = apply { + this.numModelRequests = numModelRequests + } + + /** The count of web search calls. */ + fun numRequests(numRequests: Long) = numRequests(JsonField.of(numRequests)) + + /** + * Sets [Builder.numRequests] to an arbitrary JSON value. + * + * You should usually call [Builder.numRequests] with a well-typed [Long] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun numRequests(numRequests: JsonField) = apply { + this.numRequests = numRequests + } + + /** + * Sets the field to an arbitrary JSON value. + * + * It is usually unnecessary to call this method because the field defaults to + * the following: + * ```java + * JsonValue.from("organization.usage.web_searches.result") + * ``` + * + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun object_(object_: JsonValue) = apply { this.object_ = object_ } + + /** + * When `group_by=api_key_id`, this field provides the API key ID of the grouped + * usage result. + */ + fun apiKeyId(apiKeyId: String?) = apiKeyId(JsonField.ofNullable(apiKeyId)) + + /** Alias for calling [Builder.apiKeyId] with `apiKeyId.orElse(null)`. */ + fun apiKeyId(apiKeyId: Optional) = apiKeyId(apiKeyId.getOrNull()) + + /** + * Sets [Builder.apiKeyId] to an arbitrary JSON value. + * + * You should usually call [Builder.apiKeyId] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun apiKeyId(apiKeyId: JsonField) = apply { this.apiKeyId = apiKeyId } + + /** + * When `group_by=context_level`, this field provides the search context size of + * the grouped usage result. + */ + fun contextLevel(contextLevel: String?) = + contextLevel(JsonField.ofNullable(contextLevel)) + + /** + * Alias for calling [Builder.contextLevel] with `contextLevel.orElse(null)`. + */ + fun contextLevel(contextLevel: Optional) = + contextLevel(contextLevel.getOrNull()) + + /** + * Sets [Builder.contextLevel] to an arbitrary JSON value. + * + * You should usually call [Builder.contextLevel] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun contextLevel(contextLevel: JsonField) = apply { + this.contextLevel = contextLevel + } + + /** + * When `group_by=model`, this field provides the model name of the grouped + * usage result. + */ + fun model(model: String?) = model(JsonField.ofNullable(model)) + + /** Alias for calling [Builder.model] with `model.orElse(null)`. */ + fun model(model: Optional) = model(model.getOrNull()) + + /** + * Sets [Builder.model] to an arbitrary JSON value. + * + * You should usually call [Builder.model] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun model(model: JsonField) = apply { this.model = model } + + /** + * When `group_by=project_id`, this field provides the project ID of the grouped + * usage result. + */ + fun projectId(projectId: String?) = projectId(JsonField.ofNullable(projectId)) + + /** Alias for calling [Builder.projectId] with `projectId.orElse(null)`. */ + fun projectId(projectId: Optional) = projectId(projectId.getOrNull()) + + /** + * 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 + } + + /** + * When `group_by=user_id`, this field provides the user ID of the grouped usage + * result. + */ + 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 } + + 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 [OrganizationUsageWebSearchesResult]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .numModelRequests() + * .numRequests() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): OrganizationUsageWebSearchesResult = + OrganizationUsageWebSearchesResult( + checkRequired("numModelRequests", numModelRequests), + checkRequired("numRequests", numRequests), + object_, + apiKeyId, + contextLevel, + model, + projectId, + userId, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing + * fields. + * + * @throws OpenAIInvalidDataException if any value type in this object doesn't match + * its expected type. + */ + fun validate(): OrganizationUsageWebSearchesResult = apply { + if (validated) { + return@apply + } + + numModelRequests() + numRequests() + _object_().let { + if (it != JsonValue.from("organization.usage.web_searches.result")) { + throw OpenAIInvalidDataException("'object_' is invalid, received $it") + } + } + apiKeyId() + contextLevel() + model() + projectId() + userId() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OpenAIInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (if (numModelRequests.asKnown().isPresent) 1 else 0) + + (if (numRequests.asKnown().isPresent) 1 else 0) + + object_.let { + if (it == JsonValue.from("organization.usage.web_searches.result")) 1 + else 0 + } + + (if (apiKeyId.asKnown().isPresent) 1 else 0) + + (if (contextLevel.asKnown().isPresent) 1 else 0) + + (if (model.asKnown().isPresent) 1 else 0) + + (if (projectId.asKnown().isPresent) 1 else 0) + + (if (userId.asKnown().isPresent) 1 else 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is OrganizationUsageWebSearchesResult && + numModelRequests == other.numModelRequests && + numRequests == other.numRequests && + object_ == other.object_ && + apiKeyId == other.apiKeyId && + contextLevel == other.contextLevel && + model == other.model && + projectId == other.projectId && + userId == other.userId && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + numModelRequests, + numRequests, + object_, + apiKeyId, + contextLevel, + model, + projectId, + userId, + additionalProperties, + ) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "OrganizationUsageWebSearchesResult{numModelRequests=$numModelRequests, numRequests=$numRequests, object_=$object_, apiKeyId=$apiKeyId, contextLevel=$contextLevel, model=$model, projectId=$projectId, userId=$userId, additionalProperties=$additionalProperties}" + } + /** The aggregated costs details of the specific time bucket. */ class OrganizationCostsResult @JsonCreator(mode = JsonCreator.Mode.DISABLED) diff --git a/openai-java-core/src/main/kotlin/com/openai/models/admin/organization/usage/UsageVectorStoresResponse.kt b/openai-java-core/src/main/kotlin/com/openai/models/admin/organization/usage/UsageVectorStoresResponse.kt index 1adb3b3ff..4917b040a 100644 --- a/openai-java-core/src/main/kotlin/com/openai/models/admin/organization/usage/UsageVectorStoresResponse.kt +++ b/openai-java-core/src/main/kotlin/com/openai/models/admin/organization/usage/UsageVectorStoresResponse.kt @@ -561,6 +561,36 @@ private constructor( .build() ) + /** + * Alias for calling [addResult] with + * `Result.ofOrganizationUsageFileSearches(organizationUsageFileSearches)`. + */ + fun addResult( + organizationUsageFileSearches: Result.OrganizationUsageFileSearchesResult + ) = addResult(Result.ofOrganizationUsageFileSearches(organizationUsageFileSearches)) + + /** + * Alias for calling [addResult] with the following: + * ```java + * Result.OrganizationUsageFileSearchesResult.builder() + * .numRequests(numRequests) + * .build() + * ``` + */ + fun addOrganizationUsageFileSearchesResult(numRequests: Long) = + addResult( + Result.OrganizationUsageFileSearchesResult.builder() + .numRequests(numRequests) + .build() + ) + + /** + * Alias for calling [addResult] with + * `Result.ofOrganizationUsageWebSearches(organizationUsageWebSearches)`. + */ + fun addResult(organizationUsageWebSearches: Result.OrganizationUsageWebSearchesResult) = + addResult(Result.ofOrganizationUsageWebSearches(organizationUsageWebSearches)) + /** * Alias for calling [addResult] with `Result.ofOrganizationCosts(organizationCosts)`. */ @@ -687,6 +717,8 @@ private constructor( private val organizationUsageCodeInterpreterSessions: OrganizationUsageCodeInterpreterSessionsResult? = null, + private val organizationUsageFileSearches: OrganizationUsageFileSearchesResult? = null, + private val organizationUsageWebSearches: OrganizationUsageWebSearchesResult? = null, private val organizationCosts: OrganizationCostsResult? = null, private val _json: JsonValue? = null, ) { @@ -727,6 +759,14 @@ private constructor( Optional = Optional.ofNullable(organizationUsageCodeInterpreterSessions) + /** The aggregated file search calls usage details of the specific time bucket. */ + fun organizationUsageFileSearches(): Optional = + Optional.ofNullable(organizationUsageFileSearches) + + /** The aggregated web search calls usage details of the specific time bucket. */ + fun organizationUsageWebSearches(): Optional = + Optional.ofNullable(organizationUsageWebSearches) + /** The aggregated costs details of the specific time bucket. */ fun organizationCosts(): Optional = Optional.ofNullable(organizationCosts) @@ -749,6 +789,10 @@ private constructor( fun isOrganizationUsageCodeInterpreterSessions(): Boolean = organizationUsageCodeInterpreterSessions != null + fun isOrganizationUsageFileSearches(): Boolean = organizationUsageFileSearches != null + + fun isOrganizationUsageWebSearches(): Boolean = organizationUsageWebSearches != null + fun isOrganizationCosts(): Boolean = organizationCosts != null /** The aggregated completions usage details of the specific time bucket. */ @@ -791,6 +835,14 @@ private constructor( "organizationUsageCodeInterpreterSessions" ) + /** The aggregated file search calls usage details of the specific time bucket. */ + fun asOrganizationUsageFileSearches(): OrganizationUsageFileSearchesResult = + organizationUsageFileSearches.getOrThrow("organizationUsageFileSearches") + + /** The aggregated web search calls usage details of the specific time bucket. */ + fun asOrganizationUsageWebSearches(): OrganizationUsageWebSearchesResult = + organizationUsageWebSearches.getOrThrow("organizationUsageWebSearches") + /** The aggregated costs details of the specific time bucket. */ fun asOrganizationCosts(): OrganizationCostsResult = organizationCosts.getOrThrow("organizationCosts") @@ -849,6 +901,10 @@ private constructor( visitor.visitOrganizationUsageCodeInterpreterSessions( organizationUsageCodeInterpreterSessions ) + organizationUsageFileSearches != null -> + visitor.visitOrganizationUsageFileSearches(organizationUsageFileSearches) + organizationUsageWebSearches != null -> + visitor.visitOrganizationUsageWebSearches(organizationUsageWebSearches) organizationCosts != null -> visitor.visitOrganizationCosts(organizationCosts) else -> visitor.unknown(_json) } @@ -922,6 +978,18 @@ private constructor( organizationUsageCodeInterpreterSessions.validate() } + override fun visitOrganizationUsageFileSearches( + organizationUsageFileSearches: OrganizationUsageFileSearchesResult + ) { + organizationUsageFileSearches.validate() + } + + override fun visitOrganizationUsageWebSearches( + organizationUsageWebSearches: OrganizationUsageWebSearchesResult + ) { + organizationUsageWebSearches.validate() + } + override fun visitOrganizationCosts( organizationCosts: OrganizationCostsResult ) { @@ -984,6 +1052,14 @@ private constructor( OrganizationUsageCodeInterpreterSessionsResult ) = organizationUsageCodeInterpreterSessions.validity() + override fun visitOrganizationUsageFileSearches( + organizationUsageFileSearches: OrganizationUsageFileSearchesResult + ) = organizationUsageFileSearches.validity() + + override fun visitOrganizationUsageWebSearches( + organizationUsageWebSearches: OrganizationUsageWebSearchesResult + ) = organizationUsageWebSearches.validity() + override fun visitOrganizationCosts( organizationCosts: OrganizationCostsResult ) = organizationCosts.validity() @@ -1008,6 +1084,8 @@ private constructor( organizationUsageVectorStores == other.organizationUsageVectorStores && organizationUsageCodeInterpreterSessions == other.organizationUsageCodeInterpreterSessions && + organizationUsageFileSearches == other.organizationUsageFileSearches && + organizationUsageWebSearches == other.organizationUsageWebSearches && organizationCosts == other.organizationCosts } @@ -1021,6 +1099,8 @@ private constructor( organizationUsageAudioTranscriptions, organizationUsageVectorStores, organizationUsageCodeInterpreterSessions, + organizationUsageFileSearches, + organizationUsageWebSearches, organizationCosts, ) @@ -1042,6 +1122,10 @@ private constructor( "Result{organizationUsageVectorStores=$organizationUsageVectorStores}" organizationUsageCodeInterpreterSessions != null -> "Result{organizationUsageCodeInterpreterSessions=$organizationUsageCodeInterpreterSessions}" + organizationUsageFileSearches != null -> + "Result{organizationUsageFileSearches=$organizationUsageFileSearches}" + organizationUsageWebSearches != null -> + "Result{organizationUsageWebSearches=$organizationUsageWebSearches}" organizationCosts != null -> "Result{organizationCosts=$organizationCosts}" _json != null -> "Result{_unknown=$_json}" else -> throw IllegalStateException("Invalid Result") @@ -1110,6 +1194,18 @@ private constructor( organizationUsageCodeInterpreterSessions ) + /** The aggregated file search calls usage details of the specific time bucket. */ + @JvmStatic + fun ofOrganizationUsageFileSearches( + organizationUsageFileSearches: OrganizationUsageFileSearchesResult + ) = Result(organizationUsageFileSearches = organizationUsageFileSearches) + + /** The aggregated web search calls usage details of the specific time bucket. */ + @JvmStatic + fun ofOrganizationUsageWebSearches( + organizationUsageWebSearches: OrganizationUsageWebSearchesResult + ) = Result(organizationUsageWebSearches = organizationUsageWebSearches) + /** The aggregated costs details of the specific time bucket. */ @JvmStatic fun ofOrganizationCosts(organizationCosts: OrganizationCostsResult) = @@ -1167,6 +1263,16 @@ private constructor( OrganizationUsageCodeInterpreterSessionsResult ): T + /** The aggregated file search calls usage details of the specific time bucket. */ + fun visitOrganizationUsageFileSearches( + organizationUsageFileSearches: OrganizationUsageFileSearchesResult + ): T + + /** The aggregated web search calls usage details of the specific time bucket. */ + fun visitOrganizationUsageWebSearches( + organizationUsageWebSearches: OrganizationUsageWebSearchesResult + ): T + /** The aggregated costs details of the specific time bucket. */ fun visitOrganizationCosts(organizationCosts: OrganizationCostsResult): T @@ -1262,6 +1368,22 @@ private constructor( ) } ?: Result(_json = json) } + "organization.usage.file_searches.result" -> { + return tryDeserialize( + node, + jacksonTypeRef(), + ) + ?.let { Result(organizationUsageFileSearches = it, _json = json) } + ?: Result(_json = json) + } + "organization.usage.web_searches.result" -> { + return tryDeserialize( + node, + jacksonTypeRef(), + ) + ?.let { Result(organizationUsageWebSearches = it, _json = json) } + ?: Result(_json = json) + } "organization.costs.result" -> { return tryDeserialize(node, jacksonTypeRef()) ?.let { Result(organizationCosts = it, _json = json) } @@ -1297,6 +1419,10 @@ private constructor( generator.writeObject(value.organizationUsageVectorStores) value.organizationUsageCodeInterpreterSessions != null -> generator.writeObject(value.organizationUsageCodeInterpreterSessions) + value.organizationUsageFileSearches != null -> + generator.writeObject(value.organizationUsageFileSearches) + value.organizationUsageWebSearches != null -> + generator.writeObject(value.organizationUsageWebSearches) value.organizationCosts != null -> generator.writeObject(value.organizationCosts) value._json != null -> generator.writeObject(value._json) @@ -5162,6 +5288,981 @@ private constructor( "OrganizationUsageCodeInterpreterSessionsResult{numSessions=$numSessions, object_=$object_, projectId=$projectId, additionalProperties=$additionalProperties}" } + /** The aggregated file search calls usage details of the specific time bucket. */ + class OrganizationUsageFileSearchesResult + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val numRequests: JsonField, + private val object_: JsonValue, + private val apiKeyId: JsonField, + private val projectId: JsonField, + private val userId: JsonField, + private val vectorStoreId: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("num_requests") + @ExcludeMissing + numRequests: JsonField = JsonMissing.of(), + @JsonProperty("object") @ExcludeMissing object_: JsonValue = JsonMissing.of(), + @JsonProperty("api_key_id") + @ExcludeMissing + apiKeyId: JsonField = JsonMissing.of(), + @JsonProperty("project_id") + @ExcludeMissing + projectId: JsonField = JsonMissing.of(), + @JsonProperty("user_id") + @ExcludeMissing + userId: JsonField = JsonMissing.of(), + @JsonProperty("vector_store_id") + @ExcludeMissing + vectorStoreId: JsonField = JsonMissing.of(), + ) : this( + numRequests, + object_, + apiKeyId, + projectId, + userId, + vectorStoreId, + mutableMapOf(), + ) + + /** + * The count of file search calls. + * + * @throws OpenAIInvalidDataException 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 numRequests(): Long = numRequests.getRequired("num_requests") + + /** + * Expected to always return the following: + * ```java + * JsonValue.from("organization.usage.file_searches.result") + * ``` + * + * However, this method can be useful for debugging and logging (e.g. if the server + * responded with an unexpected value). + */ + @JsonProperty("object") @ExcludeMissing fun _object_(): JsonValue = object_ + + /** + * When `group_by=api_key_id`, this field provides the API key ID of the grouped + * usage result. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun apiKeyId(): Optional = apiKeyId.getOptional("api_key_id") + + /** + * When `group_by=project_id`, this field provides the project ID of the grouped + * usage result. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun projectId(): Optional = projectId.getOptional("project_id") + + /** + * When `group_by=user_id`, this field provides the user ID of the grouped usage + * result. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun userId(): Optional = userId.getOptional("user_id") + + /** + * When `group_by=vector_store_id`, this field provides the vector store ID of the + * grouped usage result. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun vectorStoreId(): Optional = vectorStoreId.getOptional("vector_store_id") + + /** + * Returns the raw JSON value of [numRequests]. + * + * Unlike [numRequests], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("num_requests") + @ExcludeMissing + fun _numRequests(): JsonField = numRequests + + /** + * Returns the raw JSON value of [apiKeyId]. + * + * Unlike [apiKeyId], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("api_key_id") + @ExcludeMissing + fun _apiKeyId(): JsonField = apiKeyId + + /** + * 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 [userId]. + * + * Unlike [userId], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("user_id") @ExcludeMissing fun _userId(): JsonField = userId + + /** + * Returns the raw JSON value of [vectorStoreId]. + * + * Unlike [vectorStoreId], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("vector_store_id") + @ExcludeMissing + fun _vectorStoreId(): JsonField = vectorStoreId + + @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 + * [OrganizationUsageFileSearchesResult]. + * + * The following fields are required: + * ```java + * .numRequests() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [OrganizationUsageFileSearchesResult]. */ + class Builder internal constructor() { + + private var numRequests: JsonField? = null + private var object_: JsonValue = + JsonValue.from("organization.usage.file_searches.result") + private var apiKeyId: JsonField = JsonMissing.of() + private var projectId: JsonField = JsonMissing.of() + private var userId: JsonField = JsonMissing.of() + private var vectorStoreId: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from( + organizationUsageFileSearchesResult: OrganizationUsageFileSearchesResult + ) = apply { + numRequests = organizationUsageFileSearchesResult.numRequests + object_ = organizationUsageFileSearchesResult.object_ + apiKeyId = organizationUsageFileSearchesResult.apiKeyId + projectId = organizationUsageFileSearchesResult.projectId + userId = organizationUsageFileSearchesResult.userId + vectorStoreId = organizationUsageFileSearchesResult.vectorStoreId + additionalProperties = + organizationUsageFileSearchesResult.additionalProperties.toMutableMap() + } + + /** The count of file search calls. */ + fun numRequests(numRequests: Long) = numRequests(JsonField.of(numRequests)) + + /** + * Sets [Builder.numRequests] to an arbitrary JSON value. + * + * You should usually call [Builder.numRequests] with a well-typed [Long] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun numRequests(numRequests: JsonField) = apply { + this.numRequests = numRequests + } + + /** + * Sets the field to an arbitrary JSON value. + * + * It is usually unnecessary to call this method because the field defaults to + * the following: + * ```java + * JsonValue.from("organization.usage.file_searches.result") + * ``` + * + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun object_(object_: JsonValue) = apply { this.object_ = object_ } + + /** + * When `group_by=api_key_id`, this field provides the API key ID of the grouped + * usage result. + */ + fun apiKeyId(apiKeyId: String?) = apiKeyId(JsonField.ofNullable(apiKeyId)) + + /** Alias for calling [Builder.apiKeyId] with `apiKeyId.orElse(null)`. */ + fun apiKeyId(apiKeyId: Optional) = apiKeyId(apiKeyId.getOrNull()) + + /** + * Sets [Builder.apiKeyId] to an arbitrary JSON value. + * + * You should usually call [Builder.apiKeyId] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun apiKeyId(apiKeyId: JsonField) = apply { this.apiKeyId = apiKeyId } + + /** + * When `group_by=project_id`, this field provides the project ID of the grouped + * usage result. + */ + fun projectId(projectId: String?) = projectId(JsonField.ofNullable(projectId)) + + /** Alias for calling [Builder.projectId] with `projectId.orElse(null)`. */ + fun projectId(projectId: Optional) = projectId(projectId.getOrNull()) + + /** + * 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 + } + + /** + * When `group_by=user_id`, this field provides the user ID of the grouped usage + * result. + */ + 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 } + + /** + * When `group_by=vector_store_id`, this field provides the vector store ID of + * the grouped usage result. + */ + fun vectorStoreId(vectorStoreId: String?) = + vectorStoreId(JsonField.ofNullable(vectorStoreId)) + + /** + * Alias for calling [Builder.vectorStoreId] with `vectorStoreId.orElse(null)`. + */ + fun vectorStoreId(vectorStoreId: Optional) = + vectorStoreId(vectorStoreId.getOrNull()) + + /** + * Sets [Builder.vectorStoreId] to an arbitrary JSON value. + * + * You should usually call [Builder.vectorStoreId] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun vectorStoreId(vectorStoreId: JsonField) = apply { + this.vectorStoreId = vectorStoreId + } + + 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 [OrganizationUsageFileSearchesResult]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .numRequests() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): OrganizationUsageFileSearchesResult = + OrganizationUsageFileSearchesResult( + checkRequired("numRequests", numRequests), + object_, + apiKeyId, + projectId, + userId, + vectorStoreId, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing + * fields. + * + * @throws OpenAIInvalidDataException if any value type in this object doesn't match + * its expected type. + */ + fun validate(): OrganizationUsageFileSearchesResult = apply { + if (validated) { + return@apply + } + + numRequests() + _object_().let { + if (it != JsonValue.from("organization.usage.file_searches.result")) { + throw OpenAIInvalidDataException("'object_' is invalid, received $it") + } + } + apiKeyId() + projectId() + userId() + vectorStoreId() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OpenAIInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (if (numRequests.asKnown().isPresent) 1 else 0) + + object_.let { + if (it == JsonValue.from("organization.usage.file_searches.result")) 1 + else 0 + } + + (if (apiKeyId.asKnown().isPresent) 1 else 0) + + (if (projectId.asKnown().isPresent) 1 else 0) + + (if (userId.asKnown().isPresent) 1 else 0) + + (if (vectorStoreId.asKnown().isPresent) 1 else 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is OrganizationUsageFileSearchesResult && + numRequests == other.numRequests && + object_ == other.object_ && + apiKeyId == other.apiKeyId && + projectId == other.projectId && + userId == other.userId && + vectorStoreId == other.vectorStoreId && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + numRequests, + object_, + apiKeyId, + projectId, + userId, + vectorStoreId, + additionalProperties, + ) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "OrganizationUsageFileSearchesResult{numRequests=$numRequests, object_=$object_, apiKeyId=$apiKeyId, projectId=$projectId, userId=$userId, vectorStoreId=$vectorStoreId, additionalProperties=$additionalProperties}" + } + + /** The aggregated web search calls usage details of the specific time bucket. */ + class OrganizationUsageWebSearchesResult + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val numModelRequests: JsonField, + private val numRequests: JsonField, + private val object_: JsonValue, + private val apiKeyId: JsonField, + private val contextLevel: JsonField, + private val model: JsonField, + private val projectId: JsonField, + private val userId: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("num_model_requests") + @ExcludeMissing + numModelRequests: JsonField = JsonMissing.of(), + @JsonProperty("num_requests") + @ExcludeMissing + numRequests: JsonField = JsonMissing.of(), + @JsonProperty("object") @ExcludeMissing object_: JsonValue = JsonMissing.of(), + @JsonProperty("api_key_id") + @ExcludeMissing + apiKeyId: JsonField = JsonMissing.of(), + @JsonProperty("context_level") + @ExcludeMissing + contextLevel: JsonField = JsonMissing.of(), + @JsonProperty("model") + @ExcludeMissing + model: JsonField = JsonMissing.of(), + @JsonProperty("project_id") + @ExcludeMissing + projectId: JsonField = JsonMissing.of(), + @JsonProperty("user_id") + @ExcludeMissing + userId: JsonField = JsonMissing.of(), + ) : this( + numModelRequests, + numRequests, + object_, + apiKeyId, + contextLevel, + model, + projectId, + userId, + mutableMapOf(), + ) + + /** + * The count of model requests. + * + * @throws OpenAIInvalidDataException 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 numModelRequests(): Long = numModelRequests.getRequired("num_model_requests") + + /** + * The count of web search calls. + * + * @throws OpenAIInvalidDataException 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 numRequests(): Long = numRequests.getRequired("num_requests") + + /** + * Expected to always return the following: + * ```java + * JsonValue.from("organization.usage.web_searches.result") + * ``` + * + * However, this method can be useful for debugging and logging (e.g. if the server + * responded with an unexpected value). + */ + @JsonProperty("object") @ExcludeMissing fun _object_(): JsonValue = object_ + + /** + * When `group_by=api_key_id`, this field provides the API key ID of the grouped + * usage result. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun apiKeyId(): Optional = apiKeyId.getOptional("api_key_id") + + /** + * When `group_by=context_level`, this field provides the search context size of the + * grouped usage result. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun contextLevel(): Optional = contextLevel.getOptional("context_level") + + /** + * When `group_by=model`, this field provides the model name of the grouped usage + * result. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun model(): Optional = model.getOptional("model") + + /** + * When `group_by=project_id`, this field provides the project ID of the grouped + * usage result. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun projectId(): Optional = projectId.getOptional("project_id") + + /** + * When `group_by=user_id`, this field provides the user ID of the grouped usage + * result. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun userId(): Optional = userId.getOptional("user_id") + + /** + * Returns the raw JSON value of [numModelRequests]. + * + * Unlike [numModelRequests], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("num_model_requests") + @ExcludeMissing + fun _numModelRequests(): JsonField = numModelRequests + + /** + * Returns the raw JSON value of [numRequests]. + * + * Unlike [numRequests], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("num_requests") + @ExcludeMissing + fun _numRequests(): JsonField = numRequests + + /** + * Returns the raw JSON value of [apiKeyId]. + * + * Unlike [apiKeyId], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("api_key_id") + @ExcludeMissing + fun _apiKeyId(): JsonField = apiKeyId + + /** + * Returns the raw JSON value of [contextLevel]. + * + * Unlike [contextLevel], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("context_level") + @ExcludeMissing + fun _contextLevel(): JsonField = contextLevel + + /** + * Returns the raw JSON value of [model]. + * + * Unlike [model], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("model") @ExcludeMissing fun _model(): JsonField = model + + /** + * 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 [userId]. + * + * Unlike [userId], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @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 = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of + * [OrganizationUsageWebSearchesResult]. + * + * The following fields are required: + * ```java + * .numModelRequests() + * .numRequests() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [OrganizationUsageWebSearchesResult]. */ + class Builder internal constructor() { + + private var numModelRequests: JsonField? = null + private var numRequests: JsonField? = null + private var object_: JsonValue = + JsonValue.from("organization.usage.web_searches.result") + private var apiKeyId: JsonField = JsonMissing.of() + private var contextLevel: JsonField = JsonMissing.of() + private var model: JsonField = JsonMissing.of() + private var projectId: JsonField = JsonMissing.of() + private var userId: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from( + organizationUsageWebSearchesResult: OrganizationUsageWebSearchesResult + ) = apply { + numModelRequests = organizationUsageWebSearchesResult.numModelRequests + numRequests = organizationUsageWebSearchesResult.numRequests + object_ = organizationUsageWebSearchesResult.object_ + apiKeyId = organizationUsageWebSearchesResult.apiKeyId + contextLevel = organizationUsageWebSearchesResult.contextLevel + model = organizationUsageWebSearchesResult.model + projectId = organizationUsageWebSearchesResult.projectId + userId = organizationUsageWebSearchesResult.userId + additionalProperties = + organizationUsageWebSearchesResult.additionalProperties.toMutableMap() + } + + /** The count of model requests. */ + fun numModelRequests(numModelRequests: Long) = + numModelRequests(JsonField.of(numModelRequests)) + + /** + * Sets [Builder.numModelRequests] to an arbitrary JSON value. + * + * You should usually call [Builder.numModelRequests] with a well-typed [Long] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun numModelRequests(numModelRequests: JsonField) = apply { + this.numModelRequests = numModelRequests + } + + /** The count of web search calls. */ + fun numRequests(numRequests: Long) = numRequests(JsonField.of(numRequests)) + + /** + * Sets [Builder.numRequests] to an arbitrary JSON value. + * + * You should usually call [Builder.numRequests] with a well-typed [Long] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun numRequests(numRequests: JsonField) = apply { + this.numRequests = numRequests + } + + /** + * Sets the field to an arbitrary JSON value. + * + * It is usually unnecessary to call this method because the field defaults to + * the following: + * ```java + * JsonValue.from("organization.usage.web_searches.result") + * ``` + * + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun object_(object_: JsonValue) = apply { this.object_ = object_ } + + /** + * When `group_by=api_key_id`, this field provides the API key ID of the grouped + * usage result. + */ + fun apiKeyId(apiKeyId: String?) = apiKeyId(JsonField.ofNullable(apiKeyId)) + + /** Alias for calling [Builder.apiKeyId] with `apiKeyId.orElse(null)`. */ + fun apiKeyId(apiKeyId: Optional) = apiKeyId(apiKeyId.getOrNull()) + + /** + * Sets [Builder.apiKeyId] to an arbitrary JSON value. + * + * You should usually call [Builder.apiKeyId] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun apiKeyId(apiKeyId: JsonField) = apply { this.apiKeyId = apiKeyId } + + /** + * When `group_by=context_level`, this field provides the search context size of + * the grouped usage result. + */ + fun contextLevel(contextLevel: String?) = + contextLevel(JsonField.ofNullable(contextLevel)) + + /** + * Alias for calling [Builder.contextLevel] with `contextLevel.orElse(null)`. + */ + fun contextLevel(contextLevel: Optional) = + contextLevel(contextLevel.getOrNull()) + + /** + * Sets [Builder.contextLevel] to an arbitrary JSON value. + * + * You should usually call [Builder.contextLevel] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun contextLevel(contextLevel: JsonField) = apply { + this.contextLevel = contextLevel + } + + /** + * When `group_by=model`, this field provides the model name of the grouped + * usage result. + */ + fun model(model: String?) = model(JsonField.ofNullable(model)) + + /** Alias for calling [Builder.model] with `model.orElse(null)`. */ + fun model(model: Optional) = model(model.getOrNull()) + + /** + * Sets [Builder.model] to an arbitrary JSON value. + * + * You should usually call [Builder.model] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun model(model: JsonField) = apply { this.model = model } + + /** + * When `group_by=project_id`, this field provides the project ID of the grouped + * usage result. + */ + fun projectId(projectId: String?) = projectId(JsonField.ofNullable(projectId)) + + /** Alias for calling [Builder.projectId] with `projectId.orElse(null)`. */ + fun projectId(projectId: Optional) = projectId(projectId.getOrNull()) + + /** + * 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 + } + + /** + * When `group_by=user_id`, this field provides the user ID of the grouped usage + * result. + */ + 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 } + + 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 [OrganizationUsageWebSearchesResult]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .numModelRequests() + * .numRequests() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): OrganizationUsageWebSearchesResult = + OrganizationUsageWebSearchesResult( + checkRequired("numModelRequests", numModelRequests), + checkRequired("numRequests", numRequests), + object_, + apiKeyId, + contextLevel, + model, + projectId, + userId, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing + * fields. + * + * @throws OpenAIInvalidDataException if any value type in this object doesn't match + * its expected type. + */ + fun validate(): OrganizationUsageWebSearchesResult = apply { + if (validated) { + return@apply + } + + numModelRequests() + numRequests() + _object_().let { + if (it != JsonValue.from("organization.usage.web_searches.result")) { + throw OpenAIInvalidDataException("'object_' is invalid, received $it") + } + } + apiKeyId() + contextLevel() + model() + projectId() + userId() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OpenAIInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (if (numModelRequests.asKnown().isPresent) 1 else 0) + + (if (numRequests.asKnown().isPresent) 1 else 0) + + object_.let { + if (it == JsonValue.from("organization.usage.web_searches.result")) 1 + else 0 + } + + (if (apiKeyId.asKnown().isPresent) 1 else 0) + + (if (contextLevel.asKnown().isPresent) 1 else 0) + + (if (model.asKnown().isPresent) 1 else 0) + + (if (projectId.asKnown().isPresent) 1 else 0) + + (if (userId.asKnown().isPresent) 1 else 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is OrganizationUsageWebSearchesResult && + numModelRequests == other.numModelRequests && + numRequests == other.numRequests && + object_ == other.object_ && + apiKeyId == other.apiKeyId && + contextLevel == other.contextLevel && + model == other.model && + projectId == other.projectId && + userId == other.userId && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + numModelRequests, + numRequests, + object_, + apiKeyId, + contextLevel, + model, + projectId, + userId, + additionalProperties, + ) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "OrganizationUsageWebSearchesResult{numModelRequests=$numModelRequests, numRequests=$numRequests, object_=$object_, apiKeyId=$apiKeyId, contextLevel=$contextLevel, model=$model, projectId=$projectId, userId=$userId, additionalProperties=$additionalProperties}" + } + /** The aggregated costs details of the specific time bucket. */ class OrganizationCostsResult @JsonCreator(mode = JsonCreator.Mode.DISABLED) diff --git a/openai-java-core/src/main/kotlin/com/openai/models/conversations/ConversationCreateParams.kt b/openai-java-core/src/main/kotlin/com/openai/models/conversations/ConversationCreateParams.kt index c5f016f47..7d328f379 100644 --- a/openai-java-core/src/main/kotlin/com/openai/models/conversations/ConversationCreateParams.kt +++ b/openai-java-core/src/main/kotlin/com/openai/models/conversations/ConversationCreateParams.kt @@ -346,6 +346,9 @@ private constructor( */ fun addItem(customToolCall: ResponseCustomToolCall) = apply { body.addItem(customToolCall) } + /** Alias for calling [addItem] with `ResponseInputItem.ofCompactionTrigger()`. */ + fun addItemCompactionTrigger() = apply { body.addItemCompactionTrigger() } + /** Alias for calling [addItem] with `ResponseInputItem.ofItemReference(itemReference)`. */ fun addItem(itemReference: ResponseInputItem.ItemReference) = apply { body.addItem(itemReference) @@ -845,6 +848,9 @@ private constructor( fun addItem(customToolCall: ResponseCustomToolCall) = addItem(ResponseInputItem.ofCustomToolCall(customToolCall)) + /** Alias for calling [addItem] with `ResponseInputItem.ofCompactionTrigger()`. */ + fun addItemCompactionTrigger() = addItem(ResponseInputItem.ofCompactionTrigger()) + /** * Alias for calling [addItem] with `ResponseInputItem.ofItemReference(itemReference)`. */ diff --git a/openai-java-core/src/main/kotlin/com/openai/models/conversations/items/ItemCreateParams.kt b/openai-java-core/src/main/kotlin/com/openai/models/conversations/items/ItemCreateParams.kt index ef58c910e..485360a4c 100644 --- a/openai-java-core/src/main/kotlin/com/openai/models/conversations/items/ItemCreateParams.kt +++ b/openai-java-core/src/main/kotlin/com/openai/models/conversations/items/ItemCreateParams.kt @@ -368,6 +368,9 @@ private constructor( */ fun addItem(customToolCall: ResponseCustomToolCall) = apply { body.addItem(customToolCall) } + /** Alias for calling [addItem] with `ResponseInputItem.ofCompactionTrigger()`. */ + fun addItemCompactionTrigger() = apply { body.addItemCompactionTrigger() } + /** Alias for calling [addItem] with `ResponseInputItem.ofItemReference(itemReference)`. */ fun addItem(itemReference: ResponseInputItem.ItemReference) = apply { body.addItem(itemReference) @@ -840,6 +843,9 @@ private constructor( fun addItem(customToolCall: ResponseCustomToolCall) = addItem(ResponseInputItem.ofCustomToolCall(customToolCall)) + /** Alias for calling [addItem] with `ResponseInputItem.ofCompactionTrigger()`. */ + fun addItemCompactionTrigger() = addItem(ResponseInputItem.ofCompactionTrigger()) + /** * Alias for calling [addItem] with `ResponseInputItem.ofItemReference(itemReference)`. */ diff --git a/openai-java-core/src/main/kotlin/com/openai/models/responses/ResponseInputItem.kt b/openai-java-core/src/main/kotlin/com/openai/models/responses/ResponseInputItem.kt index 6d293840a..1ce24c8fc 100644 --- a/openai-java-core/src/main/kotlin/com/openai/models/responses/ResponseInputItem.kt +++ b/openai-java-core/src/main/kotlin/com/openai/models/responses/ResponseInputItem.kt @@ -69,6 +69,7 @@ private constructor( private val mcpCall: McpCall? = null, private val customToolCallOutput: ResponseCustomToolCallOutput? = null, private val customToolCall: ResponseCustomToolCall? = null, + private val compactionTrigger: JsonValue? = null, private val itemReference: ItemReference? = null, private val _json: JsonValue? = null, ) { @@ -193,6 +194,9 @@ private constructor( /** A call to a custom tool created by the model. */ fun customToolCall(): Optional = Optional.ofNullable(customToolCall) + /** Compacts the current context. Must be the final input item. */ + fun compactionTrigger(): Optional = Optional.ofNullable(compactionTrigger) + /** An internal identifier for an item to reference. */ fun itemReference(): Optional = Optional.ofNullable(itemReference) @@ -250,6 +254,8 @@ private constructor( fun isCustomToolCall(): Boolean = customToolCall != null + fun isCompactionTrigger(): Boolean = compactionTrigger != null + fun isItemReference(): Boolean = itemReference != null /** @@ -375,6 +381,9 @@ private constructor( /** A call to a custom tool created by the model. */ fun asCustomToolCall(): ResponseCustomToolCall = customToolCall.getOrThrow("customToolCall") + /** Compacts the current context. Must be the final input item. */ + fun asCompactionTrigger(): JsonValue = compactionTrigger.getOrThrow("compactionTrigger") + /** An internal identifier for an item to reference. */ fun asItemReference(): ItemReference = itemReference.getOrThrow("itemReference") @@ -439,6 +448,7 @@ private constructor( mcpCall != null -> visitor.visitMcpCall(mcpCall) customToolCallOutput != null -> visitor.visitCustomToolCallOutput(customToolCallOutput) customToolCall != null -> visitor.visitCustomToolCall(customToolCall) + compactionTrigger != null -> visitor.visitCompactionTrigger(compactionTrigger) itemReference != null -> visitor.visitItemReference(itemReference) else -> visitor.unknown(_json) } @@ -576,6 +586,16 @@ private constructor( customToolCall.validate() } + override fun visitCompactionTrigger(compactionTrigger: JsonValue) { + compactionTrigger.let { + if (it != JsonValue.from(mapOf("type" to "compaction_trigger"))) { + throw OpenAIInvalidDataException( + "'compactionTrigger' is invalid, received $it" + ) + } + } + } + override fun visitItemReference(itemReference: ItemReference) { itemReference.validate() } @@ -681,6 +701,11 @@ private constructor( override fun visitCustomToolCall(customToolCall: ResponseCustomToolCall) = customToolCall.validity() + override fun visitCompactionTrigger(compactionTrigger: JsonValue) = + compactionTrigger.let { + if (it == JsonValue.from(mapOf("type" to "compaction_trigger"))) 1 else 0 + } + override fun visitItemReference(itemReference: ItemReference) = itemReference.validity() @@ -721,6 +746,7 @@ private constructor( mcpCall == other.mcpCall && customToolCallOutput == other.customToolCallOutput && customToolCall == other.customToolCall && + compactionTrigger == other.compactionTrigger && itemReference == other.itemReference } @@ -753,6 +779,7 @@ private constructor( mcpCall, customToolCallOutput, customToolCall, + compactionTrigger, itemReference, ) @@ -795,6 +822,7 @@ private constructor( customToolCallOutput != null -> "ResponseInputItem{customToolCallOutput=$customToolCallOutput}" customToolCall != null -> "ResponseInputItem{customToolCall=$customToolCall}" + compactionTrigger != null -> "ResponseInputItem{compactionTrigger=$compactionTrigger}" itemReference != null -> "ResponseInputItem{itemReference=$itemReference}" _json != null -> "ResponseInputItem{_unknown=$_json}" else -> throw IllegalStateException("Invalid ResponseInputItem") @@ -963,6 +991,13 @@ private constructor( fun ofCustomToolCall(customToolCall: ResponseCustomToolCall) = ResponseInputItem(customToolCall = customToolCall) + /** Compacts the current context. Must be the final input item. */ + @JvmStatic + fun ofCompactionTrigger() = + ResponseInputItem( + compactionTrigger = JsonValue.from(mapOf("type" to "compaction_trigger")) + ) + /** An internal identifier for an item to reference. */ @JvmStatic fun ofItemReference(itemReference: ItemReference) = @@ -1089,6 +1124,9 @@ private constructor( /** A call to a custom tool created by the model. */ fun visitCustomToolCall(customToolCall: ResponseCustomToolCall): T + /** Compacts the current context. Must be the final input item. */ + fun visitCompactionTrigger(compactionTrigger: JsonValue): T + /** An internal identifier for an item to reference. */ fun visitItemReference(itemReference: ItemReference): T @@ -1261,6 +1299,11 @@ private constructor( ResponseInputItem(customToolCall = it, _json = json) } ?: ResponseInputItem(_json = json) } + "compaction_trigger" -> { + return tryDeserialize(node, jacksonTypeRef()) + ?.let { ResponseInputItem(compactionTrigger = it, _json = json) } + ?.takeIf { it.isValid() } ?: ResponseInputItem(_json = json) + } "item_reference" -> { return tryDeserialize(node, jacksonTypeRef())?.let { ResponseInputItem(itemReference = it, _json = json) @@ -1314,6 +1357,7 @@ private constructor( value.customToolCallOutput != null -> generator.writeObject(value.customToolCallOutput) value.customToolCall != null -> generator.writeObject(value.customToolCall) + value.compactionTrigger != null -> generator.writeObject(value.compactionTrigger) value.itemReference != null -> generator.writeObject(value.itemReference) value._json != null -> generator.writeObject(value._json) else -> throw IllegalStateException("Invalid ResponseInputItem") diff --git a/openai-java-core/src/test/kotlin/com/openai/models/responses/ResponseInputItemTest.kt b/openai-java-core/src/test/kotlin/com/openai/models/responses/ResponseInputItemTest.kt index 48bc41dc4..4186f4a38 100644 --- a/openai-java-core/src/test/kotlin/com/openai/models/responses/ResponseInputItemTest.kt +++ b/openai-java-core/src/test/kotlin/com/openai/models/responses/ResponseInputItemTest.kt @@ -53,6 +53,7 @@ internal class ResponseInputItemTest { assertThat(responseInputItem.mcpCall()).isEmpty assertThat(responseInputItem.customToolCallOutput()).isEmpty assertThat(responseInputItem.customToolCall()).isEmpty + assertThat(responseInputItem.compactionTrigger()).isEmpty assertThat(responseInputItem.itemReference()).isEmpty } @@ -117,6 +118,7 @@ internal class ResponseInputItemTest { assertThat(responseInputItem.mcpCall()).isEmpty assertThat(responseInputItem.customToolCallOutput()).isEmpty assertThat(responseInputItem.customToolCall()).isEmpty + assertThat(responseInputItem.compactionTrigger()).isEmpty assertThat(responseInputItem.itemReference()).isEmpty } @@ -206,6 +208,7 @@ internal class ResponseInputItemTest { assertThat(responseInputItem.mcpCall()).isEmpty assertThat(responseInputItem.customToolCallOutput()).isEmpty assertThat(responseInputItem.customToolCall()).isEmpty + assertThat(responseInputItem.compactionTrigger()).isEmpty assertThat(responseInputItem.itemReference()).isEmpty } @@ -307,6 +310,7 @@ internal class ResponseInputItemTest { assertThat(responseInputItem.mcpCall()).isEmpty assertThat(responseInputItem.customToolCallOutput()).isEmpty assertThat(responseInputItem.customToolCall()).isEmpty + assertThat(responseInputItem.compactionTrigger()).isEmpty assertThat(responseInputItem.itemReference()).isEmpty } @@ -406,6 +410,7 @@ internal class ResponseInputItemTest { assertThat(responseInputItem.mcpCall()).isEmpty assertThat(responseInputItem.customToolCallOutput()).isEmpty assertThat(responseInputItem.customToolCall()).isEmpty + assertThat(responseInputItem.compactionTrigger()).isEmpty assertThat(responseInputItem.itemReference()).isEmpty } @@ -505,6 +510,7 @@ internal class ResponseInputItemTest { assertThat(responseInputItem.mcpCall()).isEmpty assertThat(responseInputItem.customToolCallOutput()).isEmpty assertThat(responseInputItem.customToolCall()).isEmpty + assertThat(responseInputItem.compactionTrigger()).isEmpty assertThat(responseInputItem.itemReference()).isEmpty } @@ -590,6 +596,7 @@ internal class ResponseInputItemTest { assertThat(responseInputItem.mcpCall()).isEmpty assertThat(responseInputItem.customToolCallOutput()).isEmpty assertThat(responseInputItem.customToolCall()).isEmpty + assertThat(responseInputItem.compactionTrigger()).isEmpty assertThat(responseInputItem.itemReference()).isEmpty } @@ -665,6 +672,7 @@ internal class ResponseInputItemTest { assertThat(responseInputItem.mcpCall()).isEmpty assertThat(responseInputItem.customToolCallOutput()).isEmpty assertThat(responseInputItem.customToolCall()).isEmpty + assertThat(responseInputItem.compactionTrigger()).isEmpty assertThat(responseInputItem.itemReference()).isEmpty } @@ -731,6 +739,7 @@ internal class ResponseInputItemTest { assertThat(responseInputItem.mcpCall()).isEmpty assertThat(responseInputItem.customToolCallOutput()).isEmpty assertThat(responseInputItem.customToolCall()).isEmpty + assertThat(responseInputItem.compactionTrigger()).isEmpty assertThat(responseInputItem.itemReference()).isEmpty } @@ -796,6 +805,7 @@ internal class ResponseInputItemTest { assertThat(responseInputItem.mcpCall()).isEmpty assertThat(responseInputItem.customToolCallOutput()).isEmpty assertThat(responseInputItem.customToolCall()).isEmpty + assertThat(responseInputItem.compactionTrigger()).isEmpty assertThat(responseInputItem.itemReference()).isEmpty } @@ -874,6 +884,7 @@ internal class ResponseInputItemTest { assertThat(responseInputItem.mcpCall()).isEmpty assertThat(responseInputItem.customToolCallOutput()).isEmpty assertThat(responseInputItem.customToolCall()).isEmpty + assertThat(responseInputItem.compactionTrigger()).isEmpty assertThat(responseInputItem.itemReference()).isEmpty } @@ -952,6 +963,7 @@ internal class ResponseInputItemTest { assertThat(responseInputItem.mcpCall()).isEmpty assertThat(responseInputItem.customToolCallOutput()).isEmpty assertThat(responseInputItem.customToolCall()).isEmpty + assertThat(responseInputItem.compactionTrigger()).isEmpty assertThat(responseInputItem.itemReference()).isEmpty } @@ -1015,6 +1027,7 @@ internal class ResponseInputItemTest { assertThat(responseInputItem.mcpCall()).isEmpty assertThat(responseInputItem.customToolCallOutput()).isEmpty assertThat(responseInputItem.customToolCall()).isEmpty + assertThat(responseInputItem.compactionTrigger()).isEmpty assertThat(responseInputItem.itemReference()).isEmpty } @@ -1076,6 +1089,7 @@ internal class ResponseInputItemTest { assertThat(responseInputItem.mcpCall()).isEmpty assertThat(responseInputItem.customToolCallOutput()).isEmpty assertThat(responseInputItem.customToolCall()).isEmpty + assertThat(responseInputItem.compactionTrigger()).isEmpty assertThat(responseInputItem.itemReference()).isEmpty } @@ -1140,6 +1154,7 @@ internal class ResponseInputItemTest { assertThat(responseInputItem.mcpCall()).isEmpty assertThat(responseInputItem.customToolCallOutput()).isEmpty assertThat(responseInputItem.customToolCall()).isEmpty + assertThat(responseInputItem.compactionTrigger()).isEmpty assertThat(responseInputItem.itemReference()).isEmpty } @@ -1217,6 +1232,7 @@ internal class ResponseInputItemTest { assertThat(responseInputItem.mcpCall()).isEmpty assertThat(responseInputItem.customToolCallOutput()).isEmpty assertThat(responseInputItem.customToolCall()).isEmpty + assertThat(responseInputItem.compactionTrigger()).isEmpty assertThat(responseInputItem.itemReference()).isEmpty } @@ -1292,6 +1308,7 @@ internal class ResponseInputItemTest { assertThat(responseInputItem.mcpCall()).isEmpty assertThat(responseInputItem.customToolCallOutput()).isEmpty assertThat(responseInputItem.customToolCall()).isEmpty + assertThat(responseInputItem.compactionTrigger()).isEmpty assertThat(responseInputItem.itemReference()).isEmpty } @@ -1372,6 +1389,7 @@ internal class ResponseInputItemTest { assertThat(responseInputItem.mcpCall()).isEmpty assertThat(responseInputItem.customToolCallOutput()).isEmpty assertThat(responseInputItem.customToolCall()).isEmpty + assertThat(responseInputItem.compactionTrigger()).isEmpty assertThat(responseInputItem.itemReference()).isEmpty } @@ -1460,6 +1478,7 @@ internal class ResponseInputItemTest { assertThat(responseInputItem.mcpCall()).isEmpty assertThat(responseInputItem.customToolCallOutput()).isEmpty assertThat(responseInputItem.customToolCall()).isEmpty + assertThat(responseInputItem.compactionTrigger()).isEmpty assertThat(responseInputItem.itemReference()).isEmpty } @@ -1536,6 +1555,7 @@ internal class ResponseInputItemTest { assertThat(responseInputItem.mcpCall()).isEmpty assertThat(responseInputItem.customToolCallOutput()).isEmpty assertThat(responseInputItem.customToolCall()).isEmpty + assertThat(responseInputItem.compactionTrigger()).isEmpty assertThat(responseInputItem.itemReference()).isEmpty } @@ -1605,6 +1625,7 @@ internal class ResponseInputItemTest { assertThat(responseInputItem.mcpCall()).isEmpty assertThat(responseInputItem.customToolCallOutput()).isEmpty assertThat(responseInputItem.customToolCall()).isEmpty + assertThat(responseInputItem.compactionTrigger()).isEmpty assertThat(responseInputItem.itemReference()).isEmpty } @@ -1676,6 +1697,7 @@ internal class ResponseInputItemTest { assertThat(responseInputItem.mcpCall()).isEmpty assertThat(responseInputItem.customToolCallOutput()).isEmpty assertThat(responseInputItem.customToolCall()).isEmpty + assertThat(responseInputItem.compactionTrigger()).isEmpty assertThat(responseInputItem.itemReference()).isEmpty } @@ -1747,6 +1769,7 @@ internal class ResponseInputItemTest { assertThat(responseInputItem.mcpCall()).isEmpty assertThat(responseInputItem.customToolCallOutput()).isEmpty assertThat(responseInputItem.customToolCall()).isEmpty + assertThat(responseInputItem.compactionTrigger()).isEmpty assertThat(responseInputItem.itemReference()).isEmpty } @@ -1811,6 +1834,7 @@ internal class ResponseInputItemTest { assertThat(responseInputItem.mcpCall()).isEmpty assertThat(responseInputItem.customToolCallOutput()).isEmpty assertThat(responseInputItem.customToolCall()).isEmpty + assertThat(responseInputItem.compactionTrigger()).isEmpty assertThat(responseInputItem.itemReference()).isEmpty } @@ -1879,6 +1903,7 @@ internal class ResponseInputItemTest { assertThat(responseInputItem.mcpCall()).contains(mcpCall) assertThat(responseInputItem.customToolCallOutput()).isEmpty assertThat(responseInputItem.customToolCall()).isEmpty + assertThat(responseInputItem.compactionTrigger()).isEmpty assertThat(responseInputItem.itemReference()).isEmpty } @@ -1946,6 +1971,7 @@ internal class ResponseInputItemTest { assertThat(responseInputItem.mcpCall()).isEmpty assertThat(responseInputItem.customToolCallOutput()).contains(customToolCallOutput) assertThat(responseInputItem.customToolCall()).isEmpty + assertThat(responseInputItem.compactionTrigger()).isEmpty assertThat(responseInputItem.itemReference()).isEmpty } @@ -2010,6 +2036,7 @@ internal class ResponseInputItemTest { assertThat(responseInputItem.mcpCall()).isEmpty assertThat(responseInputItem.customToolCallOutput()).isEmpty assertThat(responseInputItem.customToolCall()).contains(customToolCall) + assertThat(responseInputItem.compactionTrigger()).isEmpty assertThat(responseInputItem.itemReference()).isEmpty } @@ -2036,6 +2063,56 @@ internal class ResponseInputItemTest { assertThat(roundtrippedResponseInputItem).isEqualTo(responseInputItem) } + @Test + fun ofCompactionTrigger() { + val responseInputItem = ResponseInputItem.ofCompactionTrigger() + + assertThat(responseInputItem.easyInputMessage()).isEmpty + assertThat(responseInputItem.message()).isEmpty + assertThat(responseInputItem.responseOutputMessage()).isEmpty + assertThat(responseInputItem.fileSearchCall()).isEmpty + assertThat(responseInputItem.computerCall()).isEmpty + assertThat(responseInputItem.computerCallOutput()).isEmpty + assertThat(responseInputItem.webSearchCall()).isEmpty + assertThat(responseInputItem.functionCall()).isEmpty + assertThat(responseInputItem.functionCallOutput()).isEmpty + assertThat(responseInputItem.toolSearchCall()).isEmpty + assertThat(responseInputItem.toolSearchOutput()).isEmpty + assertThat(responseInputItem.reasoning()).isEmpty + assertThat(responseInputItem.compaction()).isEmpty + assertThat(responseInputItem.imageGenerationCall()).isEmpty + assertThat(responseInputItem.codeInterpreterCall()).isEmpty + assertThat(responseInputItem.localShellCall()).isEmpty + assertThat(responseInputItem.localShellCallOutput()).isEmpty + assertThat(responseInputItem.shellCall()).isEmpty + assertThat(responseInputItem.shellCallOutput()).isEmpty + assertThat(responseInputItem.applyPatchCall()).isEmpty + assertThat(responseInputItem.applyPatchCallOutput()).isEmpty + assertThat(responseInputItem.mcpListTools()).isEmpty + assertThat(responseInputItem.mcpApprovalRequest()).isEmpty + assertThat(responseInputItem.mcpApprovalResponse()).isEmpty + assertThat(responseInputItem.mcpCall()).isEmpty + assertThat(responseInputItem.customToolCallOutput()).isEmpty + assertThat(responseInputItem.customToolCall()).isEmpty + assertThat(responseInputItem.compactionTrigger()) + .contains(JsonValue.from(mapOf("type" to "compaction_trigger"))) + assertThat(responseInputItem.itemReference()).isEmpty + } + + @Test + fun ofCompactionTriggerRoundtrip() { + val jsonMapper = jsonMapper() + val responseInputItem = ResponseInputItem.ofCompactionTrigger() + + val roundtrippedResponseInputItem = + jsonMapper.readValue( + jsonMapper.writeValueAsString(responseInputItem), + jacksonTypeRef(), + ) + + assertThat(roundtrippedResponseInputItem).isEqualTo(responseInputItem) + } + @Test fun ofItemReference() { val itemReference = @@ -2073,6 +2150,7 @@ internal class ResponseInputItemTest { assertThat(responseInputItem.mcpCall()).isEmpty assertThat(responseInputItem.customToolCallOutput()).isEmpty assertThat(responseInputItem.customToolCall()).isEmpty + assertThat(responseInputItem.compactionTrigger()).isEmpty assertThat(responseInputItem.itemReference()).contains(itemReference) } From 1a21364f95933116344b0ab703796fb559eb8735 Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Mon, 18 May 2026 18:55:11 +0000 Subject: [PATCH 5/8] feat(api): manual updates Update specs --- .stats.yml | 6 +- .../HostedToolPermissionRetrieveParams.kt | 198 + .../HostedToolPermissionUpdateParams.kt | 1597 ++++ .../ProjectHostedToolPermissions.kt | 1198 +++ .../ModelPermissionDeleteParams.kt | 232 + .../ModelPermissionRetrieveParams.kt | 196 + .../ModelPermissionUpdateParams.kt | 680 ++ .../ProjectModelPermissions.kt | 417 + .../ProjectModelPermissionsDeleted.kt | 225 + .../usage/UsageFileSearchCallsParams.kt | 746 ++ .../usage/UsageFileSearchCallsResponse.kt | 6930 +++++++++++++++++ .../usage/UsageWebSearchCallsParams.kt | 920 +++ .../usage/UsageWebSearchCallsResponse.kt | 6930 +++++++++++++++++ .../admin/organization/ProjectServiceAsync.kt | 10 + .../organization/ProjectServiceAsyncImpl.kt | 31 + .../admin/organization/UsageServiceAsync.kt | 58 + .../organization/UsageServiceAsyncImpl.kt | 86 + .../HostedToolPermissionServiceAsync.kt | 205 + .../HostedToolPermissionServiceAsyncImpl.kt | 156 + .../projects/ModelPermissionServiceAsync.kt | 262 + .../ModelPermissionServiceAsyncImpl.kt | 205 + .../admin/organization/ProjectService.kt | 10 + .../admin/organization/ProjectServiceImpl.kt | 29 + .../admin/organization/UsageService.kt | 58 + .../admin/organization/UsageServiceImpl.kt | 80 + .../projects/HostedToolPermissionService.kt | 201 + .../HostedToolPermissionServiceImpl.kt | 146 + .../projects/ModelPermissionService.kt | 258 + .../projects/ModelPermissionServiceImpl.kt | 193 + .../HostedToolPermissionRetrieveParamsTest.kt | 23 + .../HostedToolPermissionUpdateParamsTest.kt | 79 + .../ProjectHostedToolPermissionsTest.kt | 63 + .../ModelPermissionDeleteParamsTest.kt | 23 + .../ModelPermissionRetrieveParamsTest.kt | 23 + .../ModelPermissionUpdateParamsTest.kt | 47 + .../ProjectModelPermissionsDeletedTest.kt | 35 + .../ProjectModelPermissionsTest.kt | 42 + .../usage/UsageFileSearchCallsParamsTest.kt | 70 + .../usage/UsageFileSearchCallsResponseTest.kt | 113 + .../usage/UsageWebSearchCallsParamsTest.kt | 73 + .../usage/UsageWebSearchCallsResponseTest.kt | 113 + .../organization/UsageServiceAsyncTest.kt | 63 + .../HostedToolPermissionServiceAsyncTest.kt | 70 + .../ModelPermissionServiceAsyncTest.kt | 71 + .../admin/organization/UsageServiceTest.kt | 61 + .../HostedToolPermissionServiceTest.kt | 67 + .../projects/ModelPermissionServiceTest.kt | 65 + 47 files changed, 23361 insertions(+), 3 deletions(-) create mode 100644 openai-java-core/src/main/kotlin/com/openai/models/admin/organization/projects/hostedtoolpermissions/HostedToolPermissionRetrieveParams.kt create mode 100644 openai-java-core/src/main/kotlin/com/openai/models/admin/organization/projects/hostedtoolpermissions/HostedToolPermissionUpdateParams.kt create mode 100644 openai-java-core/src/main/kotlin/com/openai/models/admin/organization/projects/hostedtoolpermissions/ProjectHostedToolPermissions.kt create mode 100644 openai-java-core/src/main/kotlin/com/openai/models/admin/organization/projects/modelpermissions/ModelPermissionDeleteParams.kt create mode 100644 openai-java-core/src/main/kotlin/com/openai/models/admin/organization/projects/modelpermissions/ModelPermissionRetrieveParams.kt create mode 100644 openai-java-core/src/main/kotlin/com/openai/models/admin/organization/projects/modelpermissions/ModelPermissionUpdateParams.kt create mode 100644 openai-java-core/src/main/kotlin/com/openai/models/admin/organization/projects/modelpermissions/ProjectModelPermissions.kt create mode 100644 openai-java-core/src/main/kotlin/com/openai/models/admin/organization/projects/modelpermissions/ProjectModelPermissionsDeleted.kt create mode 100644 openai-java-core/src/main/kotlin/com/openai/models/admin/organization/usage/UsageFileSearchCallsParams.kt create mode 100644 openai-java-core/src/main/kotlin/com/openai/models/admin/organization/usage/UsageFileSearchCallsResponse.kt create mode 100644 openai-java-core/src/main/kotlin/com/openai/models/admin/organization/usage/UsageWebSearchCallsParams.kt create mode 100644 openai-java-core/src/main/kotlin/com/openai/models/admin/organization/usage/UsageWebSearchCallsResponse.kt create mode 100644 openai-java-core/src/main/kotlin/com/openai/services/async/admin/organization/projects/HostedToolPermissionServiceAsync.kt create mode 100644 openai-java-core/src/main/kotlin/com/openai/services/async/admin/organization/projects/HostedToolPermissionServiceAsyncImpl.kt create mode 100644 openai-java-core/src/main/kotlin/com/openai/services/async/admin/organization/projects/ModelPermissionServiceAsync.kt create mode 100644 openai-java-core/src/main/kotlin/com/openai/services/async/admin/organization/projects/ModelPermissionServiceAsyncImpl.kt create mode 100644 openai-java-core/src/main/kotlin/com/openai/services/blocking/admin/organization/projects/HostedToolPermissionService.kt create mode 100644 openai-java-core/src/main/kotlin/com/openai/services/blocking/admin/organization/projects/HostedToolPermissionServiceImpl.kt create mode 100644 openai-java-core/src/main/kotlin/com/openai/services/blocking/admin/organization/projects/ModelPermissionService.kt create mode 100644 openai-java-core/src/main/kotlin/com/openai/services/blocking/admin/organization/projects/ModelPermissionServiceImpl.kt create mode 100644 openai-java-core/src/test/kotlin/com/openai/models/admin/organization/projects/hostedtoolpermissions/HostedToolPermissionRetrieveParamsTest.kt create mode 100644 openai-java-core/src/test/kotlin/com/openai/models/admin/organization/projects/hostedtoolpermissions/HostedToolPermissionUpdateParamsTest.kt create mode 100644 openai-java-core/src/test/kotlin/com/openai/models/admin/organization/projects/hostedtoolpermissions/ProjectHostedToolPermissionsTest.kt create mode 100644 openai-java-core/src/test/kotlin/com/openai/models/admin/organization/projects/modelpermissions/ModelPermissionDeleteParamsTest.kt create mode 100644 openai-java-core/src/test/kotlin/com/openai/models/admin/organization/projects/modelpermissions/ModelPermissionRetrieveParamsTest.kt create mode 100644 openai-java-core/src/test/kotlin/com/openai/models/admin/organization/projects/modelpermissions/ModelPermissionUpdateParamsTest.kt create mode 100644 openai-java-core/src/test/kotlin/com/openai/models/admin/organization/projects/modelpermissions/ProjectModelPermissionsDeletedTest.kt create mode 100644 openai-java-core/src/test/kotlin/com/openai/models/admin/organization/projects/modelpermissions/ProjectModelPermissionsTest.kt create mode 100644 openai-java-core/src/test/kotlin/com/openai/models/admin/organization/usage/UsageFileSearchCallsParamsTest.kt create mode 100644 openai-java-core/src/test/kotlin/com/openai/models/admin/organization/usage/UsageFileSearchCallsResponseTest.kt create mode 100644 openai-java-core/src/test/kotlin/com/openai/models/admin/organization/usage/UsageWebSearchCallsParamsTest.kt create mode 100644 openai-java-core/src/test/kotlin/com/openai/models/admin/organization/usage/UsageWebSearchCallsResponseTest.kt create mode 100644 openai-java-core/src/test/kotlin/com/openai/services/async/admin/organization/projects/HostedToolPermissionServiceAsyncTest.kt create mode 100644 openai-java-core/src/test/kotlin/com/openai/services/async/admin/organization/projects/ModelPermissionServiceAsyncTest.kt create mode 100644 openai-java-core/src/test/kotlin/com/openai/services/blocking/admin/organization/projects/HostedToolPermissionServiceTest.kt create mode 100644 openai-java-core/src/test/kotlin/com/openai/services/blocking/admin/organization/projects/ModelPermissionServiceTest.kt diff --git a/.stats.yml b/.stats.yml index c3dc810d4..787895e02 100644 --- a/.stats.yml +++ b/.stats.yml @@ -1,4 +1,4 @@ -configured_endpoints: 232 -openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/openai/openai-fcfdf0bb920ca15a6d01d1cfe988accb7559b2d991b6e2ad6b25cfae81ac2ae9.yml +configured_endpoints: 239 +openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/openai/openai-d7d5adb20c516e7aca6e35ed9f58aba0bc14dd5aa0096fd980061c4a5ab406e3.yml openapi_spec_hash: 72ee7d4fe582e75d16e67b6c97881fed -config_hash: 70ff4da62a6a6ef9f91d566c38b7bddf +config_hash: af72288617facaeed4d014024a9c946d diff --git a/openai-java-core/src/main/kotlin/com/openai/models/admin/organization/projects/hostedtoolpermissions/HostedToolPermissionRetrieveParams.kt b/openai-java-core/src/main/kotlin/com/openai/models/admin/organization/projects/hostedtoolpermissions/HostedToolPermissionRetrieveParams.kt new file mode 100644 index 000000000..dca181b66 --- /dev/null +++ b/openai-java-core/src/main/kotlin/com/openai/models/admin/organization/projects/hostedtoolpermissions/HostedToolPermissionRetrieveParams.kt @@ -0,0 +1,198 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.models.admin.organization.projects.hostedtoolpermissions + +import com.openai.core.Params +import com.openai.core.http.Headers +import com.openai.core.http.QueryParams +import java.util.Objects +import java.util.Optional +import kotlin.jvm.optionals.getOrNull + +/** Returns hosted tool permissions for a project. */ +class HostedToolPermissionRetrieveParams +private constructor( + private val projectId: String?, + private val additionalHeaders: Headers, + private val additionalQueryParams: QueryParams, +) : Params { + + fun projectId(): Optional = Optional.ofNullable(projectId) + + /** Additional headers to send with the request. */ + fun _additionalHeaders(): Headers = additionalHeaders + + /** Additional query param to send with the request. */ + fun _additionalQueryParams(): QueryParams = additionalQueryParams + + fun toBuilder() = Builder().from(this) + + companion object { + + @JvmStatic fun none(): HostedToolPermissionRetrieveParams = builder().build() + + /** + * Returns a mutable builder for constructing an instance of + * [HostedToolPermissionRetrieveParams]. + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [HostedToolPermissionRetrieveParams]. */ + class Builder internal constructor() { + + private var projectId: String? = null + private var additionalHeaders: Headers.Builder = Headers.builder() + private var additionalQueryParams: QueryParams.Builder = QueryParams.builder() + + @JvmSynthetic + internal fun from(hostedToolPermissionRetrieveParams: HostedToolPermissionRetrieveParams) = + apply { + projectId = hostedToolPermissionRetrieveParams.projectId + additionalHeaders = hostedToolPermissionRetrieveParams.additionalHeaders.toBuilder() + additionalQueryParams = + hostedToolPermissionRetrieveParams.additionalQueryParams.toBuilder() + } + + fun projectId(projectId: String?) = apply { this.projectId = projectId } + + /** Alias for calling [Builder.projectId] with `projectId.orElse(null)`. */ + fun projectId(projectId: Optional) = projectId(projectId.getOrNull()) + + 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 [HostedToolPermissionRetrieveParams]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): HostedToolPermissionRetrieveParams = + HostedToolPermissionRetrieveParams( + projectId, + additionalHeaders.build(), + additionalQueryParams.build(), + ) + } + + 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 + } + + return other is HostedToolPermissionRetrieveParams && + projectId == other.projectId && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams + } + + override fun hashCode(): Int = Objects.hash(projectId, additionalHeaders, additionalQueryParams) + + override fun toString() = + "HostedToolPermissionRetrieveParams{projectId=$projectId, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" +} diff --git a/openai-java-core/src/main/kotlin/com/openai/models/admin/organization/projects/hostedtoolpermissions/HostedToolPermissionUpdateParams.kt b/openai-java-core/src/main/kotlin/com/openai/models/admin/organization/projects/hostedtoolpermissions/HostedToolPermissionUpdateParams.kt new file mode 100644 index 000000000..5f6b2be89 --- /dev/null +++ b/openai-java-core/src/main/kotlin/com/openai/models/admin/organization/projects/hostedtoolpermissions/HostedToolPermissionUpdateParams.kt @@ -0,0 +1,1597 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.models.admin.organization.projects.hostedtoolpermissions + +import com.fasterxml.jackson.annotation.JsonAnyGetter +import com.fasterxml.jackson.annotation.JsonAnySetter +import com.fasterxml.jackson.annotation.JsonCreator +import com.fasterxml.jackson.annotation.JsonProperty +import com.openai.core.ExcludeMissing +import com.openai.core.JsonField +import com.openai.core.JsonMissing +import com.openai.core.JsonValue +import com.openai.core.Params +import com.openai.core.checkRequired +import com.openai.core.http.Headers +import com.openai.core.http.QueryParams +import com.openai.errors.OpenAIInvalidDataException +import java.util.Collections +import java.util.Objects +import java.util.Optional +import kotlin.jvm.optionals.getOrNull + +/** Updates hosted tool permissions for a project. */ +class HostedToolPermissionUpdateParams +private constructor( + private val projectId: String?, + private val body: Body, + private val additionalHeaders: Headers, + private val additionalQueryParams: QueryParams, +) : Params { + + fun projectId(): Optional = Optional.ofNullable(projectId) + + /** + * The code interpreter permission update. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun codeInterpreter(): Optional = body.codeInterpreter() + + /** + * The file search permission update. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun fileSearch(): Optional = body.fileSearch() + + /** + * The image generation permission update. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun imageGeneration(): Optional = body.imageGeneration() + + /** + * The MCP permission update. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun mcp(): Optional = body.mcp() + + /** + * The web search permission update. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun webSearch(): Optional = body.webSearch() + + /** + * Returns the raw JSON value of [codeInterpreter]. + * + * Unlike [codeInterpreter], this method doesn't throw if the JSON field has an unexpected type. + */ + fun _codeInterpreter(): JsonField = body._codeInterpreter() + + /** + * Returns the raw JSON value of [fileSearch]. + * + * Unlike [fileSearch], this method doesn't throw if the JSON field has an unexpected type. + */ + fun _fileSearch(): JsonField = body._fileSearch() + + /** + * Returns the raw JSON value of [imageGeneration]. + * + * Unlike [imageGeneration], this method doesn't throw if the JSON field has an unexpected type. + */ + fun _imageGeneration(): JsonField = body._imageGeneration() + + /** + * Returns the raw JSON value of [mcp]. + * + * Unlike [mcp], this method doesn't throw if the JSON field has an unexpected type. + */ + fun _mcp(): JsonField = body._mcp() + + /** + * Returns the raw JSON value of [webSearch]. + * + * Unlike [webSearch], this method doesn't throw if the JSON field has an unexpected type. + */ + fun _webSearch(): JsonField = body._webSearch() + + fun _additionalBodyProperties(): Map = body._additionalProperties() + + /** Additional headers to send with the request. */ + fun _additionalHeaders(): Headers = additionalHeaders + + /** Additional query param to send with the request. */ + fun _additionalQueryParams(): QueryParams = additionalQueryParams + + fun toBuilder() = Builder().from(this) + + companion object { + + @JvmStatic fun none(): HostedToolPermissionUpdateParams = builder().build() + + /** + * Returns a mutable builder for constructing an instance of + * [HostedToolPermissionUpdateParams]. + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [HostedToolPermissionUpdateParams]. */ + 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 from(hostedToolPermissionUpdateParams: HostedToolPermissionUpdateParams) = + apply { + projectId = hostedToolPermissionUpdateParams.projectId + body = hostedToolPermissionUpdateParams.body.toBuilder() + additionalHeaders = hostedToolPermissionUpdateParams.additionalHeaders.toBuilder() + additionalQueryParams = + hostedToolPermissionUpdateParams.additionalQueryParams.toBuilder() + } + + fun projectId(projectId: String?) = apply { this.projectId = projectId } + + /** Alias for calling [Builder.projectId] with `projectId.orElse(null)`. */ + fun projectId(projectId: Optional) = projectId(projectId.getOrNull()) + + /** + * Sets the entire request body. + * + * This is generally only useful if you are already constructing the body separately. + * Otherwise, it's more convenient to use the top-level setters instead: + * - [codeInterpreter] + * - [fileSearch] + * - [imageGeneration] + * - [mcp] + * - [webSearch] + * - etc. + */ + fun body(body: Body) = apply { this.body = body.toBuilder() } + + /** The code interpreter permission update. */ + fun codeInterpreter(codeInterpreter: CodeInterpreter?) = apply { + body.codeInterpreter(codeInterpreter) + } + + /** Alias for calling [Builder.codeInterpreter] with `codeInterpreter.orElse(null)`. */ + fun codeInterpreter(codeInterpreter: Optional) = + codeInterpreter(codeInterpreter.getOrNull()) + + /** + * Sets [Builder.codeInterpreter] to an arbitrary JSON value. + * + * You should usually call [Builder.codeInterpreter] with a well-typed [CodeInterpreter] + * value instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun codeInterpreter(codeInterpreter: JsonField) = apply { + body.codeInterpreter(codeInterpreter) + } + + /** The file search permission update. */ + fun fileSearch(fileSearch: FileSearch?) = apply { body.fileSearch(fileSearch) } + + /** Alias for calling [Builder.fileSearch] with `fileSearch.orElse(null)`. */ + fun fileSearch(fileSearch: Optional) = fileSearch(fileSearch.getOrNull()) + + /** + * Sets [Builder.fileSearch] to an arbitrary JSON value. + * + * You should usually call [Builder.fileSearch] with a well-typed [FileSearch] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun fileSearch(fileSearch: JsonField) = apply { body.fileSearch(fileSearch) } + + /** The image generation permission update. */ + fun imageGeneration(imageGeneration: ImageGeneration?) = apply { + body.imageGeneration(imageGeneration) + } + + /** Alias for calling [Builder.imageGeneration] with `imageGeneration.orElse(null)`. */ + fun imageGeneration(imageGeneration: Optional) = + imageGeneration(imageGeneration.getOrNull()) + + /** + * Sets [Builder.imageGeneration] to an arbitrary JSON value. + * + * You should usually call [Builder.imageGeneration] with a well-typed [ImageGeneration] + * value instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun imageGeneration(imageGeneration: JsonField) = apply { + body.imageGeneration(imageGeneration) + } + + /** The MCP permission update. */ + fun mcp(mcp: Mcp?) = apply { body.mcp(mcp) } + + /** Alias for calling [Builder.mcp] with `mcp.orElse(null)`. */ + fun mcp(mcp: Optional) = mcp(mcp.getOrNull()) + + /** + * Sets [Builder.mcp] to an arbitrary JSON value. + * + * You should usually call [Builder.mcp] with a well-typed [Mcp] value instead. This method + * is primarily for setting the field to an undocumented or not yet supported value. + */ + fun mcp(mcp: JsonField) = apply { body.mcp(mcp) } + + /** The web search permission update. */ + fun webSearch(webSearch: WebSearch?) = apply { body.webSearch(webSearch) } + + /** Alias for calling [Builder.webSearch] with `webSearch.orElse(null)`. */ + fun webSearch(webSearch: Optional) = webSearch(webSearch.getOrNull()) + + /** + * Sets [Builder.webSearch] to an arbitrary JSON value. + * + * You should usually call [Builder.webSearch] with a well-typed [WebSearch] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun webSearch(webSearch: JsonField) = apply { body.webSearch(webSearch) } + + 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 [HostedToolPermissionUpdateParams]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): HostedToolPermissionUpdateParams = + HostedToolPermissionUpdateParams( + projectId, + body.build(), + additionalHeaders.build(), + additionalQueryParams.build(), + ) + } + + 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 + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val codeInterpreter: JsonField, + private val fileSearch: JsonField, + private val imageGeneration: JsonField, + private val mcp: JsonField, + private val webSearch: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("code_interpreter") + @ExcludeMissing + codeInterpreter: JsonField = JsonMissing.of(), + @JsonProperty("file_search") + @ExcludeMissing + fileSearch: JsonField = JsonMissing.of(), + @JsonProperty("image_generation") + @ExcludeMissing + imageGeneration: JsonField = JsonMissing.of(), + @JsonProperty("mcp") @ExcludeMissing mcp: JsonField = JsonMissing.of(), + @JsonProperty("web_search") + @ExcludeMissing + webSearch: JsonField = JsonMissing.of(), + ) : this(codeInterpreter, fileSearch, imageGeneration, mcp, webSearch, mutableMapOf()) + + /** + * The code interpreter permission update. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun codeInterpreter(): Optional = + codeInterpreter.getOptional("code_interpreter") + + /** + * The file search permission update. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun fileSearch(): Optional = fileSearch.getOptional("file_search") + + /** + * The image generation permission update. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun imageGeneration(): Optional = + imageGeneration.getOptional("image_generation") + + /** + * The MCP permission update. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun mcp(): Optional = mcp.getOptional("mcp") + + /** + * The web search permission update. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun webSearch(): Optional = webSearch.getOptional("web_search") + + /** + * Returns the raw JSON value of [codeInterpreter]. + * + * Unlike [codeInterpreter], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("code_interpreter") + @ExcludeMissing + fun _codeInterpreter(): JsonField = codeInterpreter + + /** + * Returns the raw JSON value of [fileSearch]. + * + * Unlike [fileSearch], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("file_search") + @ExcludeMissing + fun _fileSearch(): JsonField = fileSearch + + /** + * Returns the raw JSON value of [imageGeneration]. + * + * Unlike [imageGeneration], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("image_generation") + @ExcludeMissing + fun _imageGeneration(): JsonField = imageGeneration + + /** + * Returns the raw JSON value of [mcp]. + * + * Unlike [mcp], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("mcp") @ExcludeMissing fun _mcp(): JsonField = mcp + + /** + * Returns the raw JSON value of [webSearch]. + * + * Unlike [webSearch], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("web_search") + @ExcludeMissing + fun _webSearch(): JsonField = webSearch + + @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 codeInterpreter: JsonField = JsonMissing.of() + private var fileSearch: JsonField = JsonMissing.of() + private var imageGeneration: JsonField = JsonMissing.of() + private var mcp: JsonField = JsonMissing.of() + private var webSearch: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(body: Body) = apply { + codeInterpreter = body.codeInterpreter + fileSearch = body.fileSearch + imageGeneration = body.imageGeneration + mcp = body.mcp + webSearch = body.webSearch + additionalProperties = body.additionalProperties.toMutableMap() + } + + /** The code interpreter permission update. */ + fun codeInterpreter(codeInterpreter: CodeInterpreter?) = + codeInterpreter(JsonField.ofNullable(codeInterpreter)) + + /** Alias for calling [Builder.codeInterpreter] with `codeInterpreter.orElse(null)`. */ + fun codeInterpreter(codeInterpreter: Optional) = + codeInterpreter(codeInterpreter.getOrNull()) + + /** + * Sets [Builder.codeInterpreter] to an arbitrary JSON value. + * + * You should usually call [Builder.codeInterpreter] with a well-typed [CodeInterpreter] + * value instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun codeInterpreter(codeInterpreter: JsonField) = apply { + this.codeInterpreter = codeInterpreter + } + + /** The file search permission update. */ + fun fileSearch(fileSearch: FileSearch?) = fileSearch(JsonField.ofNullable(fileSearch)) + + /** Alias for calling [Builder.fileSearch] with `fileSearch.orElse(null)`. */ + fun fileSearch(fileSearch: Optional) = fileSearch(fileSearch.getOrNull()) + + /** + * Sets [Builder.fileSearch] to an arbitrary JSON value. + * + * You should usually call [Builder.fileSearch] with a well-typed [FileSearch] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun fileSearch(fileSearch: JsonField) = apply { + this.fileSearch = fileSearch + } + + /** The image generation permission update. */ + fun imageGeneration(imageGeneration: ImageGeneration?) = + imageGeneration(JsonField.ofNullable(imageGeneration)) + + /** Alias for calling [Builder.imageGeneration] with `imageGeneration.orElse(null)`. */ + fun imageGeneration(imageGeneration: Optional) = + imageGeneration(imageGeneration.getOrNull()) + + /** + * Sets [Builder.imageGeneration] to an arbitrary JSON value. + * + * You should usually call [Builder.imageGeneration] with a well-typed [ImageGeneration] + * value instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun imageGeneration(imageGeneration: JsonField) = apply { + this.imageGeneration = imageGeneration + } + + /** The MCP permission update. */ + fun mcp(mcp: Mcp?) = mcp(JsonField.ofNullable(mcp)) + + /** Alias for calling [Builder.mcp] with `mcp.orElse(null)`. */ + fun mcp(mcp: Optional) = mcp(mcp.getOrNull()) + + /** + * Sets [Builder.mcp] to an arbitrary JSON value. + * + * You should usually call [Builder.mcp] with a well-typed [Mcp] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun mcp(mcp: JsonField) = apply { this.mcp = mcp } + + /** The web search permission update. */ + fun webSearch(webSearch: WebSearch?) = webSearch(JsonField.ofNullable(webSearch)) + + /** Alias for calling [Builder.webSearch] with `webSearch.orElse(null)`. */ + fun webSearch(webSearch: Optional) = webSearch(webSearch.getOrNull()) + + /** + * Sets [Builder.webSearch] to an arbitrary JSON value. + * + * You should usually call [Builder.webSearch] with a well-typed [WebSearch] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun webSearch(webSearch: JsonField) = apply { this.webSearch = webSearch } + + 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( + codeInterpreter, + fileSearch, + imageGeneration, + mcp, + webSearch, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing fields. + * + * @throws OpenAIInvalidDataException if any value type in this object doesn't match its + * expected type. + */ + fun validate(): Body = apply { + if (validated) { + return@apply + } + + codeInterpreter().ifPresent { it.validate() } + fileSearch().ifPresent { it.validate() } + imageGeneration().ifPresent { it.validate() } + mcp().ifPresent { it.validate() } + webSearch().ifPresent { it.validate() } + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OpenAIInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (codeInterpreter.asKnown().getOrNull()?.validity() ?: 0) + + (fileSearch.asKnown().getOrNull()?.validity() ?: 0) + + (imageGeneration.asKnown().getOrNull()?.validity() ?: 0) + + (mcp.asKnown().getOrNull()?.validity() ?: 0) + + (webSearch.asKnown().getOrNull()?.validity() ?: 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Body && + codeInterpreter == other.codeInterpreter && + fileSearch == other.fileSearch && + imageGeneration == other.imageGeneration && + mcp == other.mcp && + webSearch == other.webSearch && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + codeInterpreter, + fileSearch, + imageGeneration, + mcp, + webSearch, + additionalProperties, + ) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Body{codeInterpreter=$codeInterpreter, fileSearch=$fileSearch, imageGeneration=$imageGeneration, mcp=$mcp, webSearch=$webSearch, additionalProperties=$additionalProperties}" + } + + /** The code interpreter permission update. */ + class CodeInterpreter + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val enabled: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("enabled") @ExcludeMissing enabled: JsonField = JsonMissing.of() + ) : this(enabled, mutableMapOf()) + + /** + * Whether to enable the hosted tool for the project. + * + * @throws OpenAIInvalidDataException 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 enabled(): Boolean = enabled.getRequired("enabled") + + /** + * Returns the raw JSON value of [enabled]. + * + * Unlike [enabled], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("enabled") @ExcludeMissing fun _enabled(): JsonField = enabled + + @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 [CodeInterpreter]. + * + * The following fields are required: + * ```java + * .enabled() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [CodeInterpreter]. */ + class Builder internal constructor() { + + private var enabled: JsonField? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(codeInterpreter: CodeInterpreter) = apply { + enabled = codeInterpreter.enabled + additionalProperties = codeInterpreter.additionalProperties.toMutableMap() + } + + /** Whether to enable the hosted tool for the project. */ + fun enabled(enabled: Boolean) = enabled(JsonField.of(enabled)) + + /** + * Sets [Builder.enabled] to an arbitrary JSON value. + * + * You should usually call [Builder.enabled] with a well-typed [Boolean] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun enabled(enabled: JsonField) = apply { this.enabled = enabled } + + 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 [CodeInterpreter]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .enabled() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): CodeInterpreter = + CodeInterpreter( + checkRequired("enabled", enabled), + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing fields. + * + * @throws OpenAIInvalidDataException if any value type in this object doesn't match its + * expected type. + */ + fun validate(): CodeInterpreter = apply { + if (validated) { + return@apply + } + + enabled() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OpenAIInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic internal fun validity(): Int = (if (enabled.asKnown().isPresent) 1 else 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is CodeInterpreter && + enabled == other.enabled && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(enabled, additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "CodeInterpreter{enabled=$enabled, additionalProperties=$additionalProperties}" + } + + /** The file search permission update. */ + class FileSearch + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val enabled: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("enabled") @ExcludeMissing enabled: JsonField = JsonMissing.of() + ) : this(enabled, mutableMapOf()) + + /** + * Whether to enable the hosted tool for the project. + * + * @throws OpenAIInvalidDataException 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 enabled(): Boolean = enabled.getRequired("enabled") + + /** + * Returns the raw JSON value of [enabled]. + * + * Unlike [enabled], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("enabled") @ExcludeMissing fun _enabled(): JsonField = enabled + + @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 [FileSearch]. + * + * The following fields are required: + * ```java + * .enabled() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [FileSearch]. */ + class Builder internal constructor() { + + private var enabled: JsonField? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(fileSearch: FileSearch) = apply { + enabled = fileSearch.enabled + additionalProperties = fileSearch.additionalProperties.toMutableMap() + } + + /** Whether to enable the hosted tool for the project. */ + fun enabled(enabled: Boolean) = enabled(JsonField.of(enabled)) + + /** + * Sets [Builder.enabled] to an arbitrary JSON value. + * + * You should usually call [Builder.enabled] with a well-typed [Boolean] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun enabled(enabled: JsonField) = apply { this.enabled = enabled } + + 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 [FileSearch]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .enabled() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): FileSearch = + FileSearch(checkRequired("enabled", enabled), additionalProperties.toMutableMap()) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing fields. + * + * @throws OpenAIInvalidDataException if any value type in this object doesn't match its + * expected type. + */ + fun validate(): FileSearch = apply { + if (validated) { + return@apply + } + + enabled() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OpenAIInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic internal fun validity(): Int = (if (enabled.asKnown().isPresent) 1 else 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is FileSearch && + enabled == other.enabled && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(enabled, additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "FileSearch{enabled=$enabled, additionalProperties=$additionalProperties}" + } + + /** The image generation permission update. */ + class ImageGeneration + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val enabled: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("enabled") @ExcludeMissing enabled: JsonField = JsonMissing.of() + ) : this(enabled, mutableMapOf()) + + /** + * Whether to enable the hosted tool for the project. + * + * @throws OpenAIInvalidDataException 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 enabled(): Boolean = enabled.getRequired("enabled") + + /** + * Returns the raw JSON value of [enabled]. + * + * Unlike [enabled], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("enabled") @ExcludeMissing fun _enabled(): JsonField = enabled + + @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 [ImageGeneration]. + * + * The following fields are required: + * ```java + * .enabled() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [ImageGeneration]. */ + class Builder internal constructor() { + + private var enabled: JsonField? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(imageGeneration: ImageGeneration) = apply { + enabled = imageGeneration.enabled + additionalProperties = imageGeneration.additionalProperties.toMutableMap() + } + + /** Whether to enable the hosted tool for the project. */ + fun enabled(enabled: Boolean) = enabled(JsonField.of(enabled)) + + /** + * Sets [Builder.enabled] to an arbitrary JSON value. + * + * You should usually call [Builder.enabled] with a well-typed [Boolean] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun enabled(enabled: JsonField) = apply { this.enabled = enabled } + + 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 [ImageGeneration]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .enabled() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): ImageGeneration = + ImageGeneration( + checkRequired("enabled", enabled), + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing fields. + * + * @throws OpenAIInvalidDataException if any value type in this object doesn't match its + * expected type. + */ + fun validate(): ImageGeneration = apply { + if (validated) { + return@apply + } + + enabled() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OpenAIInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic internal fun validity(): Int = (if (enabled.asKnown().isPresent) 1 else 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is ImageGeneration && + enabled == other.enabled && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(enabled, additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "ImageGeneration{enabled=$enabled, additionalProperties=$additionalProperties}" + } + + /** The MCP permission update. */ + class Mcp + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val enabled: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("enabled") @ExcludeMissing enabled: JsonField = JsonMissing.of() + ) : this(enabled, mutableMapOf()) + + /** + * Whether to enable the hosted tool for the project. + * + * @throws OpenAIInvalidDataException 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 enabled(): Boolean = enabled.getRequired("enabled") + + /** + * Returns the raw JSON value of [enabled]. + * + * Unlike [enabled], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("enabled") @ExcludeMissing fun _enabled(): JsonField = enabled + + @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 [Mcp]. + * + * The following fields are required: + * ```java + * .enabled() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [Mcp]. */ + class Builder internal constructor() { + + private var enabled: JsonField? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(mcp: Mcp) = apply { + enabled = mcp.enabled + additionalProperties = mcp.additionalProperties.toMutableMap() + } + + /** Whether to enable the hosted tool for the project. */ + fun enabled(enabled: Boolean) = enabled(JsonField.of(enabled)) + + /** + * Sets [Builder.enabled] to an arbitrary JSON value. + * + * You should usually call [Builder.enabled] with a well-typed [Boolean] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun enabled(enabled: JsonField) = apply { this.enabled = enabled } + + 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 [Mcp]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .enabled() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): Mcp = + Mcp(checkRequired("enabled", enabled), additionalProperties.toMutableMap()) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing fields. + * + * @throws OpenAIInvalidDataException if any value type in this object doesn't match its + * expected type. + */ + fun validate(): Mcp = apply { + if (validated) { + return@apply + } + + enabled() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OpenAIInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic internal fun validity(): Int = (if (enabled.asKnown().isPresent) 1 else 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Mcp && + enabled == other.enabled && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(enabled, additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Mcp{enabled=$enabled, additionalProperties=$additionalProperties}" + } + + /** The web search permission update. */ + class WebSearch + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val enabled: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("enabled") @ExcludeMissing enabled: JsonField = JsonMissing.of() + ) : this(enabled, mutableMapOf()) + + /** + * Whether to enable the hosted tool for the project. + * + * @throws OpenAIInvalidDataException 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 enabled(): Boolean = enabled.getRequired("enabled") + + /** + * Returns the raw JSON value of [enabled]. + * + * Unlike [enabled], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("enabled") @ExcludeMissing fun _enabled(): JsonField = enabled + + @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 [WebSearch]. + * + * The following fields are required: + * ```java + * .enabled() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [WebSearch]. */ + class Builder internal constructor() { + + private var enabled: JsonField? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(webSearch: WebSearch) = apply { + enabled = webSearch.enabled + additionalProperties = webSearch.additionalProperties.toMutableMap() + } + + /** Whether to enable the hosted tool for the project. */ + fun enabled(enabled: Boolean) = enabled(JsonField.of(enabled)) + + /** + * Sets [Builder.enabled] to an arbitrary JSON value. + * + * You should usually call [Builder.enabled] with a well-typed [Boolean] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun enabled(enabled: JsonField) = apply { this.enabled = enabled } + + 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 [WebSearch]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .enabled() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): WebSearch = + WebSearch(checkRequired("enabled", enabled), additionalProperties.toMutableMap()) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing fields. + * + * @throws OpenAIInvalidDataException if any value type in this object doesn't match its + * expected type. + */ + fun validate(): WebSearch = apply { + if (validated) { + return@apply + } + + enabled() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OpenAIInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic internal fun validity(): Int = (if (enabled.asKnown().isPresent) 1 else 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is WebSearch && + enabled == other.enabled && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(enabled, additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "WebSearch{enabled=$enabled, additionalProperties=$additionalProperties}" + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is HostedToolPermissionUpdateParams && + projectId == other.projectId && + body == other.body && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams + } + + override fun hashCode(): Int = + Objects.hash(projectId, body, additionalHeaders, additionalQueryParams) + + override fun toString() = + "HostedToolPermissionUpdateParams{projectId=$projectId, body=$body, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" +} diff --git a/openai-java-core/src/main/kotlin/com/openai/models/admin/organization/projects/hostedtoolpermissions/ProjectHostedToolPermissions.kt b/openai-java-core/src/main/kotlin/com/openai/models/admin/organization/projects/hostedtoolpermissions/ProjectHostedToolPermissions.kt new file mode 100644 index 000000000..a2c0ad08f --- /dev/null +++ b/openai-java-core/src/main/kotlin/com/openai/models/admin/organization/projects/hostedtoolpermissions/ProjectHostedToolPermissions.kt @@ -0,0 +1,1198 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.models.admin.organization.projects.hostedtoolpermissions + +import com.fasterxml.jackson.annotation.JsonAnyGetter +import com.fasterxml.jackson.annotation.JsonAnySetter +import com.fasterxml.jackson.annotation.JsonCreator +import com.fasterxml.jackson.annotation.JsonProperty +import com.openai.core.ExcludeMissing +import com.openai.core.JsonField +import com.openai.core.JsonMissing +import com.openai.core.JsonValue +import com.openai.core.checkRequired +import com.openai.errors.OpenAIInvalidDataException +import java.util.Collections +import java.util.Objects +import kotlin.jvm.optionals.getOrNull + +/** Represents hosted tool permissions for a project. */ +class ProjectHostedToolPermissions +@JsonCreator(mode = JsonCreator.Mode.DISABLED) +private constructor( + private val codeInterpreter: JsonField, + private val fileSearch: JsonField, + private val imageGeneration: JsonField, + private val mcp: JsonField, + private val webSearch: JsonField, + private val additionalProperties: MutableMap, +) { + + @JsonCreator + private constructor( + @JsonProperty("code_interpreter") + @ExcludeMissing + codeInterpreter: JsonField = JsonMissing.of(), + @JsonProperty("file_search") + @ExcludeMissing + fileSearch: JsonField = JsonMissing.of(), + @JsonProperty("image_generation") + @ExcludeMissing + imageGeneration: JsonField = JsonMissing.of(), + @JsonProperty("mcp") @ExcludeMissing mcp: JsonField = JsonMissing.of(), + @JsonProperty("web_search") + @ExcludeMissing + webSearch: JsonField = JsonMissing.of(), + ) : this(codeInterpreter, fileSearch, imageGeneration, mcp, webSearch, mutableMapOf()) + + /** + * Permission state for a single hosted tool on a project. + * + * @throws OpenAIInvalidDataException 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 codeInterpreter(): CodeInterpreter = codeInterpreter.getRequired("code_interpreter") + + /** + * Permission state for a single hosted tool on a project. + * + * @throws OpenAIInvalidDataException 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 fileSearch(): FileSearch = fileSearch.getRequired("file_search") + + /** + * Permission state for a single hosted tool on a project. + * + * @throws OpenAIInvalidDataException 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 imageGeneration(): ImageGeneration = imageGeneration.getRequired("image_generation") + + /** + * Permission state for a single hosted tool on a project. + * + * @throws OpenAIInvalidDataException 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 mcp(): Mcp = mcp.getRequired("mcp") + + /** + * Permission state for a single hosted tool on a project. + * + * @throws OpenAIInvalidDataException 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 webSearch(): WebSearch = webSearch.getRequired("web_search") + + /** + * Returns the raw JSON value of [codeInterpreter]. + * + * Unlike [codeInterpreter], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("code_interpreter") + @ExcludeMissing + fun _codeInterpreter(): JsonField = codeInterpreter + + /** + * Returns the raw JSON value of [fileSearch]. + * + * Unlike [fileSearch], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("file_search") + @ExcludeMissing + fun _fileSearch(): JsonField = fileSearch + + /** + * Returns the raw JSON value of [imageGeneration]. + * + * Unlike [imageGeneration], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("image_generation") + @ExcludeMissing + fun _imageGeneration(): JsonField = imageGeneration + + /** + * Returns the raw JSON value of [mcp]. + * + * Unlike [mcp], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("mcp") @ExcludeMissing fun _mcp(): JsonField = mcp + + /** + * Returns the raw JSON value of [webSearch]. + * + * Unlike [webSearch], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("web_search") @ExcludeMissing fun _webSearch(): JsonField = webSearch + + @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 [ProjectHostedToolPermissions]. + * + * The following fields are required: + * ```java + * .codeInterpreter() + * .fileSearch() + * .imageGeneration() + * .mcp() + * .webSearch() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [ProjectHostedToolPermissions]. */ + class Builder internal constructor() { + + private var codeInterpreter: JsonField? = null + private var fileSearch: JsonField? = null + private var imageGeneration: JsonField? = null + private var mcp: JsonField? = null + private var webSearch: JsonField? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(projectHostedToolPermissions: ProjectHostedToolPermissions) = apply { + codeInterpreter = projectHostedToolPermissions.codeInterpreter + fileSearch = projectHostedToolPermissions.fileSearch + imageGeneration = projectHostedToolPermissions.imageGeneration + mcp = projectHostedToolPermissions.mcp + webSearch = projectHostedToolPermissions.webSearch + additionalProperties = projectHostedToolPermissions.additionalProperties.toMutableMap() + } + + /** Permission state for a single hosted tool on a project. */ + fun codeInterpreter(codeInterpreter: CodeInterpreter) = + codeInterpreter(JsonField.of(codeInterpreter)) + + /** + * Sets [Builder.codeInterpreter] to an arbitrary JSON value. + * + * You should usually call [Builder.codeInterpreter] with a well-typed [CodeInterpreter] + * value instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun codeInterpreter(codeInterpreter: JsonField) = apply { + this.codeInterpreter = codeInterpreter + } + + /** Permission state for a single hosted tool on a project. */ + fun fileSearch(fileSearch: FileSearch) = fileSearch(JsonField.of(fileSearch)) + + /** + * Sets [Builder.fileSearch] to an arbitrary JSON value. + * + * You should usually call [Builder.fileSearch] with a well-typed [FileSearch] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun fileSearch(fileSearch: JsonField) = apply { this.fileSearch = fileSearch } + + /** Permission state for a single hosted tool on a project. */ + fun imageGeneration(imageGeneration: ImageGeneration) = + imageGeneration(JsonField.of(imageGeneration)) + + /** + * Sets [Builder.imageGeneration] to an arbitrary JSON value. + * + * You should usually call [Builder.imageGeneration] with a well-typed [ImageGeneration] + * value instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun imageGeneration(imageGeneration: JsonField) = apply { + this.imageGeneration = imageGeneration + } + + /** Permission state for a single hosted tool on a project. */ + fun mcp(mcp: Mcp) = mcp(JsonField.of(mcp)) + + /** + * Sets [Builder.mcp] to an arbitrary JSON value. + * + * You should usually call [Builder.mcp] with a well-typed [Mcp] value instead. This method + * is primarily for setting the field to an undocumented or not yet supported value. + */ + fun mcp(mcp: JsonField) = apply { this.mcp = mcp } + + /** Permission state for a single hosted tool on a project. */ + fun webSearch(webSearch: WebSearch) = webSearch(JsonField.of(webSearch)) + + /** + * Sets [Builder.webSearch] to an arbitrary JSON value. + * + * You should usually call [Builder.webSearch] with a well-typed [WebSearch] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun webSearch(webSearch: JsonField) = apply { this.webSearch = webSearch } + + 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 [ProjectHostedToolPermissions]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .codeInterpreter() + * .fileSearch() + * .imageGeneration() + * .mcp() + * .webSearch() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): ProjectHostedToolPermissions = + ProjectHostedToolPermissions( + checkRequired("codeInterpreter", codeInterpreter), + checkRequired("fileSearch", fileSearch), + checkRequired("imageGeneration", imageGeneration), + checkRequired("mcp", mcp), + checkRequired("webSearch", webSearch), + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected types recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing fields. + * + * @throws OpenAIInvalidDataException if any value type in this object doesn't match its + * expected type. + */ + fun validate(): ProjectHostedToolPermissions = apply { + if (validated) { + return@apply + } + + codeInterpreter().validate() + fileSearch().validate() + imageGeneration().validate() + mcp().validate() + webSearch().validate() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OpenAIInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (codeInterpreter.asKnown().getOrNull()?.validity() ?: 0) + + (fileSearch.asKnown().getOrNull()?.validity() ?: 0) + + (imageGeneration.asKnown().getOrNull()?.validity() ?: 0) + + (mcp.asKnown().getOrNull()?.validity() ?: 0) + + (webSearch.asKnown().getOrNull()?.validity() ?: 0) + + /** Permission state for a single hosted tool on a project. */ + class CodeInterpreter + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val enabled: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("enabled") @ExcludeMissing enabled: JsonField = JsonMissing.of() + ) : this(enabled, mutableMapOf()) + + /** + * Whether the hosted tool is enabled for the project. + * + * @throws OpenAIInvalidDataException 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 enabled(): Boolean = enabled.getRequired("enabled") + + /** + * Returns the raw JSON value of [enabled]. + * + * Unlike [enabled], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("enabled") @ExcludeMissing fun _enabled(): JsonField = enabled + + @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 [CodeInterpreter]. + * + * The following fields are required: + * ```java + * .enabled() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [CodeInterpreter]. */ + class Builder internal constructor() { + + private var enabled: JsonField? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(codeInterpreter: CodeInterpreter) = apply { + enabled = codeInterpreter.enabled + additionalProperties = codeInterpreter.additionalProperties.toMutableMap() + } + + /** Whether the hosted tool is enabled for the project. */ + fun enabled(enabled: Boolean) = enabled(JsonField.of(enabled)) + + /** + * Sets [Builder.enabled] to an arbitrary JSON value. + * + * You should usually call [Builder.enabled] with a well-typed [Boolean] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun enabled(enabled: JsonField) = apply { this.enabled = enabled } + + 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 [CodeInterpreter]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .enabled() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): CodeInterpreter = + CodeInterpreter( + checkRequired("enabled", enabled), + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing fields. + * + * @throws OpenAIInvalidDataException if any value type in this object doesn't match its + * expected type. + */ + fun validate(): CodeInterpreter = apply { + if (validated) { + return@apply + } + + enabled() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OpenAIInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic internal fun validity(): Int = (if (enabled.asKnown().isPresent) 1 else 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is CodeInterpreter && + enabled == other.enabled && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(enabled, additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "CodeInterpreter{enabled=$enabled, additionalProperties=$additionalProperties}" + } + + /** Permission state for a single hosted tool on a project. */ + class FileSearch + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val enabled: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("enabled") @ExcludeMissing enabled: JsonField = JsonMissing.of() + ) : this(enabled, mutableMapOf()) + + /** + * Whether the hosted tool is enabled for the project. + * + * @throws OpenAIInvalidDataException 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 enabled(): Boolean = enabled.getRequired("enabled") + + /** + * Returns the raw JSON value of [enabled]. + * + * Unlike [enabled], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("enabled") @ExcludeMissing fun _enabled(): JsonField = enabled + + @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 [FileSearch]. + * + * The following fields are required: + * ```java + * .enabled() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [FileSearch]. */ + class Builder internal constructor() { + + private var enabled: JsonField? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(fileSearch: FileSearch) = apply { + enabled = fileSearch.enabled + additionalProperties = fileSearch.additionalProperties.toMutableMap() + } + + /** Whether the hosted tool is enabled for the project. */ + fun enabled(enabled: Boolean) = enabled(JsonField.of(enabled)) + + /** + * Sets [Builder.enabled] to an arbitrary JSON value. + * + * You should usually call [Builder.enabled] with a well-typed [Boolean] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun enabled(enabled: JsonField) = apply { this.enabled = enabled } + + 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 [FileSearch]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .enabled() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): FileSearch = + FileSearch(checkRequired("enabled", enabled), additionalProperties.toMutableMap()) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing fields. + * + * @throws OpenAIInvalidDataException if any value type in this object doesn't match its + * expected type. + */ + fun validate(): FileSearch = apply { + if (validated) { + return@apply + } + + enabled() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OpenAIInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic internal fun validity(): Int = (if (enabled.asKnown().isPresent) 1 else 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is FileSearch && + enabled == other.enabled && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(enabled, additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "FileSearch{enabled=$enabled, additionalProperties=$additionalProperties}" + } + + /** Permission state for a single hosted tool on a project. */ + class ImageGeneration + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val enabled: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("enabled") @ExcludeMissing enabled: JsonField = JsonMissing.of() + ) : this(enabled, mutableMapOf()) + + /** + * Whether the hosted tool is enabled for the project. + * + * @throws OpenAIInvalidDataException 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 enabled(): Boolean = enabled.getRequired("enabled") + + /** + * Returns the raw JSON value of [enabled]. + * + * Unlike [enabled], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("enabled") @ExcludeMissing fun _enabled(): JsonField = enabled + + @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 [ImageGeneration]. + * + * The following fields are required: + * ```java + * .enabled() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [ImageGeneration]. */ + class Builder internal constructor() { + + private var enabled: JsonField? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(imageGeneration: ImageGeneration) = apply { + enabled = imageGeneration.enabled + additionalProperties = imageGeneration.additionalProperties.toMutableMap() + } + + /** Whether the hosted tool is enabled for the project. */ + fun enabled(enabled: Boolean) = enabled(JsonField.of(enabled)) + + /** + * Sets [Builder.enabled] to an arbitrary JSON value. + * + * You should usually call [Builder.enabled] with a well-typed [Boolean] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun enabled(enabled: JsonField) = apply { this.enabled = enabled } + + 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 [ImageGeneration]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .enabled() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): ImageGeneration = + ImageGeneration( + checkRequired("enabled", enabled), + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing fields. + * + * @throws OpenAIInvalidDataException if any value type in this object doesn't match its + * expected type. + */ + fun validate(): ImageGeneration = apply { + if (validated) { + return@apply + } + + enabled() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OpenAIInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic internal fun validity(): Int = (if (enabled.asKnown().isPresent) 1 else 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is ImageGeneration && + enabled == other.enabled && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(enabled, additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "ImageGeneration{enabled=$enabled, additionalProperties=$additionalProperties}" + } + + /** Permission state for a single hosted tool on a project. */ + class Mcp + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val enabled: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("enabled") @ExcludeMissing enabled: JsonField = JsonMissing.of() + ) : this(enabled, mutableMapOf()) + + /** + * Whether the hosted tool is enabled for the project. + * + * @throws OpenAIInvalidDataException 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 enabled(): Boolean = enabled.getRequired("enabled") + + /** + * Returns the raw JSON value of [enabled]. + * + * Unlike [enabled], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("enabled") @ExcludeMissing fun _enabled(): JsonField = enabled + + @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 [Mcp]. + * + * The following fields are required: + * ```java + * .enabled() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [Mcp]. */ + class Builder internal constructor() { + + private var enabled: JsonField? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(mcp: Mcp) = apply { + enabled = mcp.enabled + additionalProperties = mcp.additionalProperties.toMutableMap() + } + + /** Whether the hosted tool is enabled for the project. */ + fun enabled(enabled: Boolean) = enabled(JsonField.of(enabled)) + + /** + * Sets [Builder.enabled] to an arbitrary JSON value. + * + * You should usually call [Builder.enabled] with a well-typed [Boolean] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun enabled(enabled: JsonField) = apply { this.enabled = enabled } + + 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 [Mcp]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .enabled() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): Mcp = + Mcp(checkRequired("enabled", enabled), additionalProperties.toMutableMap()) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing fields. + * + * @throws OpenAIInvalidDataException if any value type in this object doesn't match its + * expected type. + */ + fun validate(): Mcp = apply { + if (validated) { + return@apply + } + + enabled() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OpenAIInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic internal fun validity(): Int = (if (enabled.asKnown().isPresent) 1 else 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Mcp && + enabled == other.enabled && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(enabled, additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Mcp{enabled=$enabled, additionalProperties=$additionalProperties}" + } + + /** Permission state for a single hosted tool on a project. */ + class WebSearch + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val enabled: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("enabled") @ExcludeMissing enabled: JsonField = JsonMissing.of() + ) : this(enabled, mutableMapOf()) + + /** + * Whether the hosted tool is enabled for the project. + * + * @throws OpenAIInvalidDataException 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 enabled(): Boolean = enabled.getRequired("enabled") + + /** + * Returns the raw JSON value of [enabled]. + * + * Unlike [enabled], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("enabled") @ExcludeMissing fun _enabled(): JsonField = enabled + + @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 [WebSearch]. + * + * The following fields are required: + * ```java + * .enabled() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [WebSearch]. */ + class Builder internal constructor() { + + private var enabled: JsonField? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(webSearch: WebSearch) = apply { + enabled = webSearch.enabled + additionalProperties = webSearch.additionalProperties.toMutableMap() + } + + /** Whether the hosted tool is enabled for the project. */ + fun enabled(enabled: Boolean) = enabled(JsonField.of(enabled)) + + /** + * Sets [Builder.enabled] to an arbitrary JSON value. + * + * You should usually call [Builder.enabled] with a well-typed [Boolean] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun enabled(enabled: JsonField) = apply { this.enabled = enabled } + + 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 [WebSearch]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .enabled() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): WebSearch = + WebSearch(checkRequired("enabled", enabled), additionalProperties.toMutableMap()) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing fields. + * + * @throws OpenAIInvalidDataException if any value type in this object doesn't match its + * expected type. + */ + fun validate(): WebSearch = apply { + if (validated) { + return@apply + } + + enabled() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OpenAIInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic internal fun validity(): Int = (if (enabled.asKnown().isPresent) 1 else 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is WebSearch && + enabled == other.enabled && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(enabled, additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "WebSearch{enabled=$enabled, additionalProperties=$additionalProperties}" + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is ProjectHostedToolPermissions && + codeInterpreter == other.codeInterpreter && + fileSearch == other.fileSearch && + imageGeneration == other.imageGeneration && + mcp == other.mcp && + webSearch == other.webSearch && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + codeInterpreter, + fileSearch, + imageGeneration, + mcp, + webSearch, + additionalProperties, + ) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "ProjectHostedToolPermissions{codeInterpreter=$codeInterpreter, fileSearch=$fileSearch, imageGeneration=$imageGeneration, mcp=$mcp, webSearch=$webSearch, additionalProperties=$additionalProperties}" +} diff --git a/openai-java-core/src/main/kotlin/com/openai/models/admin/organization/projects/modelpermissions/ModelPermissionDeleteParams.kt b/openai-java-core/src/main/kotlin/com/openai/models/admin/organization/projects/modelpermissions/ModelPermissionDeleteParams.kt new file mode 100644 index 000000000..e44ad55e7 --- /dev/null +++ b/openai-java-core/src/main/kotlin/com/openai/models/admin/organization/projects/modelpermissions/ModelPermissionDeleteParams.kt @@ -0,0 +1,232 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.models.admin.organization.projects.modelpermissions + +import com.openai.core.JsonValue +import com.openai.core.Params +import com.openai.core.http.Headers +import com.openai.core.http.QueryParams +import com.openai.core.toImmutable +import java.util.Objects +import java.util.Optional +import kotlin.jvm.optionals.getOrNull + +/** Deletes model permissions for a project. */ +class ModelPermissionDeleteParams +private constructor( + private val projectId: String?, + private val additionalHeaders: Headers, + private val additionalQueryParams: QueryParams, + private val additionalBodyProperties: Map, +) : Params { + + fun projectId(): Optional = Optional.ofNullable(projectId) + + /** Additional body properties to send with the request. */ + fun _additionalBodyProperties(): Map = additionalBodyProperties + + /** Additional headers to send with the request. */ + fun _additionalHeaders(): Headers = additionalHeaders + + /** Additional query param to send with the request. */ + fun _additionalQueryParams(): QueryParams = additionalQueryParams + + fun toBuilder() = Builder().from(this) + + companion object { + + @JvmStatic fun none(): ModelPermissionDeleteParams = builder().build() + + /** + * Returns a mutable builder for constructing an instance of [ModelPermissionDeleteParams]. + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [ModelPermissionDeleteParams]. */ + class Builder internal constructor() { + + private var projectId: String? = null + private var additionalHeaders: Headers.Builder = Headers.builder() + private var additionalQueryParams: QueryParams.Builder = QueryParams.builder() + private var additionalBodyProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(modelPermissionDeleteParams: ModelPermissionDeleteParams) = apply { + projectId = modelPermissionDeleteParams.projectId + additionalHeaders = modelPermissionDeleteParams.additionalHeaders.toBuilder() + additionalQueryParams = modelPermissionDeleteParams.additionalQueryParams.toBuilder() + additionalBodyProperties = + modelPermissionDeleteParams.additionalBodyProperties.toMutableMap() + } + + fun projectId(projectId: String?) = apply { this.projectId = projectId } + + /** Alias for calling [Builder.projectId] with `projectId.orElse(null)`. */ + fun projectId(projectId: Optional) = projectId(projectId.getOrNull()) + + 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) + } + + fun additionalBodyProperties(additionalBodyProperties: Map) = apply { + this.additionalBodyProperties.clear() + putAllAdditionalBodyProperties(additionalBodyProperties) + } + + fun putAdditionalBodyProperty(key: String, value: JsonValue) = apply { + additionalBodyProperties.put(key, value) + } + + fun putAllAdditionalBodyProperties(additionalBodyProperties: Map) = + apply { + this.additionalBodyProperties.putAll(additionalBodyProperties) + } + + fun removeAdditionalBodyProperty(key: String) = apply { + additionalBodyProperties.remove(key) + } + + fun removeAllAdditionalBodyProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalBodyProperty) + } + + /** + * Returns an immutable instance of [ModelPermissionDeleteParams]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): ModelPermissionDeleteParams = + ModelPermissionDeleteParams( + projectId, + additionalHeaders.build(), + additionalQueryParams.build(), + additionalBodyProperties.toImmutable(), + ) + } + + 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 + } + + return other is ModelPermissionDeleteParams && + projectId == other.projectId && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams && + additionalBodyProperties == other.additionalBodyProperties + } + + override fun hashCode(): Int = + Objects.hash(projectId, additionalHeaders, additionalQueryParams, additionalBodyProperties) + + override fun toString() = + "ModelPermissionDeleteParams{projectId=$projectId, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams, additionalBodyProperties=$additionalBodyProperties}" +} diff --git a/openai-java-core/src/main/kotlin/com/openai/models/admin/organization/projects/modelpermissions/ModelPermissionRetrieveParams.kt b/openai-java-core/src/main/kotlin/com/openai/models/admin/organization/projects/modelpermissions/ModelPermissionRetrieveParams.kt new file mode 100644 index 000000000..2b596a58a --- /dev/null +++ b/openai-java-core/src/main/kotlin/com/openai/models/admin/organization/projects/modelpermissions/ModelPermissionRetrieveParams.kt @@ -0,0 +1,196 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.models.admin.organization.projects.modelpermissions + +import com.openai.core.Params +import com.openai.core.http.Headers +import com.openai.core.http.QueryParams +import java.util.Objects +import java.util.Optional +import kotlin.jvm.optionals.getOrNull + +/** Returns model permissions for a project. */ +class ModelPermissionRetrieveParams +private constructor( + private val projectId: String?, + private val additionalHeaders: Headers, + private val additionalQueryParams: QueryParams, +) : Params { + + fun projectId(): Optional = Optional.ofNullable(projectId) + + /** Additional headers to send with the request. */ + fun _additionalHeaders(): Headers = additionalHeaders + + /** Additional query param to send with the request. */ + fun _additionalQueryParams(): QueryParams = additionalQueryParams + + fun toBuilder() = Builder().from(this) + + companion object { + + @JvmStatic fun none(): ModelPermissionRetrieveParams = builder().build() + + /** + * Returns a mutable builder for constructing an instance of + * [ModelPermissionRetrieveParams]. + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [ModelPermissionRetrieveParams]. */ + class Builder internal constructor() { + + private var projectId: String? = null + private var additionalHeaders: Headers.Builder = Headers.builder() + private var additionalQueryParams: QueryParams.Builder = QueryParams.builder() + + @JvmSynthetic + internal fun from(modelPermissionRetrieveParams: ModelPermissionRetrieveParams) = apply { + projectId = modelPermissionRetrieveParams.projectId + additionalHeaders = modelPermissionRetrieveParams.additionalHeaders.toBuilder() + additionalQueryParams = modelPermissionRetrieveParams.additionalQueryParams.toBuilder() + } + + fun projectId(projectId: String?) = apply { this.projectId = projectId } + + /** Alias for calling [Builder.projectId] with `projectId.orElse(null)`. */ + fun projectId(projectId: Optional) = projectId(projectId.getOrNull()) + + 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 [ModelPermissionRetrieveParams]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): ModelPermissionRetrieveParams = + ModelPermissionRetrieveParams( + projectId, + additionalHeaders.build(), + additionalQueryParams.build(), + ) + } + + 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 + } + + return other is ModelPermissionRetrieveParams && + projectId == other.projectId && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams + } + + override fun hashCode(): Int = Objects.hash(projectId, additionalHeaders, additionalQueryParams) + + override fun toString() = + "ModelPermissionRetrieveParams{projectId=$projectId, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" +} diff --git a/openai-java-core/src/main/kotlin/com/openai/models/admin/organization/projects/modelpermissions/ModelPermissionUpdateParams.kt b/openai-java-core/src/main/kotlin/com/openai/models/admin/organization/projects/modelpermissions/ModelPermissionUpdateParams.kt new file mode 100644 index 000000000..83e13e55d --- /dev/null +++ b/openai-java-core/src/main/kotlin/com/openai/models/admin/organization/projects/modelpermissions/ModelPermissionUpdateParams.kt @@ -0,0 +1,680 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.models.admin.organization.projects.modelpermissions + +import com.fasterxml.jackson.annotation.JsonAnyGetter +import com.fasterxml.jackson.annotation.JsonAnySetter +import com.fasterxml.jackson.annotation.JsonCreator +import com.fasterxml.jackson.annotation.JsonProperty +import com.openai.core.Enum +import com.openai.core.ExcludeMissing +import com.openai.core.JsonField +import com.openai.core.JsonMissing +import com.openai.core.JsonValue +import com.openai.core.Params +import com.openai.core.checkKnown +import com.openai.core.checkRequired +import com.openai.core.http.Headers +import com.openai.core.http.QueryParams +import com.openai.core.toImmutable +import com.openai.errors.OpenAIInvalidDataException +import java.util.Collections +import java.util.Objects +import java.util.Optional +import kotlin.jvm.optionals.getOrNull + +/** Updates model permissions for a project. */ +class ModelPermissionUpdateParams +private constructor( + private val projectId: String?, + private val body: Body, + private val additionalHeaders: Headers, + private val additionalQueryParams: QueryParams, +) : Params { + + fun projectId(): Optional = Optional.ofNullable(projectId) + + /** + * The model permissions mode to apply. + * + * @throws OpenAIInvalidDataException 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 mode(): Mode = body.mode() + + /** + * The model IDs included in this permissions policy. + * + * @throws OpenAIInvalidDataException 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 modelIds(): List = body.modelIds() + + /** + * Returns the raw JSON value of [mode]. + * + * Unlike [mode], this method doesn't throw if the JSON field has an unexpected type. + */ + fun _mode(): JsonField = body._mode() + + /** + * Returns the raw JSON value of [modelIds]. + * + * Unlike [modelIds], this method doesn't throw if the JSON field has an unexpected type. + */ + fun _modelIds(): JsonField> = body._modelIds() + + fun _additionalBodyProperties(): Map = body._additionalProperties() + + /** Additional headers to send with the request. */ + fun _additionalHeaders(): Headers = additionalHeaders + + /** Additional query param to send with the request. */ + fun _additionalQueryParams(): QueryParams = additionalQueryParams + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of [ModelPermissionUpdateParams]. + * + * The following fields are required: + * ```java + * .mode() + * .modelIds() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [ModelPermissionUpdateParams]. */ + 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 from(modelPermissionUpdateParams: ModelPermissionUpdateParams) = apply { + projectId = modelPermissionUpdateParams.projectId + body = modelPermissionUpdateParams.body.toBuilder() + additionalHeaders = modelPermissionUpdateParams.additionalHeaders.toBuilder() + additionalQueryParams = modelPermissionUpdateParams.additionalQueryParams.toBuilder() + } + + fun projectId(projectId: String?) = apply { this.projectId = projectId } + + /** Alias for calling [Builder.projectId] with `projectId.orElse(null)`. */ + fun projectId(projectId: Optional) = projectId(projectId.getOrNull()) + + /** + * Sets the entire request body. + * + * This is generally only useful if you are already constructing the body separately. + * Otherwise, it's more convenient to use the top-level setters instead: + * - [mode] + * - [modelIds] + */ + fun body(body: Body) = apply { this.body = body.toBuilder() } + + /** The model permissions mode to apply. */ + fun mode(mode: Mode) = apply { body.mode(mode) } + + /** + * 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) } + + /** The model IDs included in this permissions policy. */ + fun modelIds(modelIds: List) = apply { body.modelIds(modelIds) } + + /** + * Sets [Builder.modelIds] to an arbitrary JSON value. + * + * You should usually call [Builder.modelIds] with a well-typed `List` value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun modelIds(modelIds: JsonField>) = apply { body.modelIds(modelIds) } + + /** + * Adds a single [String] to [modelIds]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addModelId(modelId: String) = apply { body.addModelId(modelId) } + + 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 [ModelPermissionUpdateParams]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .mode() + * .modelIds() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): ModelPermissionUpdateParams = + ModelPermissionUpdateParams( + projectId, + body.build(), + additionalHeaders.build(), + additionalQueryParams.build(), + ) + } + + 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 + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val mode: JsonField, + private val modelIds: JsonField>, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("mode") @ExcludeMissing mode: JsonField = JsonMissing.of(), + @JsonProperty("model_ids") + @ExcludeMissing + modelIds: JsonField> = JsonMissing.of(), + ) : this(mode, modelIds, mutableMapOf()) + + /** + * The model permissions mode to apply. + * + * @throws OpenAIInvalidDataException 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 mode(): Mode = mode.getRequired("mode") + + /** + * The model IDs included in this permissions policy. + * + * @throws OpenAIInvalidDataException 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 modelIds(): List = modelIds.getRequired("model_ids") + + /** + * 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 [modelIds]. + * + * Unlike [modelIds], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("model_ids") + @ExcludeMissing + fun _modelIds(): JsonField> = modelIds + + @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 + * .mode() + * .modelIds() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [Body]. */ + class Builder internal constructor() { + + private var mode: JsonField? = null + private var modelIds: JsonField>? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(body: Body) = apply { + mode = body.mode + modelIds = body.modelIds.map { it.toMutableList() } + additionalProperties = body.additionalProperties.toMutableMap() + } + + /** The model permissions mode to apply. */ + fun mode(mode: Mode) = mode(JsonField.of(mode)) + + /** + * 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 { this.mode = mode } + + /** The model IDs included in this permissions policy. */ + fun modelIds(modelIds: List) = modelIds(JsonField.of(modelIds)) + + /** + * Sets [Builder.modelIds] to an arbitrary JSON value. + * + * You should usually call [Builder.modelIds] with a well-typed `List` value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun modelIds(modelIds: JsonField>) = apply { + this.modelIds = modelIds.map { it.toMutableList() } + } + + /** + * Adds a single [String] to [modelIds]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addModelId(modelId: String) = apply { + modelIds = + (modelIds ?: JsonField.of(mutableListOf())).also { + checkKnown("modelIds", it).add(modelId) + } + } + + 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 + * .mode() + * .modelIds() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): Body = + Body( + checkRequired("mode", mode), + checkRequired("modelIds", modelIds).map { it.toImmutable() }, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing fields. + * + * @throws OpenAIInvalidDataException if any value type in this object doesn't match its + * expected type. + */ + fun validate(): Body = apply { + if (validated) { + return@apply + } + + mode().validate() + modelIds() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OpenAIInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (mode.asKnown().getOrNull()?.validity() ?: 0) + + (modelIds.asKnown().getOrNull()?.size ?: 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Body && + mode == other.mode && + modelIds == other.modelIds && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(mode, modelIds, additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Body{mode=$mode, modelIds=$modelIds, additionalProperties=$additionalProperties}" + } + + /** The model permissions mode to apply. */ + class Mode @JsonCreator private constructor(private val value: JsonField) : Enum { + + /** + * Returns this class instance's raw value. + * + * This is usually only useful if this instance was deserialized from data that doesn't + * match any known member, and you want to know that value. For example, if the SDK is on an + * older version than the API, then the API may respond with new members that the SDK is + * unaware of. + */ + @com.fasterxml.jackson.annotation.JsonValue fun _value(): JsonField = value + + companion object { + + @JvmField val ALLOW_LIST = of("allow_list") + + @JvmField val DENY_LIST = of("deny_list") + + @JvmStatic fun of(value: String) = Mode(JsonField.of(value)) + } + + /** An enum containing [Mode]'s known values. */ + enum class Known { + ALLOW_LIST, + DENY_LIST, + } + + /** + * An enum containing [Mode]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [Mode] can contain an unknown value in a couple of cases: + * - It was deserialized from data that doesn't match any known member. For example, if the + * SDK is on an older version than the API, then the API may respond with new members that + * the SDK is unaware of. + * - It was constructed with an arbitrary value using the [of] method. + */ + enum class Value { + ALLOW_LIST, + DENY_LIST, + /** An enum member indicating that [Mode] was instantiated with an unknown value. */ + _UNKNOWN, + } + + /** + * Returns an enum member corresponding to this class instance's value, or [Value._UNKNOWN] + * if the class was instantiated with an unknown value. + * + * Use the [known] method instead if you're certain the value is always known or if you want + * to throw for the unknown case. + */ + fun value(): Value = + when (this) { + ALLOW_LIST -> Value.ALLOW_LIST + DENY_LIST -> Value.DENY_LIST + else -> Value._UNKNOWN + } + + /** + * Returns an enum member corresponding to this class instance's value. + * + * Use the [value] method instead if you're uncertain the value is always known and don't + * want to throw for the unknown case. + * + * @throws OpenAIInvalidDataException if this class instance's value is a not a known + * member. + */ + fun known(): Known = + when (this) { + ALLOW_LIST -> Known.ALLOW_LIST + DENY_LIST -> Known.DENY_LIST + else -> throw OpenAIInvalidDataException("Unknown Mode: $value") + } + + /** + * Returns this class instance's primitive wire representation. + * + * This differs from the [toString] method because that method is primarily for debugging + * and generally doesn't throw. + * + * @throws OpenAIInvalidDataException if this class instance's value does not have the + * expected primitive type. + */ + fun asString(): String = + _value().asString().orElseThrow { OpenAIInvalidDataException("Value is not a String") } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing fields. + * + * @throws OpenAIInvalidDataException if any value type in this object doesn't match its + * expected type. + */ + fun validate(): Mode = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OpenAIInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Mode && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is ModelPermissionUpdateParams && + projectId == other.projectId && + body == other.body && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams + } + + override fun hashCode(): Int = + Objects.hash(projectId, body, additionalHeaders, additionalQueryParams) + + override fun toString() = + "ModelPermissionUpdateParams{projectId=$projectId, body=$body, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" +} diff --git a/openai-java-core/src/main/kotlin/com/openai/models/admin/organization/projects/modelpermissions/ProjectModelPermissions.kt b/openai-java-core/src/main/kotlin/com/openai/models/admin/organization/projects/modelpermissions/ProjectModelPermissions.kt new file mode 100644 index 000000000..8173a18a5 --- /dev/null +++ b/openai-java-core/src/main/kotlin/com/openai/models/admin/organization/projects/modelpermissions/ProjectModelPermissions.kt @@ -0,0 +1,417 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.models.admin.organization.projects.modelpermissions + +import com.fasterxml.jackson.annotation.JsonAnyGetter +import com.fasterxml.jackson.annotation.JsonAnySetter +import com.fasterxml.jackson.annotation.JsonCreator +import com.fasterxml.jackson.annotation.JsonProperty +import com.openai.core.Enum +import com.openai.core.ExcludeMissing +import com.openai.core.JsonField +import com.openai.core.JsonMissing +import com.openai.core.JsonValue +import com.openai.core.checkKnown +import com.openai.core.checkRequired +import com.openai.core.toImmutable +import com.openai.errors.OpenAIInvalidDataException +import java.util.Collections +import java.util.Objects +import kotlin.jvm.optionals.getOrNull + +/** Represents the model allowlist or denylist policy for a project. */ +class ProjectModelPermissions +@JsonCreator(mode = JsonCreator.Mode.DISABLED) +private constructor( + private val mode: JsonField, + private val modelIds: JsonField>, + private val object_: JsonValue, + private val additionalProperties: MutableMap, +) { + + @JsonCreator + private constructor( + @JsonProperty("mode") @ExcludeMissing mode: JsonField = JsonMissing.of(), + @JsonProperty("model_ids") + @ExcludeMissing + modelIds: JsonField> = JsonMissing.of(), + @JsonProperty("object") @ExcludeMissing object_: JsonValue = JsonMissing.of(), + ) : this(mode, modelIds, object_, mutableMapOf()) + + /** + * Whether the project uses an allowlist or a denylist. + * + * @throws OpenAIInvalidDataException 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 mode(): Mode = mode.getRequired("mode") + + /** + * The model IDs included in the model permissions policy. + * + * @throws OpenAIInvalidDataException 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 modelIds(): List = modelIds.getRequired("model_ids") + + /** + * The object type, which is always `project.model_permissions`. + * + * Expected to always return the following: + * ```java + * JsonValue.from("project.model_permissions") + * ``` + * + * However, this method can be useful for debugging and logging (e.g. if the server responded + * with an unexpected value). + */ + @JsonProperty("object") @ExcludeMissing fun _object_(): JsonValue = object_ + + /** + * 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 [modelIds]. + * + * Unlike [modelIds], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("model_ids") @ExcludeMissing fun _modelIds(): JsonField> = modelIds + + @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 [ProjectModelPermissions]. + * + * The following fields are required: + * ```java + * .mode() + * .modelIds() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [ProjectModelPermissions]. */ + class Builder internal constructor() { + + private var mode: JsonField? = null + private var modelIds: JsonField>? = null + private var object_: JsonValue = JsonValue.from("project.model_permissions") + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(projectModelPermissions: ProjectModelPermissions) = apply { + mode = projectModelPermissions.mode + modelIds = projectModelPermissions.modelIds.map { it.toMutableList() } + object_ = projectModelPermissions.object_ + additionalProperties = projectModelPermissions.additionalProperties.toMutableMap() + } + + /** Whether the project uses an allowlist or a denylist. */ + fun mode(mode: Mode) = mode(JsonField.of(mode)) + + /** + * 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 { this.mode = mode } + + /** The model IDs included in the model permissions policy. */ + fun modelIds(modelIds: List) = modelIds(JsonField.of(modelIds)) + + /** + * Sets [Builder.modelIds] to an arbitrary JSON value. + * + * You should usually call [Builder.modelIds] with a well-typed `List` value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun modelIds(modelIds: JsonField>) = apply { + this.modelIds = modelIds.map { it.toMutableList() } + } + + /** + * Adds a single [String] to [modelIds]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addModelId(modelId: String) = apply { + modelIds = + (modelIds ?: JsonField.of(mutableListOf())).also { + checkKnown("modelIds", it).add(modelId) + } + } + + /** + * Sets the field to an arbitrary JSON value. + * + * It is usually unnecessary to call this method because the field defaults to the + * following: + * ```java + * JsonValue.from("project.model_permissions") + * ``` + * + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun object_(object_: JsonValue) = apply { this.object_ = object_ } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [ProjectModelPermissions]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .mode() + * .modelIds() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): ProjectModelPermissions = + ProjectModelPermissions( + checkRequired("mode", mode), + checkRequired("modelIds", modelIds).map { it.toImmutable() }, + object_, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected types recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing fields. + * + * @throws OpenAIInvalidDataException if any value type in this object doesn't match its + * expected type. + */ + fun validate(): ProjectModelPermissions = apply { + if (validated) { + return@apply + } + + mode().validate() + modelIds() + _object_().let { + if (it != JsonValue.from("project.model_permissions")) { + throw OpenAIInvalidDataException("'object_' is invalid, received $it") + } + } + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OpenAIInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (mode.asKnown().getOrNull()?.validity() ?: 0) + + (modelIds.asKnown().getOrNull()?.size ?: 0) + + object_.let { if (it == JsonValue.from("project.model_permissions")) 1 else 0 } + + /** Whether the project uses an allowlist or a denylist. */ + class Mode @JsonCreator private constructor(private val value: JsonField) : Enum { + + /** + * Returns this class instance's raw value. + * + * This is usually only useful if this instance was deserialized from data that doesn't + * match any known member, and you want to know that value. For example, if the SDK is on an + * older version than the API, then the API may respond with new members that the SDK is + * unaware of. + */ + @com.fasterxml.jackson.annotation.JsonValue fun _value(): JsonField = value + + companion object { + + @JvmField val ALLOW_LIST = of("allow_list") + + @JvmField val DENY_LIST = of("deny_list") + + @JvmStatic fun of(value: String) = Mode(JsonField.of(value)) + } + + /** An enum containing [Mode]'s known values. */ + enum class Known { + ALLOW_LIST, + DENY_LIST, + } + + /** + * An enum containing [Mode]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [Mode] can contain an unknown value in a couple of cases: + * - It was deserialized from data that doesn't match any known member. For example, if the + * SDK is on an older version than the API, then the API may respond with new members that + * the SDK is unaware of. + * - It was constructed with an arbitrary value using the [of] method. + */ + enum class Value { + ALLOW_LIST, + DENY_LIST, + /** An enum member indicating that [Mode] was instantiated with an unknown value. */ + _UNKNOWN, + } + + /** + * Returns an enum member corresponding to this class instance's value, or [Value._UNKNOWN] + * if the class was instantiated with an unknown value. + * + * Use the [known] method instead if you're certain the value is always known or if you want + * to throw for the unknown case. + */ + fun value(): Value = + when (this) { + ALLOW_LIST -> Value.ALLOW_LIST + DENY_LIST -> Value.DENY_LIST + else -> Value._UNKNOWN + } + + /** + * Returns an enum member corresponding to this class instance's value. + * + * Use the [value] method instead if you're uncertain the value is always known and don't + * want to throw for the unknown case. + * + * @throws OpenAIInvalidDataException if this class instance's value is a not a known + * member. + */ + fun known(): Known = + when (this) { + ALLOW_LIST -> Known.ALLOW_LIST + DENY_LIST -> Known.DENY_LIST + else -> throw OpenAIInvalidDataException("Unknown Mode: $value") + } + + /** + * Returns this class instance's primitive wire representation. + * + * This differs from the [toString] method because that method is primarily for debugging + * and generally doesn't throw. + * + * @throws OpenAIInvalidDataException if this class instance's value does not have the + * expected primitive type. + */ + fun asString(): String = + _value().asString().orElseThrow { OpenAIInvalidDataException("Value is not a String") } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing fields. + * + * @throws OpenAIInvalidDataException if any value type in this object doesn't match its + * expected type. + */ + fun validate(): Mode = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OpenAIInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Mode && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is ProjectModelPermissions && + mode == other.mode && + modelIds == other.modelIds && + object_ == other.object_ && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(mode, modelIds, object_, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "ProjectModelPermissions{mode=$mode, modelIds=$modelIds, object_=$object_, additionalProperties=$additionalProperties}" +} diff --git a/openai-java-core/src/main/kotlin/com/openai/models/admin/organization/projects/modelpermissions/ProjectModelPermissionsDeleted.kt b/openai-java-core/src/main/kotlin/com/openai/models/admin/organization/projects/modelpermissions/ProjectModelPermissionsDeleted.kt new file mode 100644 index 000000000..0e23b180e --- /dev/null +++ b/openai-java-core/src/main/kotlin/com/openai/models/admin/organization/projects/modelpermissions/ProjectModelPermissionsDeleted.kt @@ -0,0 +1,225 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.models.admin.organization.projects.modelpermissions + +import com.fasterxml.jackson.annotation.JsonAnyGetter +import com.fasterxml.jackson.annotation.JsonAnySetter +import com.fasterxml.jackson.annotation.JsonCreator +import com.fasterxml.jackson.annotation.JsonProperty +import com.openai.core.ExcludeMissing +import com.openai.core.JsonField +import com.openai.core.JsonMissing +import com.openai.core.JsonValue +import com.openai.core.checkRequired +import com.openai.errors.OpenAIInvalidDataException +import java.util.Collections +import java.util.Objects + +/** Confirmation payload returned after deleting project model permissions. */ +class ProjectModelPermissionsDeleted +@JsonCreator(mode = JsonCreator.Mode.DISABLED) +private constructor( + private val deleted: JsonField, + private val object_: JsonValue, + private val additionalProperties: MutableMap, +) { + + @JsonCreator + private constructor( + @JsonProperty("deleted") @ExcludeMissing deleted: JsonField = JsonMissing.of(), + @JsonProperty("object") @ExcludeMissing object_: JsonValue = JsonMissing.of(), + ) : this(deleted, object_, mutableMapOf()) + + /** + * Whether the project model permissions were deleted. + * + * @throws OpenAIInvalidDataException 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 deleted(): Boolean = deleted.getRequired("deleted") + + /** + * The object type, which is always `project.model_permissions.deleted`. + * + * Expected to always return the following: + * ```java + * JsonValue.from("project.model_permissions.deleted") + * ``` + * + * However, this method can be useful for debugging and logging (e.g. if the server responded + * with an unexpected value). + */ + @JsonProperty("object") @ExcludeMissing fun _object_(): JsonValue = object_ + + /** + * Returns the raw JSON value of [deleted]. + * + * Unlike [deleted], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("deleted") @ExcludeMissing fun _deleted(): JsonField = deleted + + @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 + * [ProjectModelPermissionsDeleted]. + * + * The following fields are required: + * ```java + * .deleted() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [ProjectModelPermissionsDeleted]. */ + class Builder internal constructor() { + + private var deleted: JsonField? = null + private var object_: JsonValue = JsonValue.from("project.model_permissions.deleted") + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(projectModelPermissionsDeleted: ProjectModelPermissionsDeleted) = apply { + deleted = projectModelPermissionsDeleted.deleted + object_ = projectModelPermissionsDeleted.object_ + additionalProperties = + projectModelPermissionsDeleted.additionalProperties.toMutableMap() + } + + /** Whether the project model permissions were deleted. */ + fun deleted(deleted: Boolean) = deleted(JsonField.of(deleted)) + + /** + * Sets [Builder.deleted] to an arbitrary JSON value. + * + * You should usually call [Builder.deleted] with a well-typed [Boolean] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun deleted(deleted: JsonField) = apply { this.deleted = deleted } + + /** + * Sets the field to an arbitrary JSON value. + * + * It is usually unnecessary to call this method because the field defaults to the + * following: + * ```java + * JsonValue.from("project.model_permissions.deleted") + * ``` + * + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun object_(object_: JsonValue) = apply { this.object_ = object_ } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [ProjectModelPermissionsDeleted]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .deleted() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): ProjectModelPermissionsDeleted = + ProjectModelPermissionsDeleted( + checkRequired("deleted", deleted), + object_, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected types recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing fields. + * + * @throws OpenAIInvalidDataException if any value type in this object doesn't match its + * expected type. + */ + fun validate(): ProjectModelPermissionsDeleted = apply { + if (validated) { + return@apply + } + + deleted() + _object_().let { + if (it != JsonValue.from("project.model_permissions.deleted")) { + throw OpenAIInvalidDataException("'object_' is invalid, received $it") + } + } + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OpenAIInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (if (deleted.asKnown().isPresent) 1 else 0) + + object_.let { if (it == JsonValue.from("project.model_permissions.deleted")) 1 else 0 } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is ProjectModelPermissionsDeleted && + deleted == other.deleted && + object_ == other.object_ && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(deleted, object_, additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "ProjectModelPermissionsDeleted{deleted=$deleted, object_=$object_, additionalProperties=$additionalProperties}" +} diff --git a/openai-java-core/src/main/kotlin/com/openai/models/admin/organization/usage/UsageFileSearchCallsParams.kt b/openai-java-core/src/main/kotlin/com/openai/models/admin/organization/usage/UsageFileSearchCallsParams.kt new file mode 100644 index 000000000..15fb02a02 --- /dev/null +++ b/openai-java-core/src/main/kotlin/com/openai/models/admin/organization/usage/UsageFileSearchCallsParams.kt @@ -0,0 +1,746 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.models.admin.organization.usage + +import com.fasterxml.jackson.annotation.JsonCreator +import com.openai.core.Enum +import com.openai.core.JsonField +import com.openai.core.Params +import com.openai.core.checkRequired +import com.openai.core.http.Headers +import com.openai.core.http.QueryParams +import com.openai.core.toImmutable +import com.openai.errors.OpenAIInvalidDataException +import java.util.Objects +import java.util.Optional +import kotlin.jvm.optionals.getOrNull + +/** Get file search calls usage details for the organization. */ +class UsageFileSearchCallsParams +private constructor( + private val startTime: Long, + private val apiKeyIds: List?, + private val bucketWidth: BucketWidth?, + private val endTime: Long?, + private val groupBy: List?, + private val limit: Long?, + private val page: String?, + private val projectIds: List?, + private val userIds: List?, + private val vectorStoreIds: List?, + private val additionalHeaders: Headers, + private val additionalQueryParams: QueryParams, +) : Params { + + /** Start time (Unix seconds) of the query time range, inclusive. */ + fun startTime(): Long = startTime + + /** Return only usage for these API keys. */ + fun apiKeyIds(): Optional> = Optional.ofNullable(apiKeyIds) + + /** + * Width of each time bucket in response. Currently `1m`, `1h` and `1d` are supported, default + * to `1d`. + */ + fun bucketWidth(): Optional = Optional.ofNullable(bucketWidth) + + /** End time (Unix seconds) of the query time range, exclusive. */ + fun endTime(): Optional = Optional.ofNullable(endTime) + + /** + * Group the usage data by the specified fields. Support fields include `project_id`, `user_id`, + * `api_key_id`, `vector_store_id` or any combination of them. + */ + fun groupBy(): Optional> = Optional.ofNullable(groupBy) + + /** + * Specifies the number of buckets to return. + * - `bucket_width=1d`: default: 7, max: 31 + * - `bucket_width=1h`: default: 24, max: 168 + * - `bucket_width=1m`: default: 60, max: 1440 + */ + fun limit(): Optional = Optional.ofNullable(limit) + + /** + * A cursor for use in pagination. Corresponding to the `next_page` field from the previous + * response. + */ + fun page(): Optional = Optional.ofNullable(page) + + /** Return only usage for these projects. */ + fun projectIds(): Optional> = Optional.ofNullable(projectIds) + + /** Return only usage for these users. */ + fun userIds(): Optional> = Optional.ofNullable(userIds) + + /** Return only usage for these vector stores. */ + fun vectorStoreIds(): Optional> = Optional.ofNullable(vectorStoreIds) + + /** Additional headers to send with the request. */ + fun _additionalHeaders(): Headers = additionalHeaders + + /** Additional query param to send with the request. */ + fun _additionalQueryParams(): QueryParams = additionalQueryParams + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of [UsageFileSearchCallsParams]. + * + * The following fields are required: + * ```java + * .startTime() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [UsageFileSearchCallsParams]. */ + class Builder internal constructor() { + + private var startTime: Long? = null + private var apiKeyIds: MutableList? = null + private var bucketWidth: BucketWidth? = null + private var endTime: Long? = null + private var groupBy: MutableList? = null + private var limit: Long? = null + private var page: String? = null + private var projectIds: MutableList? = null + private var userIds: MutableList? = null + private var vectorStoreIds: MutableList? = null + private var additionalHeaders: Headers.Builder = Headers.builder() + private var additionalQueryParams: QueryParams.Builder = QueryParams.builder() + + @JvmSynthetic + internal fun from(usageFileSearchCallsParams: UsageFileSearchCallsParams) = apply { + startTime = usageFileSearchCallsParams.startTime + apiKeyIds = usageFileSearchCallsParams.apiKeyIds?.toMutableList() + bucketWidth = usageFileSearchCallsParams.bucketWidth + endTime = usageFileSearchCallsParams.endTime + groupBy = usageFileSearchCallsParams.groupBy?.toMutableList() + limit = usageFileSearchCallsParams.limit + page = usageFileSearchCallsParams.page + projectIds = usageFileSearchCallsParams.projectIds?.toMutableList() + userIds = usageFileSearchCallsParams.userIds?.toMutableList() + vectorStoreIds = usageFileSearchCallsParams.vectorStoreIds?.toMutableList() + additionalHeaders = usageFileSearchCallsParams.additionalHeaders.toBuilder() + additionalQueryParams = usageFileSearchCallsParams.additionalQueryParams.toBuilder() + } + + /** Start time (Unix seconds) of the query time range, inclusive. */ + fun startTime(startTime: Long) = apply { this.startTime = startTime } + + /** Return only usage for these API keys. */ + fun apiKeyIds(apiKeyIds: List?) = apply { + this.apiKeyIds = apiKeyIds?.toMutableList() + } + + /** Alias for calling [Builder.apiKeyIds] with `apiKeyIds.orElse(null)`. */ + fun apiKeyIds(apiKeyIds: Optional>) = apiKeyIds(apiKeyIds.getOrNull()) + + /** + * Adds a single [String] to [apiKeyIds]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addApiKeyId(apiKeyId: String) = apply { + apiKeyIds = (apiKeyIds ?: mutableListOf()).apply { add(apiKeyId) } + } + + /** + * Width of each time bucket in response. Currently `1m`, `1h` and `1d` are supported, + * default to `1d`. + */ + fun bucketWidth(bucketWidth: BucketWidth?) = apply { this.bucketWidth = bucketWidth } + + /** Alias for calling [Builder.bucketWidth] with `bucketWidth.orElse(null)`. */ + fun bucketWidth(bucketWidth: Optional) = bucketWidth(bucketWidth.getOrNull()) + + /** End time (Unix seconds) of the query time range, exclusive. */ + fun endTime(endTime: Long?) = apply { this.endTime = endTime } + + /** + * Alias for [Builder.endTime]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun endTime(endTime: Long) = endTime(endTime as Long?) + + /** Alias for calling [Builder.endTime] with `endTime.orElse(null)`. */ + fun endTime(endTime: Optional) = endTime(endTime.getOrNull()) + + /** + * Group the usage data by the specified fields. Support fields include `project_id`, + * `user_id`, `api_key_id`, `vector_store_id` or any combination of them. + */ + fun groupBy(groupBy: List?) = apply { this.groupBy = groupBy?.toMutableList() } + + /** Alias for calling [Builder.groupBy] with `groupBy.orElse(null)`. */ + fun groupBy(groupBy: Optional>) = groupBy(groupBy.getOrNull()) + + /** + * Adds a single [GroupBy] to [Builder.groupBy]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addGroupBy(groupBy: GroupBy) = apply { + this.groupBy = (this.groupBy ?: mutableListOf()).apply { add(groupBy) } + } + + /** + * Specifies the number of buckets to return. + * - `bucket_width=1d`: default: 7, max: 31 + * - `bucket_width=1h`: default: 24, max: 168 + * - `bucket_width=1m`: default: 60, max: 1440 + */ + fun limit(limit: Long?) = apply { this.limit = 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()) + + /** + * A cursor for use in pagination. Corresponding to the `next_page` field from the previous + * response. + */ + fun page(page: String?) = apply { this.page = page } + + /** Alias for calling [Builder.page] with `page.orElse(null)`. */ + fun page(page: Optional) = page(page.getOrNull()) + + /** Return only usage for these projects. */ + fun projectIds(projectIds: List?) = apply { + this.projectIds = projectIds?.toMutableList() + } + + /** Alias for calling [Builder.projectIds] with `projectIds.orElse(null)`. */ + fun projectIds(projectIds: Optional>) = projectIds(projectIds.getOrNull()) + + /** + * Adds a single [String] to [projectIds]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addProjectId(projectId: String) = apply { + projectIds = (projectIds ?: mutableListOf()).apply { add(projectId) } + } + + /** Return only usage for these users. */ + fun userIds(userIds: List?) = apply { this.userIds = userIds?.toMutableList() } + + /** Alias for calling [Builder.userIds] with `userIds.orElse(null)`. */ + fun userIds(userIds: Optional>) = userIds(userIds.getOrNull()) + + /** + * Adds a single [String] to [userIds]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addUserId(userId: String) = apply { + userIds = (userIds ?: mutableListOf()).apply { add(userId) } + } + + /** Return only usage for these vector stores. */ + fun vectorStoreIds(vectorStoreIds: List?) = apply { + this.vectorStoreIds = vectorStoreIds?.toMutableList() + } + + /** Alias for calling [Builder.vectorStoreIds] with `vectorStoreIds.orElse(null)`. */ + fun vectorStoreIds(vectorStoreIds: Optional>) = + vectorStoreIds(vectorStoreIds.getOrNull()) + + /** + * Adds a single [String] to [vectorStoreIds]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addVectorStoreId(vectorStoreId: String) = apply { + vectorStoreIds = (vectorStoreIds ?: mutableListOf()).apply { add(vectorStoreId) } + } + + 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 [UsageFileSearchCallsParams]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .startTime() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): UsageFileSearchCallsParams = + UsageFileSearchCallsParams( + checkRequired("startTime", startTime), + apiKeyIds?.toImmutable(), + bucketWidth, + endTime, + groupBy?.toImmutable(), + limit, + page, + projectIds?.toImmutable(), + userIds?.toImmutable(), + vectorStoreIds?.toImmutable(), + additionalHeaders.build(), + additionalQueryParams.build(), + ) + } + + override fun _headers(): Headers = additionalHeaders + + override fun _queryParams(): QueryParams = + QueryParams.builder() + .apply { + put("start_time", startTime.toString()) + apiKeyIds?.forEach { put("api_key_ids[]", it) } + bucketWidth?.let { put("bucket_width", it.toString()) } + endTime?.let { put("end_time", it.toString()) } + groupBy?.forEach { put("group_by[]", it.toString()) } + limit?.let { put("limit", it.toString()) } + page?.let { put("page", it) } + projectIds?.forEach { put("project_ids[]", it) } + userIds?.forEach { put("user_ids[]", it) } + vectorStoreIds?.forEach { put("vector_store_ids[]", it) } + putAll(additionalQueryParams) + } + .build() + + /** + * Width of each time bucket in response. Currently `1m`, `1h` and `1d` are supported, default + * to `1d`. + */ + class BucketWidth @JsonCreator private constructor(private val value: JsonField) : + Enum { + + /** + * Returns this class instance's raw value. + * + * This is usually only useful if this instance was deserialized from data that doesn't + * match any known member, and you want to know that value. For example, if the SDK is on an + * older version than the API, then the API may respond with new members that the SDK is + * unaware of. + */ + @com.fasterxml.jackson.annotation.JsonValue fun _value(): JsonField = value + + companion object { + + @JvmField val _1M = of("1m") + + @JvmField val _1H = of("1h") + + @JvmField val _1D = of("1d") + + @JvmStatic fun of(value: String) = BucketWidth(JsonField.of(value)) + } + + /** An enum containing [BucketWidth]'s known values. */ + enum class Known { + _1M, + _1H, + _1D, + } + + /** + * An enum containing [BucketWidth]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [BucketWidth] can contain an unknown value in a couple of cases: + * - It was deserialized from data that doesn't match any known member. For example, if the + * SDK is on an older version than the API, then the API may respond with new members that + * the SDK is unaware of. + * - It was constructed with an arbitrary value using the [of] method. + */ + enum class Value { + _1M, + _1H, + _1D, + /** + * An enum member indicating that [BucketWidth] was instantiated with an unknown value. + */ + _UNKNOWN, + } + + /** + * Returns an enum member corresponding to this class instance's value, or [Value._UNKNOWN] + * if the class was instantiated with an unknown value. + * + * Use the [known] method instead if you're certain the value is always known or if you want + * to throw for the unknown case. + */ + fun value(): Value = + when (this) { + _1M -> Value._1M + _1H -> Value._1H + _1D -> Value._1D + else -> Value._UNKNOWN + } + + /** + * Returns an enum member corresponding to this class instance's value. + * + * Use the [value] method instead if you're uncertain the value is always known and don't + * want to throw for the unknown case. + * + * @throws OpenAIInvalidDataException if this class instance's value is a not a known + * member. + */ + fun known(): Known = + when (this) { + _1M -> Known._1M + _1H -> Known._1H + _1D -> Known._1D + else -> throw OpenAIInvalidDataException("Unknown BucketWidth: $value") + } + + /** + * Returns this class instance's primitive wire representation. + * + * This differs from the [toString] method because that method is primarily for debugging + * and generally doesn't throw. + * + * @throws OpenAIInvalidDataException if this class instance's value does not have the + * expected primitive type. + */ + fun asString(): String = + _value().asString().orElseThrow { OpenAIInvalidDataException("Value is not a String") } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing fields. + * + * @throws OpenAIInvalidDataException if any value type in this object doesn't match its + * expected type. + */ + fun validate(): BucketWidth = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OpenAIInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is BucketWidth && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + class GroupBy @JsonCreator private constructor(private val value: JsonField) : Enum { + + /** + * Returns this class instance's raw value. + * + * This is usually only useful if this instance was deserialized from data that doesn't + * match any known member, and you want to know that value. For example, if the SDK is on an + * older version than the API, then the API may respond with new members that the SDK is + * unaware of. + */ + @com.fasterxml.jackson.annotation.JsonValue fun _value(): JsonField = value + + companion object { + + @JvmField val PROJECT_ID = of("project_id") + + @JvmField val USER_ID = of("user_id") + + @JvmField val API_KEY_ID = of("api_key_id") + + @JvmField val VECTOR_STORE_ID = of("vector_store_id") + + @JvmStatic fun of(value: String) = GroupBy(JsonField.of(value)) + } + + /** An enum containing [GroupBy]'s known values. */ + enum class Known { + PROJECT_ID, + USER_ID, + API_KEY_ID, + VECTOR_STORE_ID, + } + + /** + * An enum containing [GroupBy]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [GroupBy] can contain an unknown value in a couple of cases: + * - It was deserialized from data that doesn't match any known member. For example, if the + * SDK is on an older version than the API, then the API may respond with new members that + * the SDK is unaware of. + * - It was constructed with an arbitrary value using the [of] method. + */ + enum class Value { + PROJECT_ID, + USER_ID, + API_KEY_ID, + VECTOR_STORE_ID, + /** An enum member indicating that [GroupBy] was instantiated with an unknown value. */ + _UNKNOWN, + } + + /** + * Returns an enum member corresponding to this class instance's value, or [Value._UNKNOWN] + * if the class was instantiated with an unknown value. + * + * Use the [known] method instead if you're certain the value is always known or if you want + * to throw for the unknown case. + */ + fun value(): Value = + when (this) { + PROJECT_ID -> Value.PROJECT_ID + USER_ID -> Value.USER_ID + API_KEY_ID -> Value.API_KEY_ID + VECTOR_STORE_ID -> Value.VECTOR_STORE_ID + else -> Value._UNKNOWN + } + + /** + * Returns an enum member corresponding to this class instance's value. + * + * Use the [value] method instead if you're uncertain the value is always known and don't + * want to throw for the unknown case. + * + * @throws OpenAIInvalidDataException if this class instance's value is a not a known + * member. + */ + fun known(): Known = + when (this) { + PROJECT_ID -> Known.PROJECT_ID + USER_ID -> Known.USER_ID + API_KEY_ID -> Known.API_KEY_ID + VECTOR_STORE_ID -> Known.VECTOR_STORE_ID + else -> throw OpenAIInvalidDataException("Unknown GroupBy: $value") + } + + /** + * Returns this class instance's primitive wire representation. + * + * This differs from the [toString] method because that method is primarily for debugging + * and generally doesn't throw. + * + * @throws OpenAIInvalidDataException if this class instance's value does not have the + * expected primitive type. + */ + fun asString(): String = + _value().asString().orElseThrow { OpenAIInvalidDataException("Value is not a String") } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing fields. + * + * @throws OpenAIInvalidDataException if any value type in this object doesn't match its + * expected type. + */ + fun validate(): GroupBy = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OpenAIInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is GroupBy && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is UsageFileSearchCallsParams && + startTime == other.startTime && + apiKeyIds == other.apiKeyIds && + bucketWidth == other.bucketWidth && + endTime == other.endTime && + groupBy == other.groupBy && + limit == other.limit && + page == other.page && + projectIds == other.projectIds && + userIds == other.userIds && + vectorStoreIds == other.vectorStoreIds && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams + } + + override fun hashCode(): Int = + Objects.hash( + startTime, + apiKeyIds, + bucketWidth, + endTime, + groupBy, + limit, + page, + projectIds, + userIds, + vectorStoreIds, + additionalHeaders, + additionalQueryParams, + ) + + override fun toString() = + "UsageFileSearchCallsParams{startTime=$startTime, apiKeyIds=$apiKeyIds, bucketWidth=$bucketWidth, endTime=$endTime, groupBy=$groupBy, limit=$limit, page=$page, projectIds=$projectIds, userIds=$userIds, vectorStoreIds=$vectorStoreIds, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" +} diff --git a/openai-java-core/src/main/kotlin/com/openai/models/admin/organization/usage/UsageFileSearchCallsResponse.kt b/openai-java-core/src/main/kotlin/com/openai/models/admin/organization/usage/UsageFileSearchCallsResponse.kt new file mode 100644 index 000000000..04edc654a --- /dev/null +++ b/openai-java-core/src/main/kotlin/com/openai/models/admin/organization/usage/UsageFileSearchCallsResponse.kt @@ -0,0 +1,6930 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.models.admin.organization.usage + +import com.fasterxml.jackson.annotation.JsonAnyGetter +import com.fasterxml.jackson.annotation.JsonAnySetter +import com.fasterxml.jackson.annotation.JsonCreator +import com.fasterxml.jackson.annotation.JsonProperty +import com.fasterxml.jackson.core.JsonGenerator +import com.fasterxml.jackson.core.ObjectCodec +import com.fasterxml.jackson.databind.JsonNode +import com.fasterxml.jackson.databind.SerializerProvider +import com.fasterxml.jackson.databind.annotation.JsonDeserialize +import com.fasterxml.jackson.databind.annotation.JsonSerialize +import com.fasterxml.jackson.module.kotlin.jacksonTypeRef +import com.openai.core.BaseDeserializer +import com.openai.core.BaseSerializer +import com.openai.core.ExcludeMissing +import com.openai.core.JsonField +import com.openai.core.JsonMissing +import com.openai.core.JsonValue +import com.openai.core.checkKnown +import com.openai.core.checkRequired +import com.openai.core.getOrThrow +import com.openai.core.toImmutable +import com.openai.errors.OpenAIInvalidDataException +import java.util.Collections +import java.util.Objects +import java.util.Optional +import kotlin.jvm.optionals.getOrNull + +class UsageFileSearchCallsResponse +@JsonCreator(mode = JsonCreator.Mode.DISABLED) +private constructor( + private val data: JsonField>, + private val hasMore: JsonField, + private val nextPage: JsonField, + private val object_: JsonValue, + private val additionalProperties: MutableMap, +) { + + @JsonCreator + private constructor( + @JsonProperty("data") @ExcludeMissing data: JsonField> = JsonMissing.of(), + @JsonProperty("has_more") @ExcludeMissing hasMore: JsonField = JsonMissing.of(), + @JsonProperty("next_page") @ExcludeMissing nextPage: JsonField = JsonMissing.of(), + @JsonProperty("object") @ExcludeMissing object_: JsonValue = JsonMissing.of(), + ) : this(data, hasMore, nextPage, object_, mutableMapOf()) + + /** + * @throws OpenAIInvalidDataException 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(): List = data.getRequired("data") + + /** + * @throws OpenAIInvalidDataException 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 hasMore(): Boolean = hasMore.getRequired("has_more") + + /** + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun nextPage(): Optional = nextPage.getOptional("next_page") + + /** + * Expected to always return the following: + * ```java + * JsonValue.from("page") + * ``` + * + * However, this method can be useful for debugging and logging (e.g. if the server responded + * with an unexpected value). + */ + @JsonProperty("object") @ExcludeMissing fun _object_(): JsonValue = object_ + + /** + * 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 + + /** + * Returns the raw JSON value of [hasMore]. + * + * Unlike [hasMore], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("has_more") @ExcludeMissing fun _hasMore(): JsonField = hasMore + + /** + * Returns the raw JSON value of [nextPage]. + * + * Unlike [nextPage], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("next_page") @ExcludeMissing fun _nextPage(): JsonField = nextPage + + @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 [UsageFileSearchCallsResponse]. + * + * The following fields are required: + * ```java + * .data() + * .hasMore() + * .nextPage() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [UsageFileSearchCallsResponse]. */ + class Builder internal constructor() { + + private var data: JsonField>? = null + private var hasMore: JsonField? = null + private var nextPage: JsonField? = null + private var object_: JsonValue = JsonValue.from("page") + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(usageFileSearchCallsResponse: UsageFileSearchCallsResponse) = apply { + data = usageFileSearchCallsResponse.data.map { it.toMutableList() } + hasMore = usageFileSearchCallsResponse.hasMore + nextPage = usageFileSearchCallsResponse.nextPage + object_ = usageFileSearchCallsResponse.object_ + additionalProperties = usageFileSearchCallsResponse.additionalProperties.toMutableMap() + } + + fun data(data: List) = data(JsonField.of(data)) + + /** + * Sets [Builder.data] to an arbitrary JSON value. + * + * You should usually call [Builder.data] with a well-typed `List` 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.map { it.toMutableList() } + } + + /** + * Adds a single [Data] to [Builder.data]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addData(data: Data) = apply { + this.data = + (this.data ?: JsonField.of(mutableListOf())).also { + checkKnown("data", it).add(data) + } + } + + fun hasMore(hasMore: Boolean) = hasMore(JsonField.of(hasMore)) + + /** + * Sets [Builder.hasMore] to an arbitrary JSON value. + * + * You should usually call [Builder.hasMore] with a well-typed [Boolean] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun hasMore(hasMore: JsonField) = apply { this.hasMore = hasMore } + + fun nextPage(nextPage: String?) = nextPage(JsonField.ofNullable(nextPage)) + + /** Alias for calling [Builder.nextPage] with `nextPage.orElse(null)`. */ + fun nextPage(nextPage: Optional) = nextPage(nextPage.getOrNull()) + + /** + * Sets [Builder.nextPage] to an arbitrary JSON value. + * + * You should usually call [Builder.nextPage] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun nextPage(nextPage: JsonField) = apply { this.nextPage = nextPage } + + /** + * Sets the field to an arbitrary JSON value. + * + * It is usually unnecessary to call this method because the field defaults to the + * following: + * ```java + * JsonValue.from("page") + * ``` + * + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun object_(object_: JsonValue) = apply { this.object_ = object_ } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [UsageFileSearchCallsResponse]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .data() + * .hasMore() + * .nextPage() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): UsageFileSearchCallsResponse = + UsageFileSearchCallsResponse( + checkRequired("data", data).map { it.toImmutable() }, + checkRequired("hasMore", hasMore), + checkRequired("nextPage", nextPage), + object_, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected types recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing fields. + * + * @throws OpenAIInvalidDataException if any value type in this object doesn't match its + * expected type. + */ + fun validate(): UsageFileSearchCallsResponse = apply { + if (validated) { + return@apply + } + + data().forEach { it.validate() } + hasMore() + nextPage() + _object_().let { + if (it != JsonValue.from("page")) { + throw OpenAIInvalidDataException("'object_' is invalid, received $it") + } + } + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OpenAIInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (data.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + + (if (hasMore.asKnown().isPresent) 1 else 0) + + (if (nextPage.asKnown().isPresent) 1 else 0) + + object_.let { if (it == JsonValue.from("page")) 1 else 0 } + + class Data + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val endTime: JsonField, + private val object_: JsonValue, + private val results: JsonField>, + private val startTime: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("end_time") @ExcludeMissing endTime: JsonField = JsonMissing.of(), + @JsonProperty("object") @ExcludeMissing object_: JsonValue = JsonMissing.of(), + @JsonProperty("results") + @ExcludeMissing + results: JsonField> = JsonMissing.of(), + @JsonProperty("start_time") + @ExcludeMissing + startTime: JsonField = JsonMissing.of(), + ) : this(endTime, object_, results, startTime, mutableMapOf()) + + /** + * @throws OpenAIInvalidDataException 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 endTime(): Long = endTime.getRequired("end_time") + + /** + * Expected to always return the following: + * ```java + * JsonValue.from("bucket") + * ``` + * + * However, this method can be useful for debugging and logging (e.g. if the server + * responded with an unexpected value). + */ + @JsonProperty("object") @ExcludeMissing fun _object_(): JsonValue = object_ + + /** + * @throws OpenAIInvalidDataException 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 results(): List = results.getRequired("results") + + /** + * @throws OpenAIInvalidDataException 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 startTime(): Long = startTime.getRequired("start_time") + + /** + * Returns the raw JSON value of [endTime]. + * + * Unlike [endTime], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("end_time") @ExcludeMissing fun _endTime(): JsonField = endTime + + /** + * Returns the raw JSON value of [results]. + * + * Unlike [results], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("results") @ExcludeMissing fun _results(): JsonField> = results + + /** + * Returns the raw JSON value of [startTime]. + * + * Unlike [startTime], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("start_time") @ExcludeMissing fun _startTime(): JsonField = startTime + + @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 [Data]. + * + * The following fields are required: + * ```java + * .endTime() + * .results() + * .startTime() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [Data]. */ + class Builder internal constructor() { + + private var endTime: JsonField? = null + private var object_: JsonValue = JsonValue.from("bucket") + private var results: JsonField>? = null + private var startTime: JsonField? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(data: Data) = apply { + endTime = data.endTime + object_ = data.object_ + results = data.results.map { it.toMutableList() } + startTime = data.startTime + additionalProperties = data.additionalProperties.toMutableMap() + } + + fun endTime(endTime: Long) = endTime(JsonField.of(endTime)) + + /** + * Sets [Builder.endTime] to an arbitrary JSON value. + * + * You should usually call [Builder.endTime] with a well-typed [Long] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun endTime(endTime: JsonField) = apply { this.endTime = endTime } + + /** + * Sets the field to an arbitrary JSON value. + * + * It is usually unnecessary to call this method because the field defaults to the + * following: + * ```java + * JsonValue.from("bucket") + * ``` + * + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun object_(object_: JsonValue) = apply { this.object_ = object_ } + + fun results(results: List) = results(JsonField.of(results)) + + /** + * Sets [Builder.results] to an arbitrary JSON value. + * + * You should usually call [Builder.results] with a well-typed `List` value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun results(results: JsonField>) = apply { + this.results = results.map { it.toMutableList() } + } + + /** + * Adds a single [Result] to [results]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addResult(result: Result) = apply { + results = + (results ?: JsonField.of(mutableListOf())).also { + checkKnown("results", it).add(result) + } + } + + /** + * Alias for calling [addResult] with + * `Result.ofOrganizationUsageCompletions(organizationUsageCompletions)`. + */ + fun addResult(organizationUsageCompletions: Result.OrganizationUsageCompletionsResult) = + addResult(Result.ofOrganizationUsageCompletions(organizationUsageCompletions)) + + /** + * Alias for calling [addResult] with + * `Result.ofOrganizationUsageEmbeddings(organizationUsageEmbeddings)`. + */ + fun addResult(organizationUsageEmbeddings: Result.OrganizationUsageEmbeddingsResult) = + addResult(Result.ofOrganizationUsageEmbeddings(organizationUsageEmbeddings)) + + /** + * Alias for calling [addResult] with + * `Result.ofOrganizationUsageModerations(organizationUsageModerations)`. + */ + fun addResult(organizationUsageModerations: Result.OrganizationUsageModerationsResult) = + addResult(Result.ofOrganizationUsageModerations(organizationUsageModerations)) + + /** + * Alias for calling [addResult] with + * `Result.ofOrganizationUsageImages(organizationUsageImages)`. + */ + fun addResult(organizationUsageImages: Result.OrganizationUsageImagesResult) = + addResult(Result.ofOrganizationUsageImages(organizationUsageImages)) + + /** + * Alias for calling [addResult] with + * `Result.ofOrganizationUsageAudioSpeeches(organizationUsageAudioSpeeches)`. + */ + fun addResult( + organizationUsageAudioSpeeches: Result.OrganizationUsageAudioSpeechesResult + ) = addResult(Result.ofOrganizationUsageAudioSpeeches(organizationUsageAudioSpeeches)) + + /** + * Alias for calling [addResult] with + * `Result.ofOrganizationUsageAudioTranscriptions(organizationUsageAudioTranscriptions)`. + */ + fun addResult( + organizationUsageAudioTranscriptions: + Result.OrganizationUsageAudioTranscriptionsResult + ) = + addResult( + Result.ofOrganizationUsageAudioTranscriptions( + organizationUsageAudioTranscriptions + ) + ) + + /** + * Alias for calling [addResult] with + * `Result.ofOrganizationUsageVectorStores(organizationUsageVectorStores)`. + */ + fun addResult( + organizationUsageVectorStores: Result.OrganizationUsageVectorStoresResult + ) = addResult(Result.ofOrganizationUsageVectorStores(organizationUsageVectorStores)) + + /** + * Alias for calling [addResult] with the following: + * ```java + * Result.OrganizationUsageVectorStoresResult.builder() + * .usageBytes(usageBytes) + * .build() + * ``` + */ + fun addOrganizationUsageVectorStoresResult(usageBytes: Long) = + addResult( + Result.OrganizationUsageVectorStoresResult.builder() + .usageBytes(usageBytes) + .build() + ) + + /** + * Alias for calling [addResult] with + * `Result.ofOrganizationUsageCodeInterpreterSessions(organizationUsageCodeInterpreterSessions)`. + */ + fun addResult( + organizationUsageCodeInterpreterSessions: + Result.OrganizationUsageCodeInterpreterSessionsResult + ) = + addResult( + Result.ofOrganizationUsageCodeInterpreterSessions( + organizationUsageCodeInterpreterSessions + ) + ) + + /** + * Alias for calling [addResult] with the following: + * ```java + * Result.OrganizationUsageCodeInterpreterSessionsResult.builder() + * .numSessions(numSessions) + * .build() + * ``` + */ + fun addOrganizationUsageCodeInterpreterSessionsResult(numSessions: Long) = + addResult( + Result.OrganizationUsageCodeInterpreterSessionsResult.builder() + .numSessions(numSessions) + .build() + ) + + /** + * Alias for calling [addResult] with + * `Result.ofOrganizationUsageFileSearches(organizationUsageFileSearches)`. + */ + fun addResult( + organizationUsageFileSearches: Result.OrganizationUsageFileSearchesResult + ) = addResult(Result.ofOrganizationUsageFileSearches(organizationUsageFileSearches)) + + /** + * Alias for calling [addResult] with the following: + * ```java + * Result.OrganizationUsageFileSearchesResult.builder() + * .numRequests(numRequests) + * .build() + * ``` + */ + fun addOrganizationUsageFileSearchesResult(numRequests: Long) = + addResult( + Result.OrganizationUsageFileSearchesResult.builder() + .numRequests(numRequests) + .build() + ) + + /** + * Alias for calling [addResult] with + * `Result.ofOrganizationUsageWebSearches(organizationUsageWebSearches)`. + */ + fun addResult(organizationUsageWebSearches: Result.OrganizationUsageWebSearchesResult) = + addResult(Result.ofOrganizationUsageWebSearches(organizationUsageWebSearches)) + + /** + * Alias for calling [addResult] with `Result.ofOrganizationCosts(organizationCosts)`. + */ + fun addResult(organizationCosts: Result.OrganizationCostsResult) = + addResult(Result.ofOrganizationCosts(organizationCosts)) + + fun startTime(startTime: Long) = startTime(JsonField.of(startTime)) + + /** + * Sets [Builder.startTime] to an arbitrary JSON value. + * + * You should usually call [Builder.startTime] with a well-typed [Long] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun startTime(startTime: JsonField) = apply { this.startTime = startTime } + + 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 [Data]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .endTime() + * .results() + * .startTime() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): Data = + Data( + checkRequired("endTime", endTime), + object_, + checkRequired("results", results).map { it.toImmutable() }, + checkRequired("startTime", startTime), + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing fields. + * + * @throws OpenAIInvalidDataException if any value type in this object doesn't match its + * expected type. + */ + fun validate(): Data = apply { + if (validated) { + return@apply + } + + endTime() + _object_().let { + if (it != JsonValue.from("bucket")) { + throw OpenAIInvalidDataException("'object_' is invalid, received $it") + } + } + results().forEach { it.validate() } + startTime() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OpenAIInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (if (endTime.asKnown().isPresent) 1 else 0) + + object_.let { if (it == JsonValue.from("bucket")) 1 else 0 } + + (results.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + + (if (startTime.asKnown().isPresent) 1 else 0) + + /** The aggregated completions usage details of the specific time bucket. */ + @JsonDeserialize(using = Result.Deserializer::class) + @JsonSerialize(using = Result.Serializer::class) + class Result + private constructor( + private val organizationUsageCompletions: OrganizationUsageCompletionsResult? = null, + private val organizationUsageEmbeddings: OrganizationUsageEmbeddingsResult? = null, + private val organizationUsageModerations: OrganizationUsageModerationsResult? = null, + private val organizationUsageImages: OrganizationUsageImagesResult? = null, + private val organizationUsageAudioSpeeches: OrganizationUsageAudioSpeechesResult? = + null, + private val organizationUsageAudioTranscriptions: + OrganizationUsageAudioTranscriptionsResult? = + null, + private val organizationUsageVectorStores: OrganizationUsageVectorStoresResult? = null, + private val organizationUsageCodeInterpreterSessions: + OrganizationUsageCodeInterpreterSessionsResult? = + null, + private val organizationUsageFileSearches: OrganizationUsageFileSearchesResult? = null, + private val organizationUsageWebSearches: OrganizationUsageWebSearchesResult? = null, + private val organizationCosts: OrganizationCostsResult? = null, + private val _json: JsonValue? = null, + ) { + + /** The aggregated completions usage details of the specific time bucket. */ + fun organizationUsageCompletions(): Optional = + Optional.ofNullable(organizationUsageCompletions) + + /** The aggregated embeddings usage details of the specific time bucket. */ + fun organizationUsageEmbeddings(): Optional = + Optional.ofNullable(organizationUsageEmbeddings) + + /** The aggregated moderations usage details of the specific time bucket. */ + fun organizationUsageModerations(): Optional = + Optional.ofNullable(organizationUsageModerations) + + /** The aggregated images usage details of the specific time bucket. */ + fun organizationUsageImages(): Optional = + Optional.ofNullable(organizationUsageImages) + + /** The aggregated audio speeches usage details of the specific time bucket. */ + fun organizationUsageAudioSpeeches(): Optional = + Optional.ofNullable(organizationUsageAudioSpeeches) + + /** The aggregated audio transcriptions usage details of the specific time bucket. */ + fun organizationUsageAudioTranscriptions(): + Optional = + Optional.ofNullable(organizationUsageAudioTranscriptions) + + /** The aggregated vector stores usage details of the specific time bucket. */ + fun organizationUsageVectorStores(): Optional = + Optional.ofNullable(organizationUsageVectorStores) + + /** + * The aggregated code interpreter sessions usage details of the specific time bucket. + */ + fun organizationUsageCodeInterpreterSessions(): + Optional = + Optional.ofNullable(organizationUsageCodeInterpreterSessions) + + /** The aggregated file search calls usage details of the specific time bucket. */ + fun organizationUsageFileSearches(): Optional = + Optional.ofNullable(organizationUsageFileSearches) + + /** The aggregated web search calls usage details of the specific time bucket. */ + fun organizationUsageWebSearches(): Optional = + Optional.ofNullable(organizationUsageWebSearches) + + /** The aggregated costs details of the specific time bucket. */ + fun organizationCosts(): Optional = + Optional.ofNullable(organizationCosts) + + fun isOrganizationUsageCompletions(): Boolean = organizationUsageCompletions != null + + fun isOrganizationUsageEmbeddings(): Boolean = organizationUsageEmbeddings != null + + fun isOrganizationUsageModerations(): Boolean = organizationUsageModerations != null + + fun isOrganizationUsageImages(): Boolean = organizationUsageImages != null + + fun isOrganizationUsageAudioSpeeches(): Boolean = organizationUsageAudioSpeeches != null + + fun isOrganizationUsageAudioTranscriptions(): Boolean = + organizationUsageAudioTranscriptions != null + + fun isOrganizationUsageVectorStores(): Boolean = organizationUsageVectorStores != null + + fun isOrganizationUsageCodeInterpreterSessions(): Boolean = + organizationUsageCodeInterpreterSessions != null + + fun isOrganizationUsageFileSearches(): Boolean = organizationUsageFileSearches != null + + fun isOrganizationUsageWebSearches(): Boolean = organizationUsageWebSearches != null + + fun isOrganizationCosts(): Boolean = organizationCosts != null + + /** The aggregated completions usage details of the specific time bucket. */ + fun asOrganizationUsageCompletions(): OrganizationUsageCompletionsResult = + organizationUsageCompletions.getOrThrow("organizationUsageCompletions") + + /** The aggregated embeddings usage details of the specific time bucket. */ + fun asOrganizationUsageEmbeddings(): OrganizationUsageEmbeddingsResult = + organizationUsageEmbeddings.getOrThrow("organizationUsageEmbeddings") + + /** The aggregated moderations usage details of the specific time bucket. */ + fun asOrganizationUsageModerations(): OrganizationUsageModerationsResult = + organizationUsageModerations.getOrThrow("organizationUsageModerations") + + /** The aggregated images usage details of the specific time bucket. */ + fun asOrganizationUsageImages(): OrganizationUsageImagesResult = + organizationUsageImages.getOrThrow("organizationUsageImages") + + /** The aggregated audio speeches usage details of the specific time bucket. */ + fun asOrganizationUsageAudioSpeeches(): OrganizationUsageAudioSpeechesResult = + organizationUsageAudioSpeeches.getOrThrow("organizationUsageAudioSpeeches") + + /** The aggregated audio transcriptions usage details of the specific time bucket. */ + fun asOrganizationUsageAudioTranscriptions(): + OrganizationUsageAudioTranscriptionsResult = + organizationUsageAudioTranscriptions.getOrThrow( + "organizationUsageAudioTranscriptions" + ) + + /** The aggregated vector stores usage details of the specific time bucket. */ + fun asOrganizationUsageVectorStores(): OrganizationUsageVectorStoresResult = + organizationUsageVectorStores.getOrThrow("organizationUsageVectorStores") + + /** + * The aggregated code interpreter sessions usage details of the specific time bucket. + */ + fun asOrganizationUsageCodeInterpreterSessions(): + OrganizationUsageCodeInterpreterSessionsResult = + organizationUsageCodeInterpreterSessions.getOrThrow( + "organizationUsageCodeInterpreterSessions" + ) + + /** The aggregated file search calls usage details of the specific time bucket. */ + fun asOrganizationUsageFileSearches(): OrganizationUsageFileSearchesResult = + organizationUsageFileSearches.getOrThrow("organizationUsageFileSearches") + + /** The aggregated web search calls usage details of the specific time bucket. */ + fun asOrganizationUsageWebSearches(): OrganizationUsageWebSearchesResult = + organizationUsageWebSearches.getOrThrow("organizationUsageWebSearches") + + /** The aggregated costs details of the specific time bucket. */ + fun asOrganizationCosts(): OrganizationCostsResult = + organizationCosts.getOrThrow("organizationCosts") + + fun _json(): Optional = Optional.ofNullable(_json) + + /** + * Maps this instance's current variant to a value of type [T] using the given + * [visitor]. + * + * Note that this method is _not_ forwards compatible with new variants from the API, + * unless [visitor] overrides [Visitor.unknown]. To handle variants not known to this + * version of the SDK gracefully, consider overriding [Visitor.unknown]: + * ```java + * import com.openai.core.JsonValue; + * import java.util.Optional; + * + * Optional result = result.accept(new Result.Visitor>() { + * @Override + * public Optional visitOrganizationUsageCompletions(OrganizationUsageCompletionsResult organizationUsageCompletions) { + * return Optional.of(organizationUsageCompletions.toString()); + * } + * + * // ... + * + * @Override + * public Optional unknown(JsonValue json) { + * // Or inspect the `json`. + * return Optional.empty(); + * } + * }); + * ``` + * + * @throws OpenAIInvalidDataException if [Visitor.unknown] is not overridden in + * [visitor] and the current variant is unknown. + */ + fun accept(visitor: Visitor): T = + when { + organizationUsageCompletions != null -> + visitor.visitOrganizationUsageCompletions(organizationUsageCompletions) + organizationUsageEmbeddings != null -> + visitor.visitOrganizationUsageEmbeddings(organizationUsageEmbeddings) + organizationUsageModerations != null -> + visitor.visitOrganizationUsageModerations(organizationUsageModerations) + organizationUsageImages != null -> + visitor.visitOrganizationUsageImages(organizationUsageImages) + organizationUsageAudioSpeeches != null -> + visitor.visitOrganizationUsageAudioSpeeches(organizationUsageAudioSpeeches) + organizationUsageAudioTranscriptions != null -> + visitor.visitOrganizationUsageAudioTranscriptions( + organizationUsageAudioTranscriptions + ) + organizationUsageVectorStores != null -> + visitor.visitOrganizationUsageVectorStores(organizationUsageVectorStores) + organizationUsageCodeInterpreterSessions != null -> + visitor.visitOrganizationUsageCodeInterpreterSessions( + organizationUsageCodeInterpreterSessions + ) + organizationUsageFileSearches != null -> + visitor.visitOrganizationUsageFileSearches(organizationUsageFileSearches) + organizationUsageWebSearches != null -> + visitor.visitOrganizationUsageWebSearches(organizationUsageWebSearches) + organizationCosts != null -> visitor.visitOrganizationCosts(organizationCosts) + else -> visitor.unknown(_json) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing + * fields. + * + * @throws OpenAIInvalidDataException if any value type in this object doesn't match its + * expected type. + */ + fun validate(): Result = apply { + if (validated) { + return@apply + } + + accept( + object : Visitor { + override fun visitOrganizationUsageCompletions( + organizationUsageCompletions: OrganizationUsageCompletionsResult + ) { + organizationUsageCompletions.validate() + } + + override fun visitOrganizationUsageEmbeddings( + organizationUsageEmbeddings: OrganizationUsageEmbeddingsResult + ) { + organizationUsageEmbeddings.validate() + } + + override fun visitOrganizationUsageModerations( + organizationUsageModerations: OrganizationUsageModerationsResult + ) { + organizationUsageModerations.validate() + } + + override fun visitOrganizationUsageImages( + organizationUsageImages: OrganizationUsageImagesResult + ) { + organizationUsageImages.validate() + } + + override fun visitOrganizationUsageAudioSpeeches( + organizationUsageAudioSpeeches: OrganizationUsageAudioSpeechesResult + ) { + organizationUsageAudioSpeeches.validate() + } + + override fun visitOrganizationUsageAudioTranscriptions( + organizationUsageAudioTranscriptions: + OrganizationUsageAudioTranscriptionsResult + ) { + organizationUsageAudioTranscriptions.validate() + } + + override fun visitOrganizationUsageVectorStores( + organizationUsageVectorStores: OrganizationUsageVectorStoresResult + ) { + organizationUsageVectorStores.validate() + } + + override fun visitOrganizationUsageCodeInterpreterSessions( + organizationUsageCodeInterpreterSessions: + OrganizationUsageCodeInterpreterSessionsResult + ) { + organizationUsageCodeInterpreterSessions.validate() + } + + override fun visitOrganizationUsageFileSearches( + organizationUsageFileSearches: OrganizationUsageFileSearchesResult + ) { + organizationUsageFileSearches.validate() + } + + override fun visitOrganizationUsageWebSearches( + organizationUsageWebSearches: OrganizationUsageWebSearchesResult + ) { + organizationUsageWebSearches.validate() + } + + override fun visitOrganizationCosts( + organizationCosts: OrganizationCostsResult + ) { + organizationCosts.validate() + } + } + ) + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OpenAIInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + accept( + object : Visitor { + override fun visitOrganizationUsageCompletions( + organizationUsageCompletions: OrganizationUsageCompletionsResult + ) = organizationUsageCompletions.validity() + + override fun visitOrganizationUsageEmbeddings( + organizationUsageEmbeddings: OrganizationUsageEmbeddingsResult + ) = organizationUsageEmbeddings.validity() + + override fun visitOrganizationUsageModerations( + organizationUsageModerations: OrganizationUsageModerationsResult + ) = organizationUsageModerations.validity() + + override fun visitOrganizationUsageImages( + organizationUsageImages: OrganizationUsageImagesResult + ) = organizationUsageImages.validity() + + override fun visitOrganizationUsageAudioSpeeches( + organizationUsageAudioSpeeches: OrganizationUsageAudioSpeechesResult + ) = organizationUsageAudioSpeeches.validity() + + override fun visitOrganizationUsageAudioTranscriptions( + organizationUsageAudioTranscriptions: + OrganizationUsageAudioTranscriptionsResult + ) = organizationUsageAudioTranscriptions.validity() + + override fun visitOrganizationUsageVectorStores( + organizationUsageVectorStores: OrganizationUsageVectorStoresResult + ) = organizationUsageVectorStores.validity() + + override fun visitOrganizationUsageCodeInterpreterSessions( + organizationUsageCodeInterpreterSessions: + OrganizationUsageCodeInterpreterSessionsResult + ) = organizationUsageCodeInterpreterSessions.validity() + + override fun visitOrganizationUsageFileSearches( + organizationUsageFileSearches: OrganizationUsageFileSearchesResult + ) = organizationUsageFileSearches.validity() + + override fun visitOrganizationUsageWebSearches( + organizationUsageWebSearches: OrganizationUsageWebSearchesResult + ) = organizationUsageWebSearches.validity() + + override fun visitOrganizationCosts( + organizationCosts: OrganizationCostsResult + ) = organizationCosts.validity() + + override fun unknown(json: JsonValue?) = 0 + } + ) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Result && + organizationUsageCompletions == other.organizationUsageCompletions && + organizationUsageEmbeddings == other.organizationUsageEmbeddings && + organizationUsageModerations == other.organizationUsageModerations && + organizationUsageImages == other.organizationUsageImages && + organizationUsageAudioSpeeches == other.organizationUsageAudioSpeeches && + organizationUsageAudioTranscriptions == + other.organizationUsageAudioTranscriptions && + organizationUsageVectorStores == other.organizationUsageVectorStores && + organizationUsageCodeInterpreterSessions == + other.organizationUsageCodeInterpreterSessions && + organizationUsageFileSearches == other.organizationUsageFileSearches && + organizationUsageWebSearches == other.organizationUsageWebSearches && + organizationCosts == other.organizationCosts + } + + override fun hashCode(): Int = + Objects.hash( + organizationUsageCompletions, + organizationUsageEmbeddings, + organizationUsageModerations, + organizationUsageImages, + organizationUsageAudioSpeeches, + organizationUsageAudioTranscriptions, + organizationUsageVectorStores, + organizationUsageCodeInterpreterSessions, + organizationUsageFileSearches, + organizationUsageWebSearches, + organizationCosts, + ) + + override fun toString(): String = + when { + organizationUsageCompletions != null -> + "Result{organizationUsageCompletions=$organizationUsageCompletions}" + organizationUsageEmbeddings != null -> + "Result{organizationUsageEmbeddings=$organizationUsageEmbeddings}" + organizationUsageModerations != null -> + "Result{organizationUsageModerations=$organizationUsageModerations}" + organizationUsageImages != null -> + "Result{organizationUsageImages=$organizationUsageImages}" + organizationUsageAudioSpeeches != null -> + "Result{organizationUsageAudioSpeeches=$organizationUsageAudioSpeeches}" + organizationUsageAudioTranscriptions != null -> + "Result{organizationUsageAudioTranscriptions=$organizationUsageAudioTranscriptions}" + organizationUsageVectorStores != null -> + "Result{organizationUsageVectorStores=$organizationUsageVectorStores}" + organizationUsageCodeInterpreterSessions != null -> + "Result{organizationUsageCodeInterpreterSessions=$organizationUsageCodeInterpreterSessions}" + organizationUsageFileSearches != null -> + "Result{organizationUsageFileSearches=$organizationUsageFileSearches}" + organizationUsageWebSearches != null -> + "Result{organizationUsageWebSearches=$organizationUsageWebSearches}" + organizationCosts != null -> "Result{organizationCosts=$organizationCosts}" + _json != null -> "Result{_unknown=$_json}" + else -> throw IllegalStateException("Invalid Result") + } + + companion object { + + /** The aggregated completions usage details of the specific time bucket. */ + @JvmStatic + fun ofOrganizationUsageCompletions( + organizationUsageCompletions: OrganizationUsageCompletionsResult + ) = Result(organizationUsageCompletions = organizationUsageCompletions) + + /** The aggregated embeddings usage details of the specific time bucket. */ + @JvmStatic + fun ofOrganizationUsageEmbeddings( + organizationUsageEmbeddings: OrganizationUsageEmbeddingsResult + ) = Result(organizationUsageEmbeddings = organizationUsageEmbeddings) + + /** The aggregated moderations usage details of the specific time bucket. */ + @JvmStatic + fun ofOrganizationUsageModerations( + organizationUsageModerations: OrganizationUsageModerationsResult + ) = Result(organizationUsageModerations = organizationUsageModerations) + + /** The aggregated images usage details of the specific time bucket. */ + @JvmStatic + fun ofOrganizationUsageImages( + organizationUsageImages: OrganizationUsageImagesResult + ) = Result(organizationUsageImages = organizationUsageImages) + + /** The aggregated audio speeches usage details of the specific time bucket. */ + @JvmStatic + fun ofOrganizationUsageAudioSpeeches( + organizationUsageAudioSpeeches: OrganizationUsageAudioSpeechesResult + ) = Result(organizationUsageAudioSpeeches = organizationUsageAudioSpeeches) + + /** + * The aggregated audio transcriptions usage details of the specific time bucket. + */ + @JvmStatic + fun ofOrganizationUsageAudioTranscriptions( + organizationUsageAudioTranscriptions: OrganizationUsageAudioTranscriptionsResult + ) = + Result( + organizationUsageAudioTranscriptions = organizationUsageAudioTranscriptions + ) + + /** The aggregated vector stores usage details of the specific time bucket. */ + @JvmStatic + fun ofOrganizationUsageVectorStores( + organizationUsageVectorStores: OrganizationUsageVectorStoresResult + ) = Result(organizationUsageVectorStores = organizationUsageVectorStores) + + /** + * The aggregated code interpreter sessions usage details of the specific time + * bucket. + */ + @JvmStatic + fun ofOrganizationUsageCodeInterpreterSessions( + organizationUsageCodeInterpreterSessions: + OrganizationUsageCodeInterpreterSessionsResult + ) = + Result( + organizationUsageCodeInterpreterSessions = + organizationUsageCodeInterpreterSessions + ) + + /** The aggregated file search calls usage details of the specific time bucket. */ + @JvmStatic + fun ofOrganizationUsageFileSearches( + organizationUsageFileSearches: OrganizationUsageFileSearchesResult + ) = Result(organizationUsageFileSearches = organizationUsageFileSearches) + + /** The aggregated web search calls usage details of the specific time bucket. */ + @JvmStatic + fun ofOrganizationUsageWebSearches( + organizationUsageWebSearches: OrganizationUsageWebSearchesResult + ) = Result(organizationUsageWebSearches = organizationUsageWebSearches) + + /** The aggregated costs details of the specific time bucket. */ + @JvmStatic + fun ofOrganizationCosts(organizationCosts: OrganizationCostsResult) = + Result(organizationCosts = organizationCosts) + } + + /** + * An interface that defines how to map each variant of [Result] to a value of type [T]. + */ + interface Visitor { + + /** The aggregated completions usage details of the specific time bucket. */ + fun visitOrganizationUsageCompletions( + organizationUsageCompletions: OrganizationUsageCompletionsResult + ): T + + /** The aggregated embeddings usage details of the specific time bucket. */ + fun visitOrganizationUsageEmbeddings( + organizationUsageEmbeddings: OrganizationUsageEmbeddingsResult + ): T + + /** The aggregated moderations usage details of the specific time bucket. */ + fun visitOrganizationUsageModerations( + organizationUsageModerations: OrganizationUsageModerationsResult + ): T + + /** The aggregated images usage details of the specific time bucket. */ + fun visitOrganizationUsageImages( + organizationUsageImages: OrganizationUsageImagesResult + ): T + + /** The aggregated audio speeches usage details of the specific time bucket. */ + fun visitOrganizationUsageAudioSpeeches( + organizationUsageAudioSpeeches: OrganizationUsageAudioSpeechesResult + ): T + + /** + * The aggregated audio transcriptions usage details of the specific time bucket. + */ + fun visitOrganizationUsageAudioTranscriptions( + organizationUsageAudioTranscriptions: OrganizationUsageAudioTranscriptionsResult + ): T + + /** The aggregated vector stores usage details of the specific time bucket. */ + fun visitOrganizationUsageVectorStores( + organizationUsageVectorStores: OrganizationUsageVectorStoresResult + ): T + + /** + * The aggregated code interpreter sessions usage details of the specific time + * bucket. + */ + fun visitOrganizationUsageCodeInterpreterSessions( + organizationUsageCodeInterpreterSessions: + OrganizationUsageCodeInterpreterSessionsResult + ): T + + /** The aggregated file search calls usage details of the specific time bucket. */ + fun visitOrganizationUsageFileSearches( + organizationUsageFileSearches: OrganizationUsageFileSearchesResult + ): T + + /** The aggregated web search calls usage details of the specific time bucket. */ + fun visitOrganizationUsageWebSearches( + organizationUsageWebSearches: OrganizationUsageWebSearchesResult + ): T + + /** The aggregated costs details of the specific time bucket. */ + fun visitOrganizationCosts(organizationCosts: OrganizationCostsResult): T + + /** + * Maps an unknown variant of [Result] to a value of type [T]. + * + * An instance of [Result] can contain an unknown variant if it was deserialized + * from data that doesn't match any known variant. For example, if the SDK is on an + * older version than the API, then the API may respond with new variants that the + * SDK is unaware of. + * + * @throws OpenAIInvalidDataException in the default implementation. + */ + fun unknown(json: JsonValue?): T { + throw OpenAIInvalidDataException("Unknown Result: $json") + } + } + + internal class Deserializer : BaseDeserializer(Result::class) { + + override fun ObjectCodec.deserialize(node: JsonNode): Result { + val json = JsonValue.fromJsonNode(node) + val object_ = + json.asObject().getOrNull()?.get("object")?.asString()?.getOrNull() + + when (object_) { + "organization.usage.completions.result" -> { + return tryDeserialize( + node, + jacksonTypeRef(), + ) + ?.let { Result(organizationUsageCompletions = it, _json = json) } + ?: Result(_json = json) + } + "organization.usage.embeddings.result" -> { + return tryDeserialize( + node, + jacksonTypeRef(), + ) + ?.let { Result(organizationUsageEmbeddings = it, _json = json) } + ?: Result(_json = json) + } + "organization.usage.moderations.result" -> { + return tryDeserialize( + node, + jacksonTypeRef(), + ) + ?.let { Result(organizationUsageModerations = it, _json = json) } + ?: Result(_json = json) + } + "organization.usage.images.result" -> { + return tryDeserialize( + node, + jacksonTypeRef(), + ) + ?.let { Result(organizationUsageImages = it, _json = json) } + ?: Result(_json = json) + } + "organization.usage.audio_speeches.result" -> { + return tryDeserialize( + node, + jacksonTypeRef(), + ) + ?.let { Result(organizationUsageAudioSpeeches = it, _json = json) } + ?: Result(_json = json) + } + "organization.usage.audio_transcriptions.result" -> { + return tryDeserialize( + node, + jacksonTypeRef(), + ) + ?.let { + Result(organizationUsageAudioTranscriptions = it, _json = json) + } ?: Result(_json = json) + } + "organization.usage.vector_stores.result" -> { + return tryDeserialize( + node, + jacksonTypeRef(), + ) + ?.let { Result(organizationUsageVectorStores = it, _json = json) } + ?: Result(_json = json) + } + "organization.usage.code_interpreter_sessions.result" -> { + return tryDeserialize( + node, + jacksonTypeRef(), + ) + ?.let { + Result( + organizationUsageCodeInterpreterSessions = it, + _json = json, + ) + } ?: Result(_json = json) + } + "organization.usage.file_searches.result" -> { + return tryDeserialize( + node, + jacksonTypeRef(), + ) + ?.let { Result(organizationUsageFileSearches = it, _json = json) } + ?: Result(_json = json) + } + "organization.usage.web_searches.result" -> { + return tryDeserialize( + node, + jacksonTypeRef(), + ) + ?.let { Result(organizationUsageWebSearches = it, _json = json) } + ?: Result(_json = json) + } + "organization.costs.result" -> { + return tryDeserialize(node, jacksonTypeRef()) + ?.let { Result(organizationCosts = it, _json = json) } + ?: Result(_json = json) + } + } + + return Result(_json = json) + } + } + + internal class Serializer : BaseSerializer(Result::class) { + + override fun serialize( + value: Result, + generator: JsonGenerator, + provider: SerializerProvider, + ) { + when { + value.organizationUsageCompletions != null -> + generator.writeObject(value.organizationUsageCompletions) + value.organizationUsageEmbeddings != null -> + generator.writeObject(value.organizationUsageEmbeddings) + value.organizationUsageModerations != null -> + generator.writeObject(value.organizationUsageModerations) + value.organizationUsageImages != null -> + generator.writeObject(value.organizationUsageImages) + value.organizationUsageAudioSpeeches != null -> + generator.writeObject(value.organizationUsageAudioSpeeches) + value.organizationUsageAudioTranscriptions != null -> + generator.writeObject(value.organizationUsageAudioTranscriptions) + value.organizationUsageVectorStores != null -> + generator.writeObject(value.organizationUsageVectorStores) + value.organizationUsageCodeInterpreterSessions != null -> + generator.writeObject(value.organizationUsageCodeInterpreterSessions) + value.organizationUsageFileSearches != null -> + generator.writeObject(value.organizationUsageFileSearches) + value.organizationUsageWebSearches != null -> + generator.writeObject(value.organizationUsageWebSearches) + value.organizationCosts != null -> + generator.writeObject(value.organizationCosts) + value._json != null -> generator.writeObject(value._json) + else -> throw IllegalStateException("Invalid Result") + } + } + } + + /** The aggregated completions usage details of the specific time bucket. */ + class OrganizationUsageCompletionsResult + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val inputTokens: JsonField, + private val numModelRequests: JsonField, + private val object_: JsonValue, + private val outputTokens: JsonField, + private val apiKeyId: JsonField, + private val batch: JsonField, + private val inputAudioTokens: JsonField, + private val inputCachedTokens: JsonField, + private val model: JsonField, + private val outputAudioTokens: JsonField, + private val projectId: JsonField, + private val serviceTier: JsonField, + private val userId: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("input_tokens") + @ExcludeMissing + inputTokens: JsonField = JsonMissing.of(), + @JsonProperty("num_model_requests") + @ExcludeMissing + numModelRequests: JsonField = JsonMissing.of(), + @JsonProperty("object") @ExcludeMissing object_: JsonValue = JsonMissing.of(), + @JsonProperty("output_tokens") + @ExcludeMissing + outputTokens: JsonField = JsonMissing.of(), + @JsonProperty("api_key_id") + @ExcludeMissing + apiKeyId: JsonField = JsonMissing.of(), + @JsonProperty("batch") + @ExcludeMissing + batch: JsonField = JsonMissing.of(), + @JsonProperty("input_audio_tokens") + @ExcludeMissing + inputAudioTokens: JsonField = JsonMissing.of(), + @JsonProperty("input_cached_tokens") + @ExcludeMissing + inputCachedTokens: JsonField = JsonMissing.of(), + @JsonProperty("model") + @ExcludeMissing + model: JsonField = JsonMissing.of(), + @JsonProperty("output_audio_tokens") + @ExcludeMissing + outputAudioTokens: JsonField = JsonMissing.of(), + @JsonProperty("project_id") + @ExcludeMissing + projectId: JsonField = JsonMissing.of(), + @JsonProperty("service_tier") + @ExcludeMissing + serviceTier: JsonField = JsonMissing.of(), + @JsonProperty("user_id") + @ExcludeMissing + userId: JsonField = JsonMissing.of(), + ) : this( + inputTokens, + numModelRequests, + object_, + outputTokens, + apiKeyId, + batch, + inputAudioTokens, + inputCachedTokens, + model, + outputAudioTokens, + projectId, + serviceTier, + userId, + mutableMapOf(), + ) + + /** + * The aggregated number of text input tokens used, including cached tokens. For + * customers subscribe to scale tier, this includes scale tier tokens. + * + * @throws OpenAIInvalidDataException 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 inputTokens(): Long = inputTokens.getRequired("input_tokens") + + /** + * The count of requests made to the model. + * + * @throws OpenAIInvalidDataException 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 numModelRequests(): Long = numModelRequests.getRequired("num_model_requests") + + /** + * Expected to always return the following: + * ```java + * JsonValue.from("organization.usage.completions.result") + * ``` + * + * However, this method can be useful for debugging and logging (e.g. if the server + * responded with an unexpected value). + */ + @JsonProperty("object") @ExcludeMissing fun _object_(): JsonValue = object_ + + /** + * The aggregated number of text output tokens used. For customers subscribe to + * scale tier, this includes scale tier tokens. + * + * @throws OpenAIInvalidDataException 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 outputTokens(): Long = outputTokens.getRequired("output_tokens") + + /** + * When `group_by=api_key_id`, this field provides the API key ID of the grouped + * usage result. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun apiKeyId(): Optional = apiKeyId.getOptional("api_key_id") + + /** + * When `group_by=batch`, this field tells whether the grouped usage result is batch + * or not. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun batch(): Optional = batch.getOptional("batch") + + /** + * The aggregated number of audio input tokens used, including cached tokens. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun inputAudioTokens(): Optional = + inputAudioTokens.getOptional("input_audio_tokens") + + /** + * The aggregated number of text input tokens that has been cached from previous + * requests. For customers subscribe to scale tier, this includes scale tier tokens. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun inputCachedTokens(): Optional = + inputCachedTokens.getOptional("input_cached_tokens") + + /** + * When `group_by=model`, this field provides the model name of the grouped usage + * result. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun model(): Optional = model.getOptional("model") + + /** + * The aggregated number of audio output tokens used. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun outputAudioTokens(): Optional = + outputAudioTokens.getOptional("output_audio_tokens") + + /** + * When `group_by=project_id`, this field provides the project ID of the grouped + * usage result. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun projectId(): Optional = projectId.getOptional("project_id") + + /** + * When `group_by=service_tier`, this field provides the service tier of the grouped + * usage result. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun serviceTier(): Optional = serviceTier.getOptional("service_tier") + + /** + * When `group_by=user_id`, this field provides the user ID of the grouped usage + * result. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun userId(): Optional = userId.getOptional("user_id") + + /** + * Returns the raw JSON value of [inputTokens]. + * + * Unlike [inputTokens], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("input_tokens") + @ExcludeMissing + fun _inputTokens(): JsonField = inputTokens + + /** + * Returns the raw JSON value of [numModelRequests]. + * + * Unlike [numModelRequests], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("num_model_requests") + @ExcludeMissing + fun _numModelRequests(): JsonField = numModelRequests + + /** + * Returns the raw JSON value of [outputTokens]. + * + * Unlike [outputTokens], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("output_tokens") + @ExcludeMissing + fun _outputTokens(): JsonField = outputTokens + + /** + * Returns the raw JSON value of [apiKeyId]. + * + * Unlike [apiKeyId], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("api_key_id") + @ExcludeMissing + fun _apiKeyId(): JsonField = apiKeyId + + /** + * Returns the raw JSON value of [batch]. + * + * Unlike [batch], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("batch") @ExcludeMissing fun _batch(): JsonField = batch + + /** + * Returns the raw JSON value of [inputAudioTokens]. + * + * Unlike [inputAudioTokens], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("input_audio_tokens") + @ExcludeMissing + fun _inputAudioTokens(): JsonField = inputAudioTokens + + /** + * Returns the raw JSON value of [inputCachedTokens]. + * + * Unlike [inputCachedTokens], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("input_cached_tokens") + @ExcludeMissing + fun _inputCachedTokens(): JsonField = inputCachedTokens + + /** + * Returns the raw JSON value of [model]. + * + * Unlike [model], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("model") @ExcludeMissing fun _model(): JsonField = model + + /** + * Returns the raw JSON value of [outputAudioTokens]. + * + * Unlike [outputAudioTokens], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("output_audio_tokens") + @ExcludeMissing + fun _outputAudioTokens(): JsonField = outputAudioTokens + + /** + * 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 [serviceTier]. + * + * Unlike [serviceTier], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("service_tier") + @ExcludeMissing + fun _serviceTier(): JsonField = serviceTier + + /** + * 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 + + @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 + * [OrganizationUsageCompletionsResult]. + * + * The following fields are required: + * ```java + * .inputTokens() + * .numModelRequests() + * .outputTokens() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [OrganizationUsageCompletionsResult]. */ + class Builder internal constructor() { + + private var inputTokens: JsonField? = null + private var numModelRequests: JsonField? = null + private var object_: JsonValue = + JsonValue.from("organization.usage.completions.result") + private var outputTokens: JsonField? = null + private var apiKeyId: JsonField = JsonMissing.of() + private var batch: JsonField = JsonMissing.of() + private var inputAudioTokens: JsonField = JsonMissing.of() + private var inputCachedTokens: JsonField = JsonMissing.of() + private var model: JsonField = JsonMissing.of() + private var outputAudioTokens: JsonField = JsonMissing.of() + private var projectId: JsonField = JsonMissing.of() + private var serviceTier: JsonField = JsonMissing.of() + private var userId: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from( + organizationUsageCompletionsResult: OrganizationUsageCompletionsResult + ) = apply { + inputTokens = organizationUsageCompletionsResult.inputTokens + numModelRequests = organizationUsageCompletionsResult.numModelRequests + object_ = organizationUsageCompletionsResult.object_ + outputTokens = organizationUsageCompletionsResult.outputTokens + apiKeyId = organizationUsageCompletionsResult.apiKeyId + batch = organizationUsageCompletionsResult.batch + inputAudioTokens = organizationUsageCompletionsResult.inputAudioTokens + inputCachedTokens = organizationUsageCompletionsResult.inputCachedTokens + model = organizationUsageCompletionsResult.model + outputAudioTokens = organizationUsageCompletionsResult.outputAudioTokens + projectId = organizationUsageCompletionsResult.projectId + serviceTier = organizationUsageCompletionsResult.serviceTier + userId = organizationUsageCompletionsResult.userId + additionalProperties = + organizationUsageCompletionsResult.additionalProperties.toMutableMap() + } + + /** + * The aggregated number of text input tokens used, including cached tokens. For + * customers subscribe to scale tier, this includes scale tier tokens. + */ + fun inputTokens(inputTokens: Long) = inputTokens(JsonField.of(inputTokens)) + + /** + * Sets [Builder.inputTokens] to an arbitrary JSON value. + * + * You should usually call [Builder.inputTokens] with a well-typed [Long] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun inputTokens(inputTokens: JsonField) = apply { + this.inputTokens = inputTokens + } + + /** The count of requests made to the model. */ + fun numModelRequests(numModelRequests: Long) = + numModelRequests(JsonField.of(numModelRequests)) + + /** + * Sets [Builder.numModelRequests] to an arbitrary JSON value. + * + * You should usually call [Builder.numModelRequests] with a well-typed [Long] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun numModelRequests(numModelRequests: JsonField) = apply { + this.numModelRequests = numModelRequests + } + + /** + * Sets the field to an arbitrary JSON value. + * + * It is usually unnecessary to call this method because the field defaults to + * the following: + * ```java + * JsonValue.from("organization.usage.completions.result") + * ``` + * + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun object_(object_: JsonValue) = apply { this.object_ = object_ } + + /** + * The aggregated number of text output tokens used. For customers subscribe to + * scale tier, this includes scale tier tokens. + */ + fun outputTokens(outputTokens: Long) = outputTokens(JsonField.of(outputTokens)) + + /** + * Sets [Builder.outputTokens] to an arbitrary JSON value. + * + * You should usually call [Builder.outputTokens] with a well-typed [Long] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun outputTokens(outputTokens: JsonField) = apply { + this.outputTokens = outputTokens + } + + /** + * When `group_by=api_key_id`, this field provides the API key ID of the grouped + * usage result. + */ + fun apiKeyId(apiKeyId: String?) = apiKeyId(JsonField.ofNullable(apiKeyId)) + + /** Alias for calling [Builder.apiKeyId] with `apiKeyId.orElse(null)`. */ + fun apiKeyId(apiKeyId: Optional) = apiKeyId(apiKeyId.getOrNull()) + + /** + * Sets [Builder.apiKeyId] to an arbitrary JSON value. + * + * You should usually call [Builder.apiKeyId] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun apiKeyId(apiKeyId: JsonField) = apply { this.apiKeyId = apiKeyId } + + /** + * When `group_by=batch`, this field tells whether the grouped usage result is + * batch or not. + */ + fun batch(batch: Boolean?) = batch(JsonField.ofNullable(batch)) + + /** + * Alias for [Builder.batch]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun batch(batch: Boolean) = batch(batch as Boolean?) + + /** Alias for calling [Builder.batch] with `batch.orElse(null)`. */ + fun batch(batch: Optional) = batch(batch.getOrNull()) + + /** + * Sets [Builder.batch] to an arbitrary JSON value. + * + * You should usually call [Builder.batch] with a well-typed [Boolean] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun batch(batch: JsonField) = apply { this.batch = batch } + + /** + * The aggregated number of audio input tokens used, including cached tokens. + */ + fun inputAudioTokens(inputAudioTokens: Long) = + inputAudioTokens(JsonField.of(inputAudioTokens)) + + /** + * Sets [Builder.inputAudioTokens] to an arbitrary JSON value. + * + * You should usually call [Builder.inputAudioTokens] with a well-typed [Long] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun inputAudioTokens(inputAudioTokens: JsonField) = apply { + this.inputAudioTokens = inputAudioTokens + } + + /** + * The aggregated number of text input tokens that has been cached from previous + * requests. For customers subscribe to scale tier, this includes scale tier + * tokens. + */ + fun inputCachedTokens(inputCachedTokens: Long) = + inputCachedTokens(JsonField.of(inputCachedTokens)) + + /** + * Sets [Builder.inputCachedTokens] to an arbitrary JSON value. + * + * You should usually call [Builder.inputCachedTokens] with a well-typed [Long] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun inputCachedTokens(inputCachedTokens: JsonField) = apply { + this.inputCachedTokens = inputCachedTokens + } + + /** + * When `group_by=model`, this field provides the model name of the grouped + * usage result. + */ + fun model(model: String?) = model(JsonField.ofNullable(model)) + + /** Alias for calling [Builder.model] with `model.orElse(null)`. */ + fun model(model: Optional) = model(model.getOrNull()) + + /** + * Sets [Builder.model] to an arbitrary JSON value. + * + * You should usually call [Builder.model] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun model(model: JsonField) = apply { this.model = model } + + /** The aggregated number of audio output tokens used. */ + fun outputAudioTokens(outputAudioTokens: Long) = + outputAudioTokens(JsonField.of(outputAudioTokens)) + + /** + * Sets [Builder.outputAudioTokens] to an arbitrary JSON value. + * + * You should usually call [Builder.outputAudioTokens] with a well-typed [Long] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun outputAudioTokens(outputAudioTokens: JsonField) = apply { + this.outputAudioTokens = outputAudioTokens + } + + /** + * When `group_by=project_id`, this field provides the project ID of the grouped + * usage result. + */ + fun projectId(projectId: String?) = projectId(JsonField.ofNullable(projectId)) + + /** Alias for calling [Builder.projectId] with `projectId.orElse(null)`. */ + fun projectId(projectId: Optional) = projectId(projectId.getOrNull()) + + /** + * 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 + } + + /** + * When `group_by=service_tier`, this field provides the service tier of the + * grouped usage result. + */ + fun serviceTier(serviceTier: String?) = + serviceTier(JsonField.ofNullable(serviceTier)) + + /** Alias for calling [Builder.serviceTier] with `serviceTier.orElse(null)`. */ + fun serviceTier(serviceTier: Optional) = + serviceTier(serviceTier.getOrNull()) + + /** + * Sets [Builder.serviceTier] to an arbitrary JSON value. + * + * You should usually call [Builder.serviceTier] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun serviceTier(serviceTier: JsonField) = apply { + this.serviceTier = serviceTier + } + + /** + * When `group_by=user_id`, this field provides the user ID of the grouped usage + * result. + */ + 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 } + + 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 [OrganizationUsageCompletionsResult]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .inputTokens() + * .numModelRequests() + * .outputTokens() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): OrganizationUsageCompletionsResult = + OrganizationUsageCompletionsResult( + checkRequired("inputTokens", inputTokens), + checkRequired("numModelRequests", numModelRequests), + object_, + checkRequired("outputTokens", outputTokens), + apiKeyId, + batch, + inputAudioTokens, + inputCachedTokens, + model, + outputAudioTokens, + projectId, + serviceTier, + userId, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing + * fields. + * + * @throws OpenAIInvalidDataException if any value type in this object doesn't match + * its expected type. + */ + fun validate(): OrganizationUsageCompletionsResult = apply { + if (validated) { + return@apply + } + + inputTokens() + numModelRequests() + _object_().let { + if (it != JsonValue.from("organization.usage.completions.result")) { + throw OpenAIInvalidDataException("'object_' is invalid, received $it") + } + } + outputTokens() + apiKeyId() + batch() + inputAudioTokens() + inputCachedTokens() + model() + outputAudioTokens() + projectId() + serviceTier() + userId() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OpenAIInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (if (inputTokens.asKnown().isPresent) 1 else 0) + + (if (numModelRequests.asKnown().isPresent) 1 else 0) + + object_.let { + if (it == JsonValue.from("organization.usage.completions.result")) 1 + else 0 + } + + (if (outputTokens.asKnown().isPresent) 1 else 0) + + (if (apiKeyId.asKnown().isPresent) 1 else 0) + + (if (batch.asKnown().isPresent) 1 else 0) + + (if (inputAudioTokens.asKnown().isPresent) 1 else 0) + + (if (inputCachedTokens.asKnown().isPresent) 1 else 0) + + (if (model.asKnown().isPresent) 1 else 0) + + (if (outputAudioTokens.asKnown().isPresent) 1 else 0) + + (if (projectId.asKnown().isPresent) 1 else 0) + + (if (serviceTier.asKnown().isPresent) 1 else 0) + + (if (userId.asKnown().isPresent) 1 else 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is OrganizationUsageCompletionsResult && + inputTokens == other.inputTokens && + numModelRequests == other.numModelRequests && + object_ == other.object_ && + outputTokens == other.outputTokens && + apiKeyId == other.apiKeyId && + batch == other.batch && + inputAudioTokens == other.inputAudioTokens && + inputCachedTokens == other.inputCachedTokens && + model == other.model && + outputAudioTokens == other.outputAudioTokens && + projectId == other.projectId && + serviceTier == other.serviceTier && + userId == other.userId && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + inputTokens, + numModelRequests, + object_, + outputTokens, + apiKeyId, + batch, + inputAudioTokens, + inputCachedTokens, + model, + outputAudioTokens, + projectId, + serviceTier, + userId, + additionalProperties, + ) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "OrganizationUsageCompletionsResult{inputTokens=$inputTokens, numModelRequests=$numModelRequests, object_=$object_, outputTokens=$outputTokens, apiKeyId=$apiKeyId, batch=$batch, inputAudioTokens=$inputAudioTokens, inputCachedTokens=$inputCachedTokens, model=$model, outputAudioTokens=$outputAudioTokens, projectId=$projectId, serviceTier=$serviceTier, userId=$userId, additionalProperties=$additionalProperties}" + } + + /** The aggregated embeddings usage details of the specific time bucket. */ + class OrganizationUsageEmbeddingsResult + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val inputTokens: JsonField, + private val numModelRequests: JsonField, + private val object_: JsonValue, + private val apiKeyId: JsonField, + private val model: JsonField, + private val projectId: JsonField, + private val userId: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("input_tokens") + @ExcludeMissing + inputTokens: JsonField = JsonMissing.of(), + @JsonProperty("num_model_requests") + @ExcludeMissing + numModelRequests: JsonField = JsonMissing.of(), + @JsonProperty("object") @ExcludeMissing object_: JsonValue = JsonMissing.of(), + @JsonProperty("api_key_id") + @ExcludeMissing + apiKeyId: JsonField = JsonMissing.of(), + @JsonProperty("model") + @ExcludeMissing + model: JsonField = JsonMissing.of(), + @JsonProperty("project_id") + @ExcludeMissing + projectId: JsonField = JsonMissing.of(), + @JsonProperty("user_id") + @ExcludeMissing + userId: JsonField = JsonMissing.of(), + ) : this( + inputTokens, + numModelRequests, + object_, + apiKeyId, + model, + projectId, + userId, + mutableMapOf(), + ) + + /** + * The aggregated number of input tokens used. + * + * @throws OpenAIInvalidDataException 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 inputTokens(): Long = inputTokens.getRequired("input_tokens") + + /** + * The count of requests made to the model. + * + * @throws OpenAIInvalidDataException 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 numModelRequests(): Long = numModelRequests.getRequired("num_model_requests") + + /** + * Expected to always return the following: + * ```java + * JsonValue.from("organization.usage.embeddings.result") + * ``` + * + * However, this method can be useful for debugging and logging (e.g. if the server + * responded with an unexpected value). + */ + @JsonProperty("object") @ExcludeMissing fun _object_(): JsonValue = object_ + + /** + * When `group_by=api_key_id`, this field provides the API key ID of the grouped + * usage result. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun apiKeyId(): Optional = apiKeyId.getOptional("api_key_id") + + /** + * When `group_by=model`, this field provides the model name of the grouped usage + * result. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun model(): Optional = model.getOptional("model") + + /** + * When `group_by=project_id`, this field provides the project ID of the grouped + * usage result. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun projectId(): Optional = projectId.getOptional("project_id") + + /** + * When `group_by=user_id`, this field provides the user ID of the grouped usage + * result. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun userId(): Optional = userId.getOptional("user_id") + + /** + * Returns the raw JSON value of [inputTokens]. + * + * Unlike [inputTokens], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("input_tokens") + @ExcludeMissing + fun _inputTokens(): JsonField = inputTokens + + /** + * Returns the raw JSON value of [numModelRequests]. + * + * Unlike [numModelRequests], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("num_model_requests") + @ExcludeMissing + fun _numModelRequests(): JsonField = numModelRequests + + /** + * Returns the raw JSON value of [apiKeyId]. + * + * Unlike [apiKeyId], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("api_key_id") + @ExcludeMissing + fun _apiKeyId(): JsonField = apiKeyId + + /** + * Returns the raw JSON value of [model]. + * + * Unlike [model], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("model") @ExcludeMissing fun _model(): JsonField = model + + /** + * 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 [userId]. + * + * Unlike [userId], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @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 = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of + * [OrganizationUsageEmbeddingsResult]. + * + * The following fields are required: + * ```java + * .inputTokens() + * .numModelRequests() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [OrganizationUsageEmbeddingsResult]. */ + class Builder internal constructor() { + + private var inputTokens: JsonField? = null + private var numModelRequests: JsonField? = null + private var object_: JsonValue = + JsonValue.from("organization.usage.embeddings.result") + private var apiKeyId: JsonField = JsonMissing.of() + private var model: JsonField = JsonMissing.of() + private var projectId: JsonField = JsonMissing.of() + private var userId: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from( + organizationUsageEmbeddingsResult: OrganizationUsageEmbeddingsResult + ) = apply { + inputTokens = organizationUsageEmbeddingsResult.inputTokens + numModelRequests = organizationUsageEmbeddingsResult.numModelRequests + object_ = organizationUsageEmbeddingsResult.object_ + apiKeyId = organizationUsageEmbeddingsResult.apiKeyId + model = organizationUsageEmbeddingsResult.model + projectId = organizationUsageEmbeddingsResult.projectId + userId = organizationUsageEmbeddingsResult.userId + additionalProperties = + organizationUsageEmbeddingsResult.additionalProperties.toMutableMap() + } + + /** The aggregated number of input tokens used. */ + fun inputTokens(inputTokens: Long) = inputTokens(JsonField.of(inputTokens)) + + /** + * Sets [Builder.inputTokens] to an arbitrary JSON value. + * + * You should usually call [Builder.inputTokens] with a well-typed [Long] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun inputTokens(inputTokens: JsonField) = apply { + this.inputTokens = inputTokens + } + + /** The count of requests made to the model. */ + fun numModelRequests(numModelRequests: Long) = + numModelRequests(JsonField.of(numModelRequests)) + + /** + * Sets [Builder.numModelRequests] to an arbitrary JSON value. + * + * You should usually call [Builder.numModelRequests] with a well-typed [Long] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun numModelRequests(numModelRequests: JsonField) = apply { + this.numModelRequests = numModelRequests + } + + /** + * Sets the field to an arbitrary JSON value. + * + * It is usually unnecessary to call this method because the field defaults to + * the following: + * ```java + * JsonValue.from("organization.usage.embeddings.result") + * ``` + * + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun object_(object_: JsonValue) = apply { this.object_ = object_ } + + /** + * When `group_by=api_key_id`, this field provides the API key ID of the grouped + * usage result. + */ + fun apiKeyId(apiKeyId: String?) = apiKeyId(JsonField.ofNullable(apiKeyId)) + + /** Alias for calling [Builder.apiKeyId] with `apiKeyId.orElse(null)`. */ + fun apiKeyId(apiKeyId: Optional) = apiKeyId(apiKeyId.getOrNull()) + + /** + * Sets [Builder.apiKeyId] to an arbitrary JSON value. + * + * You should usually call [Builder.apiKeyId] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun apiKeyId(apiKeyId: JsonField) = apply { this.apiKeyId = apiKeyId } + + /** + * When `group_by=model`, this field provides the model name of the grouped + * usage result. + */ + fun model(model: String?) = model(JsonField.ofNullable(model)) + + /** Alias for calling [Builder.model] with `model.orElse(null)`. */ + fun model(model: Optional) = model(model.getOrNull()) + + /** + * Sets [Builder.model] to an arbitrary JSON value. + * + * You should usually call [Builder.model] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun model(model: JsonField) = apply { this.model = model } + + /** + * When `group_by=project_id`, this field provides the project ID of the grouped + * usage result. + */ + fun projectId(projectId: String?) = projectId(JsonField.ofNullable(projectId)) + + /** Alias for calling [Builder.projectId] with `projectId.orElse(null)`. */ + fun projectId(projectId: Optional) = projectId(projectId.getOrNull()) + + /** + * 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 + } + + /** + * When `group_by=user_id`, this field provides the user ID of the grouped usage + * result. + */ + 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 } + + 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 [OrganizationUsageEmbeddingsResult]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .inputTokens() + * .numModelRequests() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): OrganizationUsageEmbeddingsResult = + OrganizationUsageEmbeddingsResult( + checkRequired("inputTokens", inputTokens), + checkRequired("numModelRequests", numModelRequests), + object_, + apiKeyId, + model, + projectId, + userId, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing + * fields. + * + * @throws OpenAIInvalidDataException if any value type in this object doesn't match + * its expected type. + */ + fun validate(): OrganizationUsageEmbeddingsResult = apply { + if (validated) { + return@apply + } + + inputTokens() + numModelRequests() + _object_().let { + if (it != JsonValue.from("organization.usage.embeddings.result")) { + throw OpenAIInvalidDataException("'object_' is invalid, received $it") + } + } + apiKeyId() + model() + projectId() + userId() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OpenAIInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (if (inputTokens.asKnown().isPresent) 1 else 0) + + (if (numModelRequests.asKnown().isPresent) 1 else 0) + + object_.let { + if (it == JsonValue.from("organization.usage.embeddings.result")) 1 + else 0 + } + + (if (apiKeyId.asKnown().isPresent) 1 else 0) + + (if (model.asKnown().isPresent) 1 else 0) + + (if (projectId.asKnown().isPresent) 1 else 0) + + (if (userId.asKnown().isPresent) 1 else 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is OrganizationUsageEmbeddingsResult && + inputTokens == other.inputTokens && + numModelRequests == other.numModelRequests && + object_ == other.object_ && + apiKeyId == other.apiKeyId && + model == other.model && + projectId == other.projectId && + userId == other.userId && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + inputTokens, + numModelRequests, + object_, + apiKeyId, + model, + projectId, + userId, + additionalProperties, + ) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "OrganizationUsageEmbeddingsResult{inputTokens=$inputTokens, numModelRequests=$numModelRequests, object_=$object_, apiKeyId=$apiKeyId, model=$model, projectId=$projectId, userId=$userId, additionalProperties=$additionalProperties}" + } + + /** The aggregated moderations usage details of the specific time bucket. */ + class OrganizationUsageModerationsResult + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val inputTokens: JsonField, + private val numModelRequests: JsonField, + private val object_: JsonValue, + private val apiKeyId: JsonField, + private val model: JsonField, + private val projectId: JsonField, + private val userId: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("input_tokens") + @ExcludeMissing + inputTokens: JsonField = JsonMissing.of(), + @JsonProperty("num_model_requests") + @ExcludeMissing + numModelRequests: JsonField = JsonMissing.of(), + @JsonProperty("object") @ExcludeMissing object_: JsonValue = JsonMissing.of(), + @JsonProperty("api_key_id") + @ExcludeMissing + apiKeyId: JsonField = JsonMissing.of(), + @JsonProperty("model") + @ExcludeMissing + model: JsonField = JsonMissing.of(), + @JsonProperty("project_id") + @ExcludeMissing + projectId: JsonField = JsonMissing.of(), + @JsonProperty("user_id") + @ExcludeMissing + userId: JsonField = JsonMissing.of(), + ) : this( + inputTokens, + numModelRequests, + object_, + apiKeyId, + model, + projectId, + userId, + mutableMapOf(), + ) + + /** + * The aggregated number of input tokens used. + * + * @throws OpenAIInvalidDataException 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 inputTokens(): Long = inputTokens.getRequired("input_tokens") + + /** + * The count of requests made to the model. + * + * @throws OpenAIInvalidDataException 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 numModelRequests(): Long = numModelRequests.getRequired("num_model_requests") + + /** + * Expected to always return the following: + * ```java + * JsonValue.from("organization.usage.moderations.result") + * ``` + * + * However, this method can be useful for debugging and logging (e.g. if the server + * responded with an unexpected value). + */ + @JsonProperty("object") @ExcludeMissing fun _object_(): JsonValue = object_ + + /** + * When `group_by=api_key_id`, this field provides the API key ID of the grouped + * usage result. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun apiKeyId(): Optional = apiKeyId.getOptional("api_key_id") + + /** + * When `group_by=model`, this field provides the model name of the grouped usage + * result. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun model(): Optional = model.getOptional("model") + + /** + * When `group_by=project_id`, this field provides the project ID of the grouped + * usage result. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun projectId(): Optional = projectId.getOptional("project_id") + + /** + * When `group_by=user_id`, this field provides the user ID of the grouped usage + * result. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun userId(): Optional = userId.getOptional("user_id") + + /** + * Returns the raw JSON value of [inputTokens]. + * + * Unlike [inputTokens], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("input_tokens") + @ExcludeMissing + fun _inputTokens(): JsonField = inputTokens + + /** + * Returns the raw JSON value of [numModelRequests]. + * + * Unlike [numModelRequests], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("num_model_requests") + @ExcludeMissing + fun _numModelRequests(): JsonField = numModelRequests + + /** + * Returns the raw JSON value of [apiKeyId]. + * + * Unlike [apiKeyId], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("api_key_id") + @ExcludeMissing + fun _apiKeyId(): JsonField = apiKeyId + + /** + * Returns the raw JSON value of [model]. + * + * Unlike [model], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("model") @ExcludeMissing fun _model(): JsonField = model + + /** + * 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 [userId]. + * + * Unlike [userId], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @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 = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of + * [OrganizationUsageModerationsResult]. + * + * The following fields are required: + * ```java + * .inputTokens() + * .numModelRequests() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [OrganizationUsageModerationsResult]. */ + class Builder internal constructor() { + + private var inputTokens: JsonField? = null + private var numModelRequests: JsonField? = null + private var object_: JsonValue = + JsonValue.from("organization.usage.moderations.result") + private var apiKeyId: JsonField = JsonMissing.of() + private var model: JsonField = JsonMissing.of() + private var projectId: JsonField = JsonMissing.of() + private var userId: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from( + organizationUsageModerationsResult: OrganizationUsageModerationsResult + ) = apply { + inputTokens = organizationUsageModerationsResult.inputTokens + numModelRequests = organizationUsageModerationsResult.numModelRequests + object_ = organizationUsageModerationsResult.object_ + apiKeyId = organizationUsageModerationsResult.apiKeyId + model = organizationUsageModerationsResult.model + projectId = organizationUsageModerationsResult.projectId + userId = organizationUsageModerationsResult.userId + additionalProperties = + organizationUsageModerationsResult.additionalProperties.toMutableMap() + } + + /** The aggregated number of input tokens used. */ + fun inputTokens(inputTokens: Long) = inputTokens(JsonField.of(inputTokens)) + + /** + * Sets [Builder.inputTokens] to an arbitrary JSON value. + * + * You should usually call [Builder.inputTokens] with a well-typed [Long] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun inputTokens(inputTokens: JsonField) = apply { + this.inputTokens = inputTokens + } + + /** The count of requests made to the model. */ + fun numModelRequests(numModelRequests: Long) = + numModelRequests(JsonField.of(numModelRequests)) + + /** + * Sets [Builder.numModelRequests] to an arbitrary JSON value. + * + * You should usually call [Builder.numModelRequests] with a well-typed [Long] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun numModelRequests(numModelRequests: JsonField) = apply { + this.numModelRequests = numModelRequests + } + + /** + * Sets the field to an arbitrary JSON value. + * + * It is usually unnecessary to call this method because the field defaults to + * the following: + * ```java + * JsonValue.from("organization.usage.moderations.result") + * ``` + * + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun object_(object_: JsonValue) = apply { this.object_ = object_ } + + /** + * When `group_by=api_key_id`, this field provides the API key ID of the grouped + * usage result. + */ + fun apiKeyId(apiKeyId: String?) = apiKeyId(JsonField.ofNullable(apiKeyId)) + + /** Alias for calling [Builder.apiKeyId] with `apiKeyId.orElse(null)`. */ + fun apiKeyId(apiKeyId: Optional) = apiKeyId(apiKeyId.getOrNull()) + + /** + * Sets [Builder.apiKeyId] to an arbitrary JSON value. + * + * You should usually call [Builder.apiKeyId] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun apiKeyId(apiKeyId: JsonField) = apply { this.apiKeyId = apiKeyId } + + /** + * When `group_by=model`, this field provides the model name of the grouped + * usage result. + */ + fun model(model: String?) = model(JsonField.ofNullable(model)) + + /** Alias for calling [Builder.model] with `model.orElse(null)`. */ + fun model(model: Optional) = model(model.getOrNull()) + + /** + * Sets [Builder.model] to an arbitrary JSON value. + * + * You should usually call [Builder.model] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun model(model: JsonField) = apply { this.model = model } + + /** + * When `group_by=project_id`, this field provides the project ID of the grouped + * usage result. + */ + fun projectId(projectId: String?) = projectId(JsonField.ofNullable(projectId)) + + /** Alias for calling [Builder.projectId] with `projectId.orElse(null)`. */ + fun projectId(projectId: Optional) = projectId(projectId.getOrNull()) + + /** + * 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 + } + + /** + * When `group_by=user_id`, this field provides the user ID of the grouped usage + * result. + */ + 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 } + + 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 [OrganizationUsageModerationsResult]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .inputTokens() + * .numModelRequests() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): OrganizationUsageModerationsResult = + OrganizationUsageModerationsResult( + checkRequired("inputTokens", inputTokens), + checkRequired("numModelRequests", numModelRequests), + object_, + apiKeyId, + model, + projectId, + userId, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing + * fields. + * + * @throws OpenAIInvalidDataException if any value type in this object doesn't match + * its expected type. + */ + fun validate(): OrganizationUsageModerationsResult = apply { + if (validated) { + return@apply + } + + inputTokens() + numModelRequests() + _object_().let { + if (it != JsonValue.from("organization.usage.moderations.result")) { + throw OpenAIInvalidDataException("'object_' is invalid, received $it") + } + } + apiKeyId() + model() + projectId() + userId() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OpenAIInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (if (inputTokens.asKnown().isPresent) 1 else 0) + + (if (numModelRequests.asKnown().isPresent) 1 else 0) + + object_.let { + if (it == JsonValue.from("organization.usage.moderations.result")) 1 + else 0 + } + + (if (apiKeyId.asKnown().isPresent) 1 else 0) + + (if (model.asKnown().isPresent) 1 else 0) + + (if (projectId.asKnown().isPresent) 1 else 0) + + (if (userId.asKnown().isPresent) 1 else 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is OrganizationUsageModerationsResult && + inputTokens == other.inputTokens && + numModelRequests == other.numModelRequests && + object_ == other.object_ && + apiKeyId == other.apiKeyId && + model == other.model && + projectId == other.projectId && + userId == other.userId && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + inputTokens, + numModelRequests, + object_, + apiKeyId, + model, + projectId, + userId, + additionalProperties, + ) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "OrganizationUsageModerationsResult{inputTokens=$inputTokens, numModelRequests=$numModelRequests, object_=$object_, apiKeyId=$apiKeyId, model=$model, projectId=$projectId, userId=$userId, additionalProperties=$additionalProperties}" + } + + /** The aggregated images usage details of the specific time bucket. */ + class OrganizationUsageImagesResult + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val images: JsonField, + private val numModelRequests: JsonField, + private val object_: JsonValue, + private val apiKeyId: JsonField, + private val model: JsonField, + private val projectId: JsonField, + private val size: JsonField, + private val source: JsonField, + private val userId: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("images") + @ExcludeMissing + images: JsonField = JsonMissing.of(), + @JsonProperty("num_model_requests") + @ExcludeMissing + numModelRequests: JsonField = JsonMissing.of(), + @JsonProperty("object") @ExcludeMissing object_: JsonValue = JsonMissing.of(), + @JsonProperty("api_key_id") + @ExcludeMissing + apiKeyId: JsonField = JsonMissing.of(), + @JsonProperty("model") + @ExcludeMissing + model: JsonField = JsonMissing.of(), + @JsonProperty("project_id") + @ExcludeMissing + projectId: JsonField = JsonMissing.of(), + @JsonProperty("size") + @ExcludeMissing + size: JsonField = JsonMissing.of(), + @JsonProperty("source") + @ExcludeMissing + source: JsonField = JsonMissing.of(), + @JsonProperty("user_id") + @ExcludeMissing + userId: JsonField = JsonMissing.of(), + ) : this( + images, + numModelRequests, + object_, + apiKeyId, + model, + projectId, + size, + source, + userId, + mutableMapOf(), + ) + + /** + * The number of images processed. + * + * @throws OpenAIInvalidDataException 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 images(): Long = images.getRequired("images") + + /** + * The count of requests made to the model. + * + * @throws OpenAIInvalidDataException 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 numModelRequests(): Long = numModelRequests.getRequired("num_model_requests") + + /** + * Expected to always return the following: + * ```java + * JsonValue.from("organization.usage.images.result") + * ``` + * + * However, this method can be useful for debugging and logging (e.g. if the server + * responded with an unexpected value). + */ + @JsonProperty("object") @ExcludeMissing fun _object_(): JsonValue = object_ + + /** + * When `group_by=api_key_id`, this field provides the API key ID of the grouped + * usage result. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun apiKeyId(): Optional = apiKeyId.getOptional("api_key_id") + + /** + * When `group_by=model`, this field provides the model name of the grouped usage + * result. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun model(): Optional = model.getOptional("model") + + /** + * When `group_by=project_id`, this field provides the project ID of the grouped + * usage result. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun projectId(): Optional = projectId.getOptional("project_id") + + /** + * When `group_by=size`, this field provides the image size of the grouped usage + * result. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun size(): Optional = size.getOptional("size") + + /** + * When `group_by=source`, this field provides the source of the grouped usage + * result, possible values are `image.generation`, `image.edit`, `image.variation`. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun source(): Optional = source.getOptional("source") + + /** + * When `group_by=user_id`, this field provides the user ID of the grouped usage + * result. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun userId(): Optional = userId.getOptional("user_id") + + /** + * Returns the raw JSON value of [images]. + * + * Unlike [images], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("images") @ExcludeMissing fun _images(): JsonField = images + + /** + * Returns the raw JSON value of [numModelRequests]. + * + * Unlike [numModelRequests], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("num_model_requests") + @ExcludeMissing + fun _numModelRequests(): JsonField = numModelRequests + + /** + * Returns the raw JSON value of [apiKeyId]. + * + * Unlike [apiKeyId], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("api_key_id") + @ExcludeMissing + fun _apiKeyId(): JsonField = apiKeyId + + /** + * Returns the raw JSON value of [model]. + * + * Unlike [model], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("model") @ExcludeMissing fun _model(): JsonField = model + + /** + * 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 [size]. + * + * Unlike [size], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("size") @ExcludeMissing fun _size(): JsonField = size + + /** + * Returns the raw JSON value of [source]. + * + * Unlike [source], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("source") @ExcludeMissing fun _source(): JsonField = source + + /** + * 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 + + @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 + * [OrganizationUsageImagesResult]. + * + * The following fields are required: + * ```java + * .images() + * .numModelRequests() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [OrganizationUsageImagesResult]. */ + class Builder internal constructor() { + + private var images: JsonField? = null + private var numModelRequests: JsonField? = null + private var object_: JsonValue = + JsonValue.from("organization.usage.images.result") + private var apiKeyId: JsonField = JsonMissing.of() + private var model: JsonField = JsonMissing.of() + private var projectId: JsonField = JsonMissing.of() + private var size: JsonField = JsonMissing.of() + private var source: JsonField = JsonMissing.of() + private var userId: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from( + organizationUsageImagesResult: OrganizationUsageImagesResult + ) = apply { + images = organizationUsageImagesResult.images + numModelRequests = organizationUsageImagesResult.numModelRequests + object_ = organizationUsageImagesResult.object_ + apiKeyId = organizationUsageImagesResult.apiKeyId + model = organizationUsageImagesResult.model + projectId = organizationUsageImagesResult.projectId + size = organizationUsageImagesResult.size + source = organizationUsageImagesResult.source + userId = organizationUsageImagesResult.userId + additionalProperties = + organizationUsageImagesResult.additionalProperties.toMutableMap() + } + + /** The number of images processed. */ + fun images(images: Long) = images(JsonField.of(images)) + + /** + * Sets [Builder.images] to an arbitrary JSON value. + * + * You should usually call [Builder.images] with a well-typed [Long] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun images(images: JsonField) = apply { this.images = images } + + /** The count of requests made to the model. */ + fun numModelRequests(numModelRequests: Long) = + numModelRequests(JsonField.of(numModelRequests)) + + /** + * Sets [Builder.numModelRequests] to an arbitrary JSON value. + * + * You should usually call [Builder.numModelRequests] with a well-typed [Long] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun numModelRequests(numModelRequests: JsonField) = apply { + this.numModelRequests = numModelRequests + } + + /** + * Sets the field to an arbitrary JSON value. + * + * It is usually unnecessary to call this method because the field defaults to + * the following: + * ```java + * JsonValue.from("organization.usage.images.result") + * ``` + * + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun object_(object_: JsonValue) = apply { this.object_ = object_ } + + /** + * When `group_by=api_key_id`, this field provides the API key ID of the grouped + * usage result. + */ + fun apiKeyId(apiKeyId: String?) = apiKeyId(JsonField.ofNullable(apiKeyId)) + + /** Alias for calling [Builder.apiKeyId] with `apiKeyId.orElse(null)`. */ + fun apiKeyId(apiKeyId: Optional) = apiKeyId(apiKeyId.getOrNull()) + + /** + * Sets [Builder.apiKeyId] to an arbitrary JSON value. + * + * You should usually call [Builder.apiKeyId] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun apiKeyId(apiKeyId: JsonField) = apply { this.apiKeyId = apiKeyId } + + /** + * When `group_by=model`, this field provides the model name of the grouped + * usage result. + */ + fun model(model: String?) = model(JsonField.ofNullable(model)) + + /** Alias for calling [Builder.model] with `model.orElse(null)`. */ + fun model(model: Optional) = model(model.getOrNull()) + + /** + * Sets [Builder.model] to an arbitrary JSON value. + * + * You should usually call [Builder.model] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun model(model: JsonField) = apply { this.model = model } + + /** + * When `group_by=project_id`, this field provides the project ID of the grouped + * usage result. + */ + fun projectId(projectId: String?) = projectId(JsonField.ofNullable(projectId)) + + /** Alias for calling [Builder.projectId] with `projectId.orElse(null)`. */ + fun projectId(projectId: Optional) = projectId(projectId.getOrNull()) + + /** + * 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 + } + + /** + * When `group_by=size`, this field provides the image size of the grouped usage + * result. + */ + fun size(size: String?) = size(JsonField.ofNullable(size)) + + /** Alias for calling [Builder.size] with `size.orElse(null)`. */ + fun size(size: Optional) = size(size.getOrNull()) + + /** + * Sets [Builder.size] to an arbitrary JSON value. + * + * You should usually call [Builder.size] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun size(size: JsonField) = apply { this.size = size } + + /** + * When `group_by=source`, this field provides the source of the grouped usage + * result, possible values are `image.generation`, `image.edit`, + * `image.variation`. + */ + fun source(source: String?) = source(JsonField.ofNullable(source)) + + /** Alias for calling [Builder.source] with `source.orElse(null)`. */ + fun source(source: Optional) = source(source.getOrNull()) + + /** + * Sets [Builder.source] to an arbitrary JSON value. + * + * You should usually call [Builder.source] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun source(source: JsonField) = apply { this.source = source } + + /** + * When `group_by=user_id`, this field provides the user ID of the grouped usage + * result. + */ + 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 } + + 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 [OrganizationUsageImagesResult]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .images() + * .numModelRequests() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): OrganizationUsageImagesResult = + OrganizationUsageImagesResult( + checkRequired("images", images), + checkRequired("numModelRequests", numModelRequests), + object_, + apiKeyId, + model, + projectId, + size, + source, + userId, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing + * fields. + * + * @throws OpenAIInvalidDataException if any value type in this object doesn't match + * its expected type. + */ + fun validate(): OrganizationUsageImagesResult = apply { + if (validated) { + return@apply + } + + images() + numModelRequests() + _object_().let { + if (it != JsonValue.from("organization.usage.images.result")) { + throw OpenAIInvalidDataException("'object_' is invalid, received $it") + } + } + apiKeyId() + model() + projectId() + size() + source() + userId() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OpenAIInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (if (images.asKnown().isPresent) 1 else 0) + + (if (numModelRequests.asKnown().isPresent) 1 else 0) + + object_.let { + if (it == JsonValue.from("organization.usage.images.result")) 1 else 0 + } + + (if (apiKeyId.asKnown().isPresent) 1 else 0) + + (if (model.asKnown().isPresent) 1 else 0) + + (if (projectId.asKnown().isPresent) 1 else 0) + + (if (size.asKnown().isPresent) 1 else 0) + + (if (source.asKnown().isPresent) 1 else 0) + + (if (userId.asKnown().isPresent) 1 else 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is OrganizationUsageImagesResult && + images == other.images && + numModelRequests == other.numModelRequests && + object_ == other.object_ && + apiKeyId == other.apiKeyId && + model == other.model && + projectId == other.projectId && + size == other.size && + source == other.source && + userId == other.userId && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + images, + numModelRequests, + object_, + apiKeyId, + model, + projectId, + size, + source, + userId, + additionalProperties, + ) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "OrganizationUsageImagesResult{images=$images, numModelRequests=$numModelRequests, object_=$object_, apiKeyId=$apiKeyId, model=$model, projectId=$projectId, size=$size, source=$source, userId=$userId, additionalProperties=$additionalProperties}" + } + + /** The aggregated audio speeches usage details of the specific time bucket. */ + class OrganizationUsageAudioSpeechesResult + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val characters: JsonField, + private val numModelRequests: JsonField, + private val object_: JsonValue, + private val apiKeyId: JsonField, + private val model: JsonField, + private val projectId: JsonField, + private val userId: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("characters") + @ExcludeMissing + characters: JsonField = JsonMissing.of(), + @JsonProperty("num_model_requests") + @ExcludeMissing + numModelRequests: JsonField = JsonMissing.of(), + @JsonProperty("object") @ExcludeMissing object_: JsonValue = JsonMissing.of(), + @JsonProperty("api_key_id") + @ExcludeMissing + apiKeyId: JsonField = JsonMissing.of(), + @JsonProperty("model") + @ExcludeMissing + model: JsonField = JsonMissing.of(), + @JsonProperty("project_id") + @ExcludeMissing + projectId: JsonField = JsonMissing.of(), + @JsonProperty("user_id") + @ExcludeMissing + userId: JsonField = JsonMissing.of(), + ) : this( + characters, + numModelRequests, + object_, + apiKeyId, + model, + projectId, + userId, + mutableMapOf(), + ) + + /** + * The number of characters processed. + * + * @throws OpenAIInvalidDataException 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 characters(): Long = characters.getRequired("characters") + + /** + * The count of requests made to the model. + * + * @throws OpenAIInvalidDataException 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 numModelRequests(): Long = numModelRequests.getRequired("num_model_requests") + + /** + * Expected to always return the following: + * ```java + * JsonValue.from("organization.usage.audio_speeches.result") + * ``` + * + * However, this method can be useful for debugging and logging (e.g. if the server + * responded with an unexpected value). + */ + @JsonProperty("object") @ExcludeMissing fun _object_(): JsonValue = object_ + + /** + * When `group_by=api_key_id`, this field provides the API key ID of the grouped + * usage result. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun apiKeyId(): Optional = apiKeyId.getOptional("api_key_id") + + /** + * When `group_by=model`, this field provides the model name of the grouped usage + * result. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun model(): Optional = model.getOptional("model") + + /** + * When `group_by=project_id`, this field provides the project ID of the grouped + * usage result. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun projectId(): Optional = projectId.getOptional("project_id") + + /** + * When `group_by=user_id`, this field provides the user ID of the grouped usage + * result. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun userId(): Optional = userId.getOptional("user_id") + + /** + * Returns the raw JSON value of [characters]. + * + * Unlike [characters], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("characters") + @ExcludeMissing + fun _characters(): JsonField = characters + + /** + * Returns the raw JSON value of [numModelRequests]. + * + * Unlike [numModelRequests], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("num_model_requests") + @ExcludeMissing + fun _numModelRequests(): JsonField = numModelRequests + + /** + * Returns the raw JSON value of [apiKeyId]. + * + * Unlike [apiKeyId], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("api_key_id") + @ExcludeMissing + fun _apiKeyId(): JsonField = apiKeyId + + /** + * Returns the raw JSON value of [model]. + * + * Unlike [model], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("model") @ExcludeMissing fun _model(): JsonField = model + + /** + * 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 [userId]. + * + * Unlike [userId], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @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 = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of + * [OrganizationUsageAudioSpeechesResult]. + * + * The following fields are required: + * ```java + * .characters() + * .numModelRequests() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [OrganizationUsageAudioSpeechesResult]. */ + class Builder internal constructor() { + + private var characters: JsonField? = null + private var numModelRequests: JsonField? = null + private var object_: JsonValue = + JsonValue.from("organization.usage.audio_speeches.result") + private var apiKeyId: JsonField = JsonMissing.of() + private var model: JsonField = JsonMissing.of() + private var projectId: JsonField = JsonMissing.of() + private var userId: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from( + organizationUsageAudioSpeechesResult: OrganizationUsageAudioSpeechesResult + ) = apply { + characters = organizationUsageAudioSpeechesResult.characters + numModelRequests = organizationUsageAudioSpeechesResult.numModelRequests + object_ = organizationUsageAudioSpeechesResult.object_ + apiKeyId = organizationUsageAudioSpeechesResult.apiKeyId + model = organizationUsageAudioSpeechesResult.model + projectId = organizationUsageAudioSpeechesResult.projectId + userId = organizationUsageAudioSpeechesResult.userId + additionalProperties = + organizationUsageAudioSpeechesResult.additionalProperties.toMutableMap() + } + + /** The number of characters processed. */ + fun characters(characters: Long) = characters(JsonField.of(characters)) + + /** + * Sets [Builder.characters] to an arbitrary JSON value. + * + * You should usually call [Builder.characters] with a well-typed [Long] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun characters(characters: JsonField) = apply { + this.characters = characters + } + + /** The count of requests made to the model. */ + fun numModelRequests(numModelRequests: Long) = + numModelRequests(JsonField.of(numModelRequests)) + + /** + * Sets [Builder.numModelRequests] to an arbitrary JSON value. + * + * You should usually call [Builder.numModelRequests] with a well-typed [Long] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun numModelRequests(numModelRequests: JsonField) = apply { + this.numModelRequests = numModelRequests + } + + /** + * Sets the field to an arbitrary JSON value. + * + * It is usually unnecessary to call this method because the field defaults to + * the following: + * ```java + * JsonValue.from("organization.usage.audio_speeches.result") + * ``` + * + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun object_(object_: JsonValue) = apply { this.object_ = object_ } + + /** + * When `group_by=api_key_id`, this field provides the API key ID of the grouped + * usage result. + */ + fun apiKeyId(apiKeyId: String?) = apiKeyId(JsonField.ofNullable(apiKeyId)) + + /** Alias for calling [Builder.apiKeyId] with `apiKeyId.orElse(null)`. */ + fun apiKeyId(apiKeyId: Optional) = apiKeyId(apiKeyId.getOrNull()) + + /** + * Sets [Builder.apiKeyId] to an arbitrary JSON value. + * + * You should usually call [Builder.apiKeyId] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun apiKeyId(apiKeyId: JsonField) = apply { this.apiKeyId = apiKeyId } + + /** + * When `group_by=model`, this field provides the model name of the grouped + * usage result. + */ + fun model(model: String?) = model(JsonField.ofNullable(model)) + + /** Alias for calling [Builder.model] with `model.orElse(null)`. */ + fun model(model: Optional) = model(model.getOrNull()) + + /** + * Sets [Builder.model] to an arbitrary JSON value. + * + * You should usually call [Builder.model] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun model(model: JsonField) = apply { this.model = model } + + /** + * When `group_by=project_id`, this field provides the project ID of the grouped + * usage result. + */ + fun projectId(projectId: String?) = projectId(JsonField.ofNullable(projectId)) + + /** Alias for calling [Builder.projectId] with `projectId.orElse(null)`. */ + fun projectId(projectId: Optional) = projectId(projectId.getOrNull()) + + /** + * 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 + } + + /** + * When `group_by=user_id`, this field provides the user ID of the grouped usage + * result. + */ + 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 } + + 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 [OrganizationUsageAudioSpeechesResult]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .characters() + * .numModelRequests() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): OrganizationUsageAudioSpeechesResult = + OrganizationUsageAudioSpeechesResult( + checkRequired("characters", characters), + checkRequired("numModelRequests", numModelRequests), + object_, + apiKeyId, + model, + projectId, + userId, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing + * fields. + * + * @throws OpenAIInvalidDataException if any value type in this object doesn't match + * its expected type. + */ + fun validate(): OrganizationUsageAudioSpeechesResult = apply { + if (validated) { + return@apply + } + + characters() + numModelRequests() + _object_().let { + if (it != JsonValue.from("organization.usage.audio_speeches.result")) { + throw OpenAIInvalidDataException("'object_' is invalid, received $it") + } + } + apiKeyId() + model() + projectId() + userId() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OpenAIInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (if (characters.asKnown().isPresent) 1 else 0) + + (if (numModelRequests.asKnown().isPresent) 1 else 0) + + object_.let { + if (it == JsonValue.from("organization.usage.audio_speeches.result")) 1 + else 0 + } + + (if (apiKeyId.asKnown().isPresent) 1 else 0) + + (if (model.asKnown().isPresent) 1 else 0) + + (if (projectId.asKnown().isPresent) 1 else 0) + + (if (userId.asKnown().isPresent) 1 else 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is OrganizationUsageAudioSpeechesResult && + characters == other.characters && + numModelRequests == other.numModelRequests && + object_ == other.object_ && + apiKeyId == other.apiKeyId && + model == other.model && + projectId == other.projectId && + userId == other.userId && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + characters, + numModelRequests, + object_, + apiKeyId, + model, + projectId, + userId, + additionalProperties, + ) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "OrganizationUsageAudioSpeechesResult{characters=$characters, numModelRequests=$numModelRequests, object_=$object_, apiKeyId=$apiKeyId, model=$model, projectId=$projectId, userId=$userId, additionalProperties=$additionalProperties}" + } + + /** The aggregated audio transcriptions usage details of the specific time bucket. */ + class OrganizationUsageAudioTranscriptionsResult + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val numModelRequests: JsonField, + private val object_: JsonValue, + private val seconds: JsonField, + private val apiKeyId: JsonField, + private val model: JsonField, + private val projectId: JsonField, + private val userId: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("num_model_requests") + @ExcludeMissing + numModelRequests: JsonField = JsonMissing.of(), + @JsonProperty("object") @ExcludeMissing object_: JsonValue = JsonMissing.of(), + @JsonProperty("seconds") + @ExcludeMissing + seconds: JsonField = JsonMissing.of(), + @JsonProperty("api_key_id") + @ExcludeMissing + apiKeyId: JsonField = JsonMissing.of(), + @JsonProperty("model") + @ExcludeMissing + model: JsonField = JsonMissing.of(), + @JsonProperty("project_id") + @ExcludeMissing + projectId: JsonField = JsonMissing.of(), + @JsonProperty("user_id") + @ExcludeMissing + userId: JsonField = JsonMissing.of(), + ) : this( + numModelRequests, + object_, + seconds, + apiKeyId, + model, + projectId, + userId, + mutableMapOf(), + ) + + /** + * The count of requests made to the model. + * + * @throws OpenAIInvalidDataException 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 numModelRequests(): Long = numModelRequests.getRequired("num_model_requests") + + /** + * Expected to always return the following: + * ```java + * JsonValue.from("organization.usage.audio_transcriptions.result") + * ``` + * + * However, this method can be useful for debugging and logging (e.g. if the server + * responded with an unexpected value). + */ + @JsonProperty("object") @ExcludeMissing fun _object_(): JsonValue = object_ + + /** + * The number of seconds processed. + * + * @throws OpenAIInvalidDataException 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 seconds(): Long = seconds.getRequired("seconds") + + /** + * When `group_by=api_key_id`, this field provides the API key ID of the grouped + * usage result. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun apiKeyId(): Optional = apiKeyId.getOptional("api_key_id") + + /** + * When `group_by=model`, this field provides the model name of the grouped usage + * result. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun model(): Optional = model.getOptional("model") + + /** + * When `group_by=project_id`, this field provides the project ID of the grouped + * usage result. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun projectId(): Optional = projectId.getOptional("project_id") + + /** + * When `group_by=user_id`, this field provides the user ID of the grouped usage + * result. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun userId(): Optional = userId.getOptional("user_id") + + /** + * Returns the raw JSON value of [numModelRequests]. + * + * Unlike [numModelRequests], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("num_model_requests") + @ExcludeMissing + fun _numModelRequests(): JsonField = numModelRequests + + /** + * Returns the raw JSON value of [seconds]. + * + * Unlike [seconds], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("seconds") @ExcludeMissing fun _seconds(): JsonField = seconds + + /** + * Returns the raw JSON value of [apiKeyId]. + * + * Unlike [apiKeyId], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("api_key_id") + @ExcludeMissing + fun _apiKeyId(): JsonField = apiKeyId + + /** + * Returns the raw JSON value of [model]. + * + * Unlike [model], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("model") @ExcludeMissing fun _model(): JsonField = model + + /** + * 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 [userId]. + * + * Unlike [userId], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @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 = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of + * [OrganizationUsageAudioTranscriptionsResult]. + * + * The following fields are required: + * ```java + * .numModelRequests() + * .seconds() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [OrganizationUsageAudioTranscriptionsResult]. */ + class Builder internal constructor() { + + private var numModelRequests: JsonField? = null + private var object_: JsonValue = + JsonValue.from("organization.usage.audio_transcriptions.result") + private var seconds: JsonField? = null + private var apiKeyId: JsonField = JsonMissing.of() + private var model: JsonField = JsonMissing.of() + private var projectId: JsonField = JsonMissing.of() + private var userId: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from( + organizationUsageAudioTranscriptionsResult: + OrganizationUsageAudioTranscriptionsResult + ) = apply { + numModelRequests = + organizationUsageAudioTranscriptionsResult.numModelRequests + object_ = organizationUsageAudioTranscriptionsResult.object_ + seconds = organizationUsageAudioTranscriptionsResult.seconds + apiKeyId = organizationUsageAudioTranscriptionsResult.apiKeyId + model = organizationUsageAudioTranscriptionsResult.model + projectId = organizationUsageAudioTranscriptionsResult.projectId + userId = organizationUsageAudioTranscriptionsResult.userId + additionalProperties = + organizationUsageAudioTranscriptionsResult.additionalProperties + .toMutableMap() + } + + /** The count of requests made to the model. */ + fun numModelRequests(numModelRequests: Long) = + numModelRequests(JsonField.of(numModelRequests)) + + /** + * Sets [Builder.numModelRequests] to an arbitrary JSON value. + * + * You should usually call [Builder.numModelRequests] with a well-typed [Long] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun numModelRequests(numModelRequests: JsonField) = apply { + this.numModelRequests = numModelRequests + } + + /** + * Sets the field to an arbitrary JSON value. + * + * It is usually unnecessary to call this method because the field defaults to + * the following: + * ```java + * JsonValue.from("organization.usage.audio_transcriptions.result") + * ``` + * + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun object_(object_: JsonValue) = apply { this.object_ = object_ } + + /** The number of seconds processed. */ + fun seconds(seconds: Long) = seconds(JsonField.of(seconds)) + + /** + * Sets [Builder.seconds] to an arbitrary JSON value. + * + * You should usually call [Builder.seconds] with a well-typed [Long] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun seconds(seconds: JsonField) = apply { this.seconds = seconds } + + /** + * When `group_by=api_key_id`, this field provides the API key ID of the grouped + * usage result. + */ + fun apiKeyId(apiKeyId: String?) = apiKeyId(JsonField.ofNullable(apiKeyId)) + + /** Alias for calling [Builder.apiKeyId] with `apiKeyId.orElse(null)`. */ + fun apiKeyId(apiKeyId: Optional) = apiKeyId(apiKeyId.getOrNull()) + + /** + * Sets [Builder.apiKeyId] to an arbitrary JSON value. + * + * You should usually call [Builder.apiKeyId] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun apiKeyId(apiKeyId: JsonField) = apply { this.apiKeyId = apiKeyId } + + /** + * When `group_by=model`, this field provides the model name of the grouped + * usage result. + */ + fun model(model: String?) = model(JsonField.ofNullable(model)) + + /** Alias for calling [Builder.model] with `model.orElse(null)`. */ + fun model(model: Optional) = model(model.getOrNull()) + + /** + * Sets [Builder.model] to an arbitrary JSON value. + * + * You should usually call [Builder.model] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun model(model: JsonField) = apply { this.model = model } + + /** + * When `group_by=project_id`, this field provides the project ID of the grouped + * usage result. + */ + fun projectId(projectId: String?) = projectId(JsonField.ofNullable(projectId)) + + /** Alias for calling [Builder.projectId] with `projectId.orElse(null)`. */ + fun projectId(projectId: Optional) = projectId(projectId.getOrNull()) + + /** + * 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 + } + + /** + * When `group_by=user_id`, this field provides the user ID of the grouped usage + * result. + */ + 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 } + + 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 + * [OrganizationUsageAudioTranscriptionsResult]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .numModelRequests() + * .seconds() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): OrganizationUsageAudioTranscriptionsResult = + OrganizationUsageAudioTranscriptionsResult( + checkRequired("numModelRequests", numModelRequests), + object_, + checkRequired("seconds", seconds), + apiKeyId, + model, + projectId, + userId, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing + * fields. + * + * @throws OpenAIInvalidDataException if any value type in this object doesn't match + * its expected type. + */ + fun validate(): OrganizationUsageAudioTranscriptionsResult = apply { + if (validated) { + return@apply + } + + numModelRequests() + _object_().let { + if ( + it != JsonValue.from("organization.usage.audio_transcriptions.result") + ) { + throw OpenAIInvalidDataException("'object_' is invalid, received $it") + } + } + seconds() + apiKeyId() + model() + projectId() + userId() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OpenAIInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (if (numModelRequests.asKnown().isPresent) 1 else 0) + + object_.let { + if ( + it == + JsonValue.from("organization.usage.audio_transcriptions.result") + ) + 1 + else 0 + } + + (if (seconds.asKnown().isPresent) 1 else 0) + + (if (apiKeyId.asKnown().isPresent) 1 else 0) + + (if (model.asKnown().isPresent) 1 else 0) + + (if (projectId.asKnown().isPresent) 1 else 0) + + (if (userId.asKnown().isPresent) 1 else 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is OrganizationUsageAudioTranscriptionsResult && + numModelRequests == other.numModelRequests && + object_ == other.object_ && + seconds == other.seconds && + apiKeyId == other.apiKeyId && + model == other.model && + projectId == other.projectId && + userId == other.userId && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + numModelRequests, + object_, + seconds, + apiKeyId, + model, + projectId, + userId, + additionalProperties, + ) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "OrganizationUsageAudioTranscriptionsResult{numModelRequests=$numModelRequests, object_=$object_, seconds=$seconds, apiKeyId=$apiKeyId, model=$model, projectId=$projectId, userId=$userId, additionalProperties=$additionalProperties}" + } + + /** The aggregated vector stores usage details of the specific time bucket. */ + class OrganizationUsageVectorStoresResult + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val object_: JsonValue, + private val usageBytes: JsonField, + private val projectId: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("object") @ExcludeMissing object_: JsonValue = JsonMissing.of(), + @JsonProperty("usage_bytes") + @ExcludeMissing + usageBytes: JsonField = JsonMissing.of(), + @JsonProperty("project_id") + @ExcludeMissing + projectId: JsonField = JsonMissing.of(), + ) : this(object_, usageBytes, projectId, mutableMapOf()) + + /** + * Expected to always return the following: + * ```java + * JsonValue.from("organization.usage.vector_stores.result") + * ``` + * + * However, this method can be useful for debugging and logging (e.g. if the server + * responded with an unexpected value). + */ + @JsonProperty("object") @ExcludeMissing fun _object_(): JsonValue = object_ + + /** + * The vector stores usage in bytes. + * + * @throws OpenAIInvalidDataException 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 usageBytes(): Long = usageBytes.getRequired("usage_bytes") + + /** + * When `group_by=project_id`, this field provides the project ID of the grouped + * usage result. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun projectId(): Optional = projectId.getOptional("project_id") + + /** + * Returns the raw JSON value of [usageBytes]. + * + * Unlike [usageBytes], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("usage_bytes") + @ExcludeMissing + fun _usageBytes(): JsonField = usageBytes + + /** + * 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 + + @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 + * [OrganizationUsageVectorStoresResult]. + * + * The following fields are required: + * ```java + * .usageBytes() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [OrganizationUsageVectorStoresResult]. */ + class Builder internal constructor() { + + private var object_: JsonValue = + JsonValue.from("organization.usage.vector_stores.result") + private var usageBytes: JsonField? = null + private var projectId: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from( + organizationUsageVectorStoresResult: OrganizationUsageVectorStoresResult + ) = apply { + object_ = organizationUsageVectorStoresResult.object_ + usageBytes = organizationUsageVectorStoresResult.usageBytes + projectId = organizationUsageVectorStoresResult.projectId + additionalProperties = + organizationUsageVectorStoresResult.additionalProperties.toMutableMap() + } + + /** + * Sets the field to an arbitrary JSON value. + * + * It is usually unnecessary to call this method because the field defaults to + * the following: + * ```java + * JsonValue.from("organization.usage.vector_stores.result") + * ``` + * + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun object_(object_: JsonValue) = apply { this.object_ = object_ } + + /** The vector stores usage in bytes. */ + fun usageBytes(usageBytes: Long) = usageBytes(JsonField.of(usageBytes)) + + /** + * Sets [Builder.usageBytes] to an arbitrary JSON value. + * + * You should usually call [Builder.usageBytes] with a well-typed [Long] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun usageBytes(usageBytes: JsonField) = apply { + this.usageBytes = usageBytes + } + + /** + * When `group_by=project_id`, this field provides the project ID of the grouped + * usage result. + */ + fun projectId(projectId: String?) = projectId(JsonField.ofNullable(projectId)) + + /** Alias for calling [Builder.projectId] with `projectId.orElse(null)`. */ + fun projectId(projectId: Optional) = projectId(projectId.getOrNull()) + + /** + * 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 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 [OrganizationUsageVectorStoresResult]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .usageBytes() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): OrganizationUsageVectorStoresResult = + OrganizationUsageVectorStoresResult( + object_, + checkRequired("usageBytes", usageBytes), + projectId, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing + * fields. + * + * @throws OpenAIInvalidDataException if any value type in this object doesn't match + * its expected type. + */ + fun validate(): OrganizationUsageVectorStoresResult = apply { + if (validated) { + return@apply + } + + _object_().let { + if (it != JsonValue.from("organization.usage.vector_stores.result")) { + throw OpenAIInvalidDataException("'object_' is invalid, received $it") + } + } + usageBytes() + projectId() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OpenAIInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + object_.let { + if (it == JsonValue.from("organization.usage.vector_stores.result")) 1 + else 0 + } + + (if (usageBytes.asKnown().isPresent) 1 else 0) + + (if (projectId.asKnown().isPresent) 1 else 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is OrganizationUsageVectorStoresResult && + object_ == other.object_ && + usageBytes == other.usageBytes && + projectId == other.projectId && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(object_, usageBytes, projectId, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "OrganizationUsageVectorStoresResult{object_=$object_, usageBytes=$usageBytes, projectId=$projectId, additionalProperties=$additionalProperties}" + } + + /** + * The aggregated code interpreter sessions usage details of the specific time bucket. + */ + class OrganizationUsageCodeInterpreterSessionsResult + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val numSessions: JsonField, + private val object_: JsonValue, + private val projectId: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("num_sessions") + @ExcludeMissing + numSessions: JsonField = JsonMissing.of(), + @JsonProperty("object") @ExcludeMissing object_: JsonValue = JsonMissing.of(), + @JsonProperty("project_id") + @ExcludeMissing + projectId: JsonField = JsonMissing.of(), + ) : this(numSessions, object_, projectId, mutableMapOf()) + + /** + * The number of code interpreter sessions. + * + * @throws OpenAIInvalidDataException 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 numSessions(): Long = numSessions.getRequired("num_sessions") + + /** + * Expected to always return the following: + * ```java + * JsonValue.from("organization.usage.code_interpreter_sessions.result") + * ``` + * + * However, this method can be useful for debugging and logging (e.g. if the server + * responded with an unexpected value). + */ + @JsonProperty("object") @ExcludeMissing fun _object_(): JsonValue = object_ + + /** + * When `group_by=project_id`, this field provides the project ID of the grouped + * usage result. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun projectId(): Optional = projectId.getOptional("project_id") + + /** + * Returns the raw JSON value of [numSessions]. + * + * Unlike [numSessions], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("num_sessions") + @ExcludeMissing + fun _numSessions(): JsonField = numSessions + + /** + * 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 + + @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 + * [OrganizationUsageCodeInterpreterSessionsResult]. + * + * The following fields are required: + * ```java + * .numSessions() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [OrganizationUsageCodeInterpreterSessionsResult]. */ + class Builder internal constructor() { + + private var numSessions: JsonField? = null + private var object_: JsonValue = + JsonValue.from("organization.usage.code_interpreter_sessions.result") + private var projectId: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from( + organizationUsageCodeInterpreterSessionsResult: + OrganizationUsageCodeInterpreterSessionsResult + ) = apply { + numSessions = organizationUsageCodeInterpreterSessionsResult.numSessions + object_ = organizationUsageCodeInterpreterSessionsResult.object_ + projectId = organizationUsageCodeInterpreterSessionsResult.projectId + additionalProperties = + organizationUsageCodeInterpreterSessionsResult.additionalProperties + .toMutableMap() + } + + /** The number of code interpreter sessions. */ + fun numSessions(numSessions: Long) = numSessions(JsonField.of(numSessions)) + + /** + * Sets [Builder.numSessions] to an arbitrary JSON value. + * + * You should usually call [Builder.numSessions] with a well-typed [Long] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun numSessions(numSessions: JsonField) = apply { + this.numSessions = numSessions + } + + /** + * Sets the field to an arbitrary JSON value. + * + * It is usually unnecessary to call this method because the field defaults to + * the following: + * ```java + * JsonValue.from("organization.usage.code_interpreter_sessions.result") + * ``` + * + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun object_(object_: JsonValue) = apply { this.object_ = object_ } + + /** + * When `group_by=project_id`, this field provides the project ID of the grouped + * usage result. + */ + fun projectId(projectId: String?) = projectId(JsonField.ofNullable(projectId)) + + /** Alias for calling [Builder.projectId] with `projectId.orElse(null)`. */ + fun projectId(projectId: Optional) = projectId(projectId.getOrNull()) + + /** + * 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 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 + * [OrganizationUsageCodeInterpreterSessionsResult]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .numSessions() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): OrganizationUsageCodeInterpreterSessionsResult = + OrganizationUsageCodeInterpreterSessionsResult( + checkRequired("numSessions", numSessions), + object_, + projectId, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing + * fields. + * + * @throws OpenAIInvalidDataException if any value type in this object doesn't match + * its expected type. + */ + fun validate(): OrganizationUsageCodeInterpreterSessionsResult = apply { + if (validated) { + return@apply + } + + numSessions() + _object_().let { + if ( + it != + JsonValue.from( + "organization.usage.code_interpreter_sessions.result" + ) + ) { + throw OpenAIInvalidDataException("'object_' is invalid, received $it") + } + } + projectId() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OpenAIInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (if (numSessions.asKnown().isPresent) 1 else 0) + + object_.let { + if ( + it == + JsonValue.from( + "organization.usage.code_interpreter_sessions.result" + ) + ) + 1 + else 0 + } + + (if (projectId.asKnown().isPresent) 1 else 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is OrganizationUsageCodeInterpreterSessionsResult && + numSessions == other.numSessions && + object_ == other.object_ && + projectId == other.projectId && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(numSessions, object_, projectId, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "OrganizationUsageCodeInterpreterSessionsResult{numSessions=$numSessions, object_=$object_, projectId=$projectId, additionalProperties=$additionalProperties}" + } + + /** The aggregated file search calls usage details of the specific time bucket. */ + class OrganizationUsageFileSearchesResult + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val numRequests: JsonField, + private val object_: JsonValue, + private val apiKeyId: JsonField, + private val projectId: JsonField, + private val userId: JsonField, + private val vectorStoreId: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("num_requests") + @ExcludeMissing + numRequests: JsonField = JsonMissing.of(), + @JsonProperty("object") @ExcludeMissing object_: JsonValue = JsonMissing.of(), + @JsonProperty("api_key_id") + @ExcludeMissing + apiKeyId: JsonField = JsonMissing.of(), + @JsonProperty("project_id") + @ExcludeMissing + projectId: JsonField = JsonMissing.of(), + @JsonProperty("user_id") + @ExcludeMissing + userId: JsonField = JsonMissing.of(), + @JsonProperty("vector_store_id") + @ExcludeMissing + vectorStoreId: JsonField = JsonMissing.of(), + ) : this( + numRequests, + object_, + apiKeyId, + projectId, + userId, + vectorStoreId, + mutableMapOf(), + ) + + /** + * The count of file search calls. + * + * @throws OpenAIInvalidDataException 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 numRequests(): Long = numRequests.getRequired("num_requests") + + /** + * Expected to always return the following: + * ```java + * JsonValue.from("organization.usage.file_searches.result") + * ``` + * + * However, this method can be useful for debugging and logging (e.g. if the server + * responded with an unexpected value). + */ + @JsonProperty("object") @ExcludeMissing fun _object_(): JsonValue = object_ + + /** + * When `group_by=api_key_id`, this field provides the API key ID of the grouped + * usage result. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun apiKeyId(): Optional = apiKeyId.getOptional("api_key_id") + + /** + * When `group_by=project_id`, this field provides the project ID of the grouped + * usage result. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun projectId(): Optional = projectId.getOptional("project_id") + + /** + * When `group_by=user_id`, this field provides the user ID of the grouped usage + * result. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun userId(): Optional = userId.getOptional("user_id") + + /** + * When `group_by=vector_store_id`, this field provides the vector store ID of the + * grouped usage result. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun vectorStoreId(): Optional = vectorStoreId.getOptional("vector_store_id") + + /** + * Returns the raw JSON value of [numRequests]. + * + * Unlike [numRequests], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("num_requests") + @ExcludeMissing + fun _numRequests(): JsonField = numRequests + + /** + * Returns the raw JSON value of [apiKeyId]. + * + * Unlike [apiKeyId], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("api_key_id") + @ExcludeMissing + fun _apiKeyId(): JsonField = apiKeyId + + /** + * 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 [userId]. + * + * Unlike [userId], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("user_id") @ExcludeMissing fun _userId(): JsonField = userId + + /** + * Returns the raw JSON value of [vectorStoreId]. + * + * Unlike [vectorStoreId], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("vector_store_id") + @ExcludeMissing + fun _vectorStoreId(): JsonField = vectorStoreId + + @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 + * [OrganizationUsageFileSearchesResult]. + * + * The following fields are required: + * ```java + * .numRequests() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [OrganizationUsageFileSearchesResult]. */ + class Builder internal constructor() { + + private var numRequests: JsonField? = null + private var object_: JsonValue = + JsonValue.from("organization.usage.file_searches.result") + private var apiKeyId: JsonField = JsonMissing.of() + private var projectId: JsonField = JsonMissing.of() + private var userId: JsonField = JsonMissing.of() + private var vectorStoreId: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from( + organizationUsageFileSearchesResult: OrganizationUsageFileSearchesResult + ) = apply { + numRequests = organizationUsageFileSearchesResult.numRequests + object_ = organizationUsageFileSearchesResult.object_ + apiKeyId = organizationUsageFileSearchesResult.apiKeyId + projectId = organizationUsageFileSearchesResult.projectId + userId = organizationUsageFileSearchesResult.userId + vectorStoreId = organizationUsageFileSearchesResult.vectorStoreId + additionalProperties = + organizationUsageFileSearchesResult.additionalProperties.toMutableMap() + } + + /** The count of file search calls. */ + fun numRequests(numRequests: Long) = numRequests(JsonField.of(numRequests)) + + /** + * Sets [Builder.numRequests] to an arbitrary JSON value. + * + * You should usually call [Builder.numRequests] with a well-typed [Long] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun numRequests(numRequests: JsonField) = apply { + this.numRequests = numRequests + } + + /** + * Sets the field to an arbitrary JSON value. + * + * It is usually unnecessary to call this method because the field defaults to + * the following: + * ```java + * JsonValue.from("organization.usage.file_searches.result") + * ``` + * + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun object_(object_: JsonValue) = apply { this.object_ = object_ } + + /** + * When `group_by=api_key_id`, this field provides the API key ID of the grouped + * usage result. + */ + fun apiKeyId(apiKeyId: String?) = apiKeyId(JsonField.ofNullable(apiKeyId)) + + /** Alias for calling [Builder.apiKeyId] with `apiKeyId.orElse(null)`. */ + fun apiKeyId(apiKeyId: Optional) = apiKeyId(apiKeyId.getOrNull()) + + /** + * Sets [Builder.apiKeyId] to an arbitrary JSON value. + * + * You should usually call [Builder.apiKeyId] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun apiKeyId(apiKeyId: JsonField) = apply { this.apiKeyId = apiKeyId } + + /** + * When `group_by=project_id`, this field provides the project ID of the grouped + * usage result. + */ + fun projectId(projectId: String?) = projectId(JsonField.ofNullable(projectId)) + + /** Alias for calling [Builder.projectId] with `projectId.orElse(null)`. */ + fun projectId(projectId: Optional) = projectId(projectId.getOrNull()) + + /** + * 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 + } + + /** + * When `group_by=user_id`, this field provides the user ID of the grouped usage + * result. + */ + 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 } + + /** + * When `group_by=vector_store_id`, this field provides the vector store ID of + * the grouped usage result. + */ + fun vectorStoreId(vectorStoreId: String?) = + vectorStoreId(JsonField.ofNullable(vectorStoreId)) + + /** + * Alias for calling [Builder.vectorStoreId] with `vectorStoreId.orElse(null)`. + */ + fun vectorStoreId(vectorStoreId: Optional) = + vectorStoreId(vectorStoreId.getOrNull()) + + /** + * Sets [Builder.vectorStoreId] to an arbitrary JSON value. + * + * You should usually call [Builder.vectorStoreId] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun vectorStoreId(vectorStoreId: JsonField) = apply { + this.vectorStoreId = vectorStoreId + } + + 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 [OrganizationUsageFileSearchesResult]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .numRequests() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): OrganizationUsageFileSearchesResult = + OrganizationUsageFileSearchesResult( + checkRequired("numRequests", numRequests), + object_, + apiKeyId, + projectId, + userId, + vectorStoreId, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing + * fields. + * + * @throws OpenAIInvalidDataException if any value type in this object doesn't match + * its expected type. + */ + fun validate(): OrganizationUsageFileSearchesResult = apply { + if (validated) { + return@apply + } + + numRequests() + _object_().let { + if (it != JsonValue.from("organization.usage.file_searches.result")) { + throw OpenAIInvalidDataException("'object_' is invalid, received $it") + } + } + apiKeyId() + projectId() + userId() + vectorStoreId() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OpenAIInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (if (numRequests.asKnown().isPresent) 1 else 0) + + object_.let { + if (it == JsonValue.from("organization.usage.file_searches.result")) 1 + else 0 + } + + (if (apiKeyId.asKnown().isPresent) 1 else 0) + + (if (projectId.asKnown().isPresent) 1 else 0) + + (if (userId.asKnown().isPresent) 1 else 0) + + (if (vectorStoreId.asKnown().isPresent) 1 else 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is OrganizationUsageFileSearchesResult && + numRequests == other.numRequests && + object_ == other.object_ && + apiKeyId == other.apiKeyId && + projectId == other.projectId && + userId == other.userId && + vectorStoreId == other.vectorStoreId && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + numRequests, + object_, + apiKeyId, + projectId, + userId, + vectorStoreId, + additionalProperties, + ) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "OrganizationUsageFileSearchesResult{numRequests=$numRequests, object_=$object_, apiKeyId=$apiKeyId, projectId=$projectId, userId=$userId, vectorStoreId=$vectorStoreId, additionalProperties=$additionalProperties}" + } + + /** The aggregated web search calls usage details of the specific time bucket. */ + class OrganizationUsageWebSearchesResult + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val numModelRequests: JsonField, + private val numRequests: JsonField, + private val object_: JsonValue, + private val apiKeyId: JsonField, + private val contextLevel: JsonField, + private val model: JsonField, + private val projectId: JsonField, + private val userId: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("num_model_requests") + @ExcludeMissing + numModelRequests: JsonField = JsonMissing.of(), + @JsonProperty("num_requests") + @ExcludeMissing + numRequests: JsonField = JsonMissing.of(), + @JsonProperty("object") @ExcludeMissing object_: JsonValue = JsonMissing.of(), + @JsonProperty("api_key_id") + @ExcludeMissing + apiKeyId: JsonField = JsonMissing.of(), + @JsonProperty("context_level") + @ExcludeMissing + contextLevel: JsonField = JsonMissing.of(), + @JsonProperty("model") + @ExcludeMissing + model: JsonField = JsonMissing.of(), + @JsonProperty("project_id") + @ExcludeMissing + projectId: JsonField = JsonMissing.of(), + @JsonProperty("user_id") + @ExcludeMissing + userId: JsonField = JsonMissing.of(), + ) : this( + numModelRequests, + numRequests, + object_, + apiKeyId, + contextLevel, + model, + projectId, + userId, + mutableMapOf(), + ) + + /** + * The count of model requests. + * + * @throws OpenAIInvalidDataException 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 numModelRequests(): Long = numModelRequests.getRequired("num_model_requests") + + /** + * The count of web search calls. + * + * @throws OpenAIInvalidDataException 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 numRequests(): Long = numRequests.getRequired("num_requests") + + /** + * Expected to always return the following: + * ```java + * JsonValue.from("organization.usage.web_searches.result") + * ``` + * + * However, this method can be useful for debugging and logging (e.g. if the server + * responded with an unexpected value). + */ + @JsonProperty("object") @ExcludeMissing fun _object_(): JsonValue = object_ + + /** + * When `group_by=api_key_id`, this field provides the API key ID of the grouped + * usage result. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun apiKeyId(): Optional = apiKeyId.getOptional("api_key_id") + + /** + * When `group_by=context_level`, this field provides the search context size of the + * grouped usage result. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun contextLevel(): Optional = contextLevel.getOptional("context_level") + + /** + * When `group_by=model`, this field provides the model name of the grouped usage + * result. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun model(): Optional = model.getOptional("model") + + /** + * When `group_by=project_id`, this field provides the project ID of the grouped + * usage result. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun projectId(): Optional = projectId.getOptional("project_id") + + /** + * When `group_by=user_id`, this field provides the user ID of the grouped usage + * result. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun userId(): Optional = userId.getOptional("user_id") + + /** + * Returns the raw JSON value of [numModelRequests]. + * + * Unlike [numModelRequests], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("num_model_requests") + @ExcludeMissing + fun _numModelRequests(): JsonField = numModelRequests + + /** + * Returns the raw JSON value of [numRequests]. + * + * Unlike [numRequests], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("num_requests") + @ExcludeMissing + fun _numRequests(): JsonField = numRequests + + /** + * Returns the raw JSON value of [apiKeyId]. + * + * Unlike [apiKeyId], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("api_key_id") + @ExcludeMissing + fun _apiKeyId(): JsonField = apiKeyId + + /** + * Returns the raw JSON value of [contextLevel]. + * + * Unlike [contextLevel], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("context_level") + @ExcludeMissing + fun _contextLevel(): JsonField = contextLevel + + /** + * Returns the raw JSON value of [model]. + * + * Unlike [model], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("model") @ExcludeMissing fun _model(): JsonField = model + + /** + * 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 [userId]. + * + * Unlike [userId], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @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 = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of + * [OrganizationUsageWebSearchesResult]. + * + * The following fields are required: + * ```java + * .numModelRequests() + * .numRequests() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [OrganizationUsageWebSearchesResult]. */ + class Builder internal constructor() { + + private var numModelRequests: JsonField? = null + private var numRequests: JsonField? = null + private var object_: JsonValue = + JsonValue.from("organization.usage.web_searches.result") + private var apiKeyId: JsonField = JsonMissing.of() + private var contextLevel: JsonField = JsonMissing.of() + private var model: JsonField = JsonMissing.of() + private var projectId: JsonField = JsonMissing.of() + private var userId: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from( + organizationUsageWebSearchesResult: OrganizationUsageWebSearchesResult + ) = apply { + numModelRequests = organizationUsageWebSearchesResult.numModelRequests + numRequests = organizationUsageWebSearchesResult.numRequests + object_ = organizationUsageWebSearchesResult.object_ + apiKeyId = organizationUsageWebSearchesResult.apiKeyId + contextLevel = organizationUsageWebSearchesResult.contextLevel + model = organizationUsageWebSearchesResult.model + projectId = organizationUsageWebSearchesResult.projectId + userId = organizationUsageWebSearchesResult.userId + additionalProperties = + organizationUsageWebSearchesResult.additionalProperties.toMutableMap() + } + + /** The count of model requests. */ + fun numModelRequests(numModelRequests: Long) = + numModelRequests(JsonField.of(numModelRequests)) + + /** + * Sets [Builder.numModelRequests] to an arbitrary JSON value. + * + * You should usually call [Builder.numModelRequests] with a well-typed [Long] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun numModelRequests(numModelRequests: JsonField) = apply { + this.numModelRequests = numModelRequests + } + + /** The count of web search calls. */ + fun numRequests(numRequests: Long) = numRequests(JsonField.of(numRequests)) + + /** + * Sets [Builder.numRequests] to an arbitrary JSON value. + * + * You should usually call [Builder.numRequests] with a well-typed [Long] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun numRequests(numRequests: JsonField) = apply { + this.numRequests = numRequests + } + + /** + * Sets the field to an arbitrary JSON value. + * + * It is usually unnecessary to call this method because the field defaults to + * the following: + * ```java + * JsonValue.from("organization.usage.web_searches.result") + * ``` + * + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun object_(object_: JsonValue) = apply { this.object_ = object_ } + + /** + * When `group_by=api_key_id`, this field provides the API key ID of the grouped + * usage result. + */ + fun apiKeyId(apiKeyId: String?) = apiKeyId(JsonField.ofNullable(apiKeyId)) + + /** Alias for calling [Builder.apiKeyId] with `apiKeyId.orElse(null)`. */ + fun apiKeyId(apiKeyId: Optional) = apiKeyId(apiKeyId.getOrNull()) + + /** + * Sets [Builder.apiKeyId] to an arbitrary JSON value. + * + * You should usually call [Builder.apiKeyId] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun apiKeyId(apiKeyId: JsonField) = apply { this.apiKeyId = apiKeyId } + + /** + * When `group_by=context_level`, this field provides the search context size of + * the grouped usage result. + */ + fun contextLevel(contextLevel: String?) = + contextLevel(JsonField.ofNullable(contextLevel)) + + /** + * Alias for calling [Builder.contextLevel] with `contextLevel.orElse(null)`. + */ + fun contextLevel(contextLevel: Optional) = + contextLevel(contextLevel.getOrNull()) + + /** + * Sets [Builder.contextLevel] to an arbitrary JSON value. + * + * You should usually call [Builder.contextLevel] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun contextLevel(contextLevel: JsonField) = apply { + this.contextLevel = contextLevel + } + + /** + * When `group_by=model`, this field provides the model name of the grouped + * usage result. + */ + fun model(model: String?) = model(JsonField.ofNullable(model)) + + /** Alias for calling [Builder.model] with `model.orElse(null)`. */ + fun model(model: Optional) = model(model.getOrNull()) + + /** + * Sets [Builder.model] to an arbitrary JSON value. + * + * You should usually call [Builder.model] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun model(model: JsonField) = apply { this.model = model } + + /** + * When `group_by=project_id`, this field provides the project ID of the grouped + * usage result. + */ + fun projectId(projectId: String?) = projectId(JsonField.ofNullable(projectId)) + + /** Alias for calling [Builder.projectId] with `projectId.orElse(null)`. */ + fun projectId(projectId: Optional) = projectId(projectId.getOrNull()) + + /** + * 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 + } + + /** + * When `group_by=user_id`, this field provides the user ID of the grouped usage + * result. + */ + 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 } + + 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 [OrganizationUsageWebSearchesResult]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .numModelRequests() + * .numRequests() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): OrganizationUsageWebSearchesResult = + OrganizationUsageWebSearchesResult( + checkRequired("numModelRequests", numModelRequests), + checkRequired("numRequests", numRequests), + object_, + apiKeyId, + contextLevel, + model, + projectId, + userId, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing + * fields. + * + * @throws OpenAIInvalidDataException if any value type in this object doesn't match + * its expected type. + */ + fun validate(): OrganizationUsageWebSearchesResult = apply { + if (validated) { + return@apply + } + + numModelRequests() + numRequests() + _object_().let { + if (it != JsonValue.from("organization.usage.web_searches.result")) { + throw OpenAIInvalidDataException("'object_' is invalid, received $it") + } + } + apiKeyId() + contextLevel() + model() + projectId() + userId() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OpenAIInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (if (numModelRequests.asKnown().isPresent) 1 else 0) + + (if (numRequests.asKnown().isPresent) 1 else 0) + + object_.let { + if (it == JsonValue.from("organization.usage.web_searches.result")) 1 + else 0 + } + + (if (apiKeyId.asKnown().isPresent) 1 else 0) + + (if (contextLevel.asKnown().isPresent) 1 else 0) + + (if (model.asKnown().isPresent) 1 else 0) + + (if (projectId.asKnown().isPresent) 1 else 0) + + (if (userId.asKnown().isPresent) 1 else 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is OrganizationUsageWebSearchesResult && + numModelRequests == other.numModelRequests && + numRequests == other.numRequests && + object_ == other.object_ && + apiKeyId == other.apiKeyId && + contextLevel == other.contextLevel && + model == other.model && + projectId == other.projectId && + userId == other.userId && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + numModelRequests, + numRequests, + object_, + apiKeyId, + contextLevel, + model, + projectId, + userId, + additionalProperties, + ) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "OrganizationUsageWebSearchesResult{numModelRequests=$numModelRequests, numRequests=$numRequests, object_=$object_, apiKeyId=$apiKeyId, contextLevel=$contextLevel, model=$model, projectId=$projectId, userId=$userId, additionalProperties=$additionalProperties}" + } + + /** The aggregated costs details of the specific time bucket. */ + class OrganizationCostsResult + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val object_: JsonValue, + private val amount: JsonField, + private val apiKeyId: JsonField, + private val lineItem: JsonField, + private val projectId: JsonField, + private val quantity: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("object") @ExcludeMissing object_: JsonValue = JsonMissing.of(), + @JsonProperty("amount") + @ExcludeMissing + amount: JsonField = JsonMissing.of(), + @JsonProperty("api_key_id") + @ExcludeMissing + apiKeyId: JsonField = JsonMissing.of(), + @JsonProperty("line_item") + @ExcludeMissing + lineItem: JsonField = JsonMissing.of(), + @JsonProperty("project_id") + @ExcludeMissing + projectId: JsonField = JsonMissing.of(), + @JsonProperty("quantity") + @ExcludeMissing + quantity: JsonField = JsonMissing.of(), + ) : this(object_, amount, apiKeyId, lineItem, projectId, quantity, mutableMapOf()) + + /** + * Expected to always return the following: + * ```java + * JsonValue.from("organization.costs.result") + * ``` + * + * However, this method can be useful for debugging and logging (e.g. if the server + * responded with an unexpected value). + */ + @JsonProperty("object") @ExcludeMissing fun _object_(): JsonValue = object_ + + /** + * The monetary value in its associated currency. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun amount(): Optional = amount.getOptional("amount") + + /** + * When `group_by=api_key_id`, this field provides the API Key ID of the grouped + * costs result. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun apiKeyId(): Optional = apiKeyId.getOptional("api_key_id") + + /** + * When `group_by=line_item`, this field provides the line item of the grouped costs + * result. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun lineItem(): Optional = lineItem.getOptional("line_item") + + /** + * When `group_by=project_id`, this field provides the project ID of the grouped + * costs result. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun projectId(): Optional = projectId.getOptional("project_id") + + /** + * When `group_by=line_item`, this field provides the quantity of the grouped costs + * result. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun quantity(): Optional = quantity.getOptional("quantity") + + /** + * Returns the raw JSON value of [amount]. + * + * Unlike [amount], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("amount") @ExcludeMissing fun _amount(): JsonField = amount + + /** + * Returns the raw JSON value of [apiKeyId]. + * + * Unlike [apiKeyId], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("api_key_id") + @ExcludeMissing + fun _apiKeyId(): JsonField = apiKeyId + + /** + * Returns the raw JSON value of [lineItem]. + * + * Unlike [lineItem], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("line_item") + @ExcludeMissing + fun _lineItem(): JsonField = lineItem + + /** + * 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 [quantity]. + * + * Unlike [quantity], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("quantity") + @ExcludeMissing + fun _quantity(): JsonField = quantity + + @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 + * [OrganizationCostsResult]. + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [OrganizationCostsResult]. */ + class Builder internal constructor() { + + private var object_: JsonValue = JsonValue.from("organization.costs.result") + private var amount: JsonField = JsonMissing.of() + private var apiKeyId: JsonField = JsonMissing.of() + private var lineItem: JsonField = JsonMissing.of() + private var projectId: JsonField = JsonMissing.of() + private var quantity: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(organizationCostsResult: OrganizationCostsResult) = apply { + object_ = organizationCostsResult.object_ + amount = organizationCostsResult.amount + apiKeyId = organizationCostsResult.apiKeyId + lineItem = organizationCostsResult.lineItem + projectId = organizationCostsResult.projectId + quantity = organizationCostsResult.quantity + additionalProperties = + organizationCostsResult.additionalProperties.toMutableMap() + } + + /** + * Sets the field to an arbitrary JSON value. + * + * It is usually unnecessary to call this method because the field defaults to + * the following: + * ```java + * JsonValue.from("organization.costs.result") + * ``` + * + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun object_(object_: JsonValue) = apply { this.object_ = object_ } + + /** The monetary value in its associated currency. */ + fun amount(amount: Amount) = amount(JsonField.of(amount)) + + /** + * Sets [Builder.amount] to an arbitrary JSON value. + * + * You should usually call [Builder.amount] with a well-typed [Amount] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun amount(amount: JsonField) = apply { this.amount = amount } + + /** + * When `group_by=api_key_id`, this field provides the API Key ID of the grouped + * costs result. + */ + fun apiKeyId(apiKeyId: String?) = apiKeyId(JsonField.ofNullable(apiKeyId)) + + /** Alias for calling [Builder.apiKeyId] with `apiKeyId.orElse(null)`. */ + fun apiKeyId(apiKeyId: Optional) = apiKeyId(apiKeyId.getOrNull()) + + /** + * Sets [Builder.apiKeyId] to an arbitrary JSON value. + * + * You should usually call [Builder.apiKeyId] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun apiKeyId(apiKeyId: JsonField) = apply { this.apiKeyId = apiKeyId } + + /** + * When `group_by=line_item`, this field provides the line item of the grouped + * costs result. + */ + fun lineItem(lineItem: String?) = lineItem(JsonField.ofNullable(lineItem)) + + /** Alias for calling [Builder.lineItem] with `lineItem.orElse(null)`. */ + fun lineItem(lineItem: Optional) = lineItem(lineItem.getOrNull()) + + /** + * Sets [Builder.lineItem] to an arbitrary JSON value. + * + * You should usually call [Builder.lineItem] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun lineItem(lineItem: JsonField) = apply { this.lineItem = lineItem } + + /** + * When `group_by=project_id`, this field provides the project ID of the grouped + * costs result. + */ + fun projectId(projectId: String?) = projectId(JsonField.ofNullable(projectId)) + + /** Alias for calling [Builder.projectId] with `projectId.orElse(null)`. */ + fun projectId(projectId: Optional) = projectId(projectId.getOrNull()) + + /** + * 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 + } + + /** + * When `group_by=line_item`, this field provides the quantity of the grouped + * costs result. + */ + fun quantity(quantity: Double?) = quantity(JsonField.ofNullable(quantity)) + + /** + * Alias for [Builder.quantity]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun quantity(quantity: Double) = quantity(quantity as Double?) + + /** Alias for calling [Builder.quantity] with `quantity.orElse(null)`. */ + fun quantity(quantity: Optional) = quantity(quantity.getOrNull()) + + /** + * Sets [Builder.quantity] to an arbitrary JSON value. + * + * You should usually call [Builder.quantity] with a well-typed [Double] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun quantity(quantity: JsonField) = apply { this.quantity = quantity } + + 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 [OrganizationCostsResult]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): OrganizationCostsResult = + OrganizationCostsResult( + object_, + amount, + apiKeyId, + lineItem, + projectId, + quantity, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing + * fields. + * + * @throws OpenAIInvalidDataException if any value type in this object doesn't match + * its expected type. + */ + fun validate(): OrganizationCostsResult = apply { + if (validated) { + return@apply + } + + _object_().let { + if (it != JsonValue.from("organization.costs.result")) { + throw OpenAIInvalidDataException("'object_' is invalid, received $it") + } + } + amount().ifPresent { it.validate() } + apiKeyId() + lineItem() + projectId() + quantity() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OpenAIInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + object_.let { + if (it == JsonValue.from("organization.costs.result")) 1 else 0 + } + + (amount.asKnown().getOrNull()?.validity() ?: 0) + + (if (apiKeyId.asKnown().isPresent) 1 else 0) + + (if (lineItem.asKnown().isPresent) 1 else 0) + + (if (projectId.asKnown().isPresent) 1 else 0) + + (if (quantity.asKnown().isPresent) 1 else 0) + + /** The monetary value in its associated currency. */ + class Amount + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val currency: JsonField, + private val value: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("currency") + @ExcludeMissing + currency: JsonField = JsonMissing.of(), + @JsonProperty("value") + @ExcludeMissing + value: JsonField = JsonMissing.of(), + ) : this(currency, value, mutableMapOf()) + + /** + * Lowercase ISO-4217 currency e.g. "usd" + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun currency(): Optional = currency.getOptional("currency") + + /** + * The numeric value of the cost. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun value(): Optional = value.getOptional("value") + + /** + * Returns the raw JSON value of [currency]. + * + * Unlike [currency], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("currency") + @ExcludeMissing + fun _currency(): JsonField = currency + + /** + * 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 [Amount]. */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [Amount]. */ + class Builder internal constructor() { + + private var currency: JsonField = JsonMissing.of() + private var value: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = + mutableMapOf() + + @JvmSynthetic + internal fun from(amount: Amount) = apply { + currency = amount.currency + value = amount.value + additionalProperties = amount.additionalProperties.toMutableMap() + } + + /** Lowercase ISO-4217 currency e.g. "usd" */ + fun currency(currency: String) = currency(JsonField.of(currency)) + + /** + * Sets [Builder.currency] to an arbitrary JSON value. + * + * You should usually call [Builder.currency] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun currency(currency: JsonField) = apply { + this.currency = currency + } + + /** The numeric value of the cost. */ + fun value(value: Double) = value(JsonField.of(value)) + + /** + * Sets [Builder.value] to an arbitrary JSON value. + * + * You should usually call [Builder.value] with a well-typed [Double] 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 [Amount]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): Amount = + Amount(currency, value, additionalProperties.toMutableMap()) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected + * types recursively. + * + * This method is _not_ forwards compatible with new types from the API for + * existing fields. + * + * @throws OpenAIInvalidDataException if any value type in this object doesn't + * match its expected type. + */ + fun validate(): Amount = apply { + if (validated) { + return@apply + } + + currency() + value() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OpenAIInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (if (currency.asKnown().isPresent) 1 else 0) + + (if (value.asKnown().isPresent) 1 else 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Amount && + currency == other.currency && + value == other.value && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(currency, value, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Amount{currency=$currency, value=$value, additionalProperties=$additionalProperties}" + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is OrganizationCostsResult && + object_ == other.object_ && + amount == other.amount && + apiKeyId == other.apiKeyId && + lineItem == other.lineItem && + projectId == other.projectId && + quantity == other.quantity && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + object_, + amount, + apiKeyId, + lineItem, + projectId, + quantity, + additionalProperties, + ) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "OrganizationCostsResult{object_=$object_, amount=$amount, apiKeyId=$apiKeyId, lineItem=$lineItem, projectId=$projectId, quantity=$quantity, additionalProperties=$additionalProperties}" + } + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Data && + endTime == other.endTime && + object_ == other.object_ && + results == other.results && + startTime == other.startTime && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(endTime, object_, results, startTime, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Data{endTime=$endTime, object_=$object_, results=$results, startTime=$startTime, additionalProperties=$additionalProperties}" + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is UsageFileSearchCallsResponse && + data == other.data && + hasMore == other.hasMore && + nextPage == other.nextPage && + object_ == other.object_ && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(data, hasMore, nextPage, object_, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "UsageFileSearchCallsResponse{data=$data, hasMore=$hasMore, nextPage=$nextPage, object_=$object_, additionalProperties=$additionalProperties}" +} diff --git a/openai-java-core/src/main/kotlin/com/openai/models/admin/organization/usage/UsageWebSearchCallsParams.kt b/openai-java-core/src/main/kotlin/com/openai/models/admin/organization/usage/UsageWebSearchCallsParams.kt new file mode 100644 index 000000000..9d756bd3d --- /dev/null +++ b/openai-java-core/src/main/kotlin/com/openai/models/admin/organization/usage/UsageWebSearchCallsParams.kt @@ -0,0 +1,920 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.models.admin.organization.usage + +import com.fasterxml.jackson.annotation.JsonCreator +import com.openai.core.Enum +import com.openai.core.JsonField +import com.openai.core.Params +import com.openai.core.checkRequired +import com.openai.core.http.Headers +import com.openai.core.http.QueryParams +import com.openai.core.toImmutable +import com.openai.errors.OpenAIInvalidDataException +import java.util.Objects +import java.util.Optional +import kotlin.jvm.optionals.getOrNull + +/** Get web search calls usage details for the organization. */ +class UsageWebSearchCallsParams +private constructor( + private val startTime: Long, + private val apiKeyIds: List?, + private val bucketWidth: BucketWidth?, + private val contextLevels: List?, + private val endTime: Long?, + private val groupBy: List?, + private val limit: Long?, + private val models: List?, + private val page: String?, + private val projectIds: List?, + private val userIds: List?, + private val additionalHeaders: Headers, + private val additionalQueryParams: QueryParams, +) : Params { + + /** Start time (Unix seconds) of the query time range, inclusive. */ + fun startTime(): Long = startTime + + /** Return only usage for these API keys. */ + fun apiKeyIds(): Optional> = Optional.ofNullable(apiKeyIds) + + /** + * Width of each time bucket in response. Currently `1m`, `1h` and `1d` are supported, default + * to `1d`. + */ + fun bucketWidth(): Optional = Optional.ofNullable(bucketWidth) + + /** Return only web search usage for these context levels. */ + fun contextLevels(): Optional> = Optional.ofNullable(contextLevels) + + /** End time (Unix seconds) of the query time range, exclusive. */ + fun endTime(): Optional = Optional.ofNullable(endTime) + + /** + * Group the usage data by the specified fields. Support fields include `project_id`, `user_id`, + * `api_key_id`, `model`, `context_level` or any combination of them. + */ + fun groupBy(): Optional> = Optional.ofNullable(groupBy) + + /** + * Specifies the number of buckets to return. + * - `bucket_width=1d`: default: 7, max: 31 + * - `bucket_width=1h`: default: 24, max: 168 + * - `bucket_width=1m`: default: 60, max: 1440 + */ + fun limit(): Optional = Optional.ofNullable(limit) + + /** Return only usage for these models. */ + fun models(): Optional> = Optional.ofNullable(models) + + /** + * A cursor for use in pagination. Corresponding to the `next_page` field from the previous + * response. + */ + fun page(): Optional = Optional.ofNullable(page) + + /** Return only usage for these projects. */ + fun projectIds(): Optional> = Optional.ofNullable(projectIds) + + /** Return only usage for these users. */ + fun userIds(): Optional> = Optional.ofNullable(userIds) + + /** Additional headers to send with the request. */ + fun _additionalHeaders(): Headers = additionalHeaders + + /** Additional query param to send with the request. */ + fun _additionalQueryParams(): QueryParams = additionalQueryParams + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of [UsageWebSearchCallsParams]. + * + * The following fields are required: + * ```java + * .startTime() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [UsageWebSearchCallsParams]. */ + class Builder internal constructor() { + + private var startTime: Long? = null + private var apiKeyIds: MutableList? = null + private var bucketWidth: BucketWidth? = null + private var contextLevels: MutableList? = null + private var endTime: Long? = null + private var groupBy: MutableList? = null + private var limit: Long? = null + private var models: MutableList? = null + private var page: String? = null + private var projectIds: MutableList? = null + private var userIds: MutableList? = null + private var additionalHeaders: Headers.Builder = Headers.builder() + private var additionalQueryParams: QueryParams.Builder = QueryParams.builder() + + @JvmSynthetic + internal fun from(usageWebSearchCallsParams: UsageWebSearchCallsParams) = apply { + startTime = usageWebSearchCallsParams.startTime + apiKeyIds = usageWebSearchCallsParams.apiKeyIds?.toMutableList() + bucketWidth = usageWebSearchCallsParams.bucketWidth + contextLevels = usageWebSearchCallsParams.contextLevels?.toMutableList() + endTime = usageWebSearchCallsParams.endTime + groupBy = usageWebSearchCallsParams.groupBy?.toMutableList() + limit = usageWebSearchCallsParams.limit + models = usageWebSearchCallsParams.models?.toMutableList() + page = usageWebSearchCallsParams.page + projectIds = usageWebSearchCallsParams.projectIds?.toMutableList() + userIds = usageWebSearchCallsParams.userIds?.toMutableList() + additionalHeaders = usageWebSearchCallsParams.additionalHeaders.toBuilder() + additionalQueryParams = usageWebSearchCallsParams.additionalQueryParams.toBuilder() + } + + /** Start time (Unix seconds) of the query time range, inclusive. */ + fun startTime(startTime: Long) = apply { this.startTime = startTime } + + /** Return only usage for these API keys. */ + fun apiKeyIds(apiKeyIds: List?) = apply { + this.apiKeyIds = apiKeyIds?.toMutableList() + } + + /** Alias for calling [Builder.apiKeyIds] with `apiKeyIds.orElse(null)`. */ + fun apiKeyIds(apiKeyIds: Optional>) = apiKeyIds(apiKeyIds.getOrNull()) + + /** + * Adds a single [String] to [apiKeyIds]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addApiKeyId(apiKeyId: String) = apply { + apiKeyIds = (apiKeyIds ?: mutableListOf()).apply { add(apiKeyId) } + } + + /** + * Width of each time bucket in response. Currently `1m`, `1h` and `1d` are supported, + * default to `1d`. + */ + fun bucketWidth(bucketWidth: BucketWidth?) = apply { this.bucketWidth = bucketWidth } + + /** Alias for calling [Builder.bucketWidth] with `bucketWidth.orElse(null)`. */ + fun bucketWidth(bucketWidth: Optional) = bucketWidth(bucketWidth.getOrNull()) + + /** Return only web search usage for these context levels. */ + fun contextLevels(contextLevels: List?) = apply { + this.contextLevels = contextLevels?.toMutableList() + } + + /** Alias for calling [Builder.contextLevels] with `contextLevels.orElse(null)`. */ + fun contextLevels(contextLevels: Optional>) = + contextLevels(contextLevels.getOrNull()) + + /** + * Adds a single [ContextLevel] to [contextLevels]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addContextLevel(contextLevel: ContextLevel) = apply { + contextLevels = (contextLevels ?: mutableListOf()).apply { add(contextLevel) } + } + + /** End time (Unix seconds) of the query time range, exclusive. */ + fun endTime(endTime: Long?) = apply { this.endTime = endTime } + + /** + * Alias for [Builder.endTime]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun endTime(endTime: Long) = endTime(endTime as Long?) + + /** Alias for calling [Builder.endTime] with `endTime.orElse(null)`. */ + fun endTime(endTime: Optional) = endTime(endTime.getOrNull()) + + /** + * Group the usage data by the specified fields. Support fields include `project_id`, + * `user_id`, `api_key_id`, `model`, `context_level` or any combination of them. + */ + fun groupBy(groupBy: List?) = apply { this.groupBy = groupBy?.toMutableList() } + + /** Alias for calling [Builder.groupBy] with `groupBy.orElse(null)`. */ + fun groupBy(groupBy: Optional>) = groupBy(groupBy.getOrNull()) + + /** + * Adds a single [GroupBy] to [Builder.groupBy]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addGroupBy(groupBy: GroupBy) = apply { + this.groupBy = (this.groupBy ?: mutableListOf()).apply { add(groupBy) } + } + + /** + * Specifies the number of buckets to return. + * - `bucket_width=1d`: default: 7, max: 31 + * - `bucket_width=1h`: default: 24, max: 168 + * - `bucket_width=1m`: default: 60, max: 1440 + */ + fun limit(limit: Long?) = apply { this.limit = 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()) + + /** Return only usage for these models. */ + fun models(models: List?) = apply { this.models = models?.toMutableList() } + + /** Alias for calling [Builder.models] with `models.orElse(null)`. */ + fun models(models: Optional>) = models(models.getOrNull()) + + /** + * Adds a single [String] to [models]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addModel(model: String) = apply { + models = (models ?: mutableListOf()).apply { add(model) } + } + + /** + * A cursor for use in pagination. Corresponding to the `next_page` field from the previous + * response. + */ + fun page(page: String?) = apply { this.page = page } + + /** Alias for calling [Builder.page] with `page.orElse(null)`. */ + fun page(page: Optional) = page(page.getOrNull()) + + /** Return only usage for these projects. */ + fun projectIds(projectIds: List?) = apply { + this.projectIds = projectIds?.toMutableList() + } + + /** Alias for calling [Builder.projectIds] with `projectIds.orElse(null)`. */ + fun projectIds(projectIds: Optional>) = projectIds(projectIds.getOrNull()) + + /** + * Adds a single [String] to [projectIds]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addProjectId(projectId: String) = apply { + projectIds = (projectIds ?: mutableListOf()).apply { add(projectId) } + } + + /** Return only usage for these users. */ + fun userIds(userIds: List?) = apply { this.userIds = userIds?.toMutableList() } + + /** Alias for calling [Builder.userIds] with `userIds.orElse(null)`. */ + fun userIds(userIds: Optional>) = userIds(userIds.getOrNull()) + + /** + * Adds a single [String] to [userIds]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addUserId(userId: String) = apply { + userIds = (userIds ?: mutableListOf()).apply { add(userId) } + } + + 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 [UsageWebSearchCallsParams]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .startTime() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): UsageWebSearchCallsParams = + UsageWebSearchCallsParams( + checkRequired("startTime", startTime), + apiKeyIds?.toImmutable(), + bucketWidth, + contextLevels?.toImmutable(), + endTime, + groupBy?.toImmutable(), + limit, + models?.toImmutable(), + page, + projectIds?.toImmutable(), + userIds?.toImmutable(), + additionalHeaders.build(), + additionalQueryParams.build(), + ) + } + + override fun _headers(): Headers = additionalHeaders + + override fun _queryParams(): QueryParams = + QueryParams.builder() + .apply { + put("start_time", startTime.toString()) + apiKeyIds?.forEach { put("api_key_ids[]", it) } + bucketWidth?.let { put("bucket_width", it.toString()) } + contextLevels?.forEach { put("context_levels[]", it.toString()) } + endTime?.let { put("end_time", it.toString()) } + groupBy?.forEach { put("group_by[]", it.toString()) } + limit?.let { put("limit", it.toString()) } + models?.forEach { put("models[]", it) } + page?.let { put("page", it) } + projectIds?.forEach { put("project_ids[]", it) } + userIds?.forEach { put("user_ids[]", it) } + putAll(additionalQueryParams) + } + .build() + + /** + * Width of each time bucket in response. Currently `1m`, `1h` and `1d` are supported, default + * to `1d`. + */ + class BucketWidth @JsonCreator private constructor(private val value: JsonField) : + Enum { + + /** + * Returns this class instance's raw value. + * + * This is usually only useful if this instance was deserialized from data that doesn't + * match any known member, and you want to know that value. For example, if the SDK is on an + * older version than the API, then the API may respond with new members that the SDK is + * unaware of. + */ + @com.fasterxml.jackson.annotation.JsonValue fun _value(): JsonField = value + + companion object { + + @JvmField val _1M = of("1m") + + @JvmField val _1H = of("1h") + + @JvmField val _1D = of("1d") + + @JvmStatic fun of(value: String) = BucketWidth(JsonField.of(value)) + } + + /** An enum containing [BucketWidth]'s known values. */ + enum class Known { + _1M, + _1H, + _1D, + } + + /** + * An enum containing [BucketWidth]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [BucketWidth] can contain an unknown value in a couple of cases: + * - It was deserialized from data that doesn't match any known member. For example, if the + * SDK is on an older version than the API, then the API may respond with new members that + * the SDK is unaware of. + * - It was constructed with an arbitrary value using the [of] method. + */ + enum class Value { + _1M, + _1H, + _1D, + /** + * An enum member indicating that [BucketWidth] was instantiated with an unknown value. + */ + _UNKNOWN, + } + + /** + * Returns an enum member corresponding to this class instance's value, or [Value._UNKNOWN] + * if the class was instantiated with an unknown value. + * + * Use the [known] method instead if you're certain the value is always known or if you want + * to throw for the unknown case. + */ + fun value(): Value = + when (this) { + _1M -> Value._1M + _1H -> Value._1H + _1D -> Value._1D + else -> Value._UNKNOWN + } + + /** + * Returns an enum member corresponding to this class instance's value. + * + * Use the [value] method instead if you're uncertain the value is always known and don't + * want to throw for the unknown case. + * + * @throws OpenAIInvalidDataException if this class instance's value is a not a known + * member. + */ + fun known(): Known = + when (this) { + _1M -> Known._1M + _1H -> Known._1H + _1D -> Known._1D + else -> throw OpenAIInvalidDataException("Unknown BucketWidth: $value") + } + + /** + * Returns this class instance's primitive wire representation. + * + * This differs from the [toString] method because that method is primarily for debugging + * and generally doesn't throw. + * + * @throws OpenAIInvalidDataException if this class instance's value does not have the + * expected primitive type. + */ + fun asString(): String = + _value().asString().orElseThrow { OpenAIInvalidDataException("Value is not a String") } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing fields. + * + * @throws OpenAIInvalidDataException if any value type in this object doesn't match its + * expected type. + */ + fun validate(): BucketWidth = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OpenAIInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is BucketWidth && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + class ContextLevel @JsonCreator private constructor(private val value: JsonField) : + Enum { + + /** + * Returns this class instance's raw value. + * + * This is usually only useful if this instance was deserialized from data that doesn't + * match any known member, and you want to know that value. For example, if the SDK is on an + * older version than the API, then the API may respond with new members that the SDK is + * unaware of. + */ + @com.fasterxml.jackson.annotation.JsonValue fun _value(): JsonField = value + + companion object { + + @JvmField val LOW = of("low") + + @JvmField val MEDIUM = of("medium") + + @JvmField val HIGH = of("high") + + @JvmStatic fun of(value: String) = ContextLevel(JsonField.of(value)) + } + + /** An enum containing [ContextLevel]'s known values. */ + enum class Known { + LOW, + MEDIUM, + HIGH, + } + + /** + * An enum containing [ContextLevel]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [ContextLevel] can contain an unknown value in a couple of cases: + * - It was deserialized from data that doesn't match any known member. For example, if the + * SDK is on an older version than the API, then the API may respond with new members that + * the SDK is unaware of. + * - It was constructed with an arbitrary value using the [of] method. + */ + enum class Value { + LOW, + MEDIUM, + HIGH, + /** + * An enum member indicating that [ContextLevel] was instantiated with an unknown value. + */ + _UNKNOWN, + } + + /** + * Returns an enum member corresponding to this class instance's value, or [Value._UNKNOWN] + * if the class was instantiated with an unknown value. + * + * Use the [known] method instead if you're certain the value is always known or if you want + * to throw for the unknown case. + */ + fun value(): Value = + when (this) { + LOW -> Value.LOW + MEDIUM -> Value.MEDIUM + HIGH -> Value.HIGH + else -> Value._UNKNOWN + } + + /** + * Returns an enum member corresponding to this class instance's value. + * + * Use the [value] method instead if you're uncertain the value is always known and don't + * want to throw for the unknown case. + * + * @throws OpenAIInvalidDataException if this class instance's value is a not a known + * member. + */ + fun known(): Known = + when (this) { + LOW -> Known.LOW + MEDIUM -> Known.MEDIUM + HIGH -> Known.HIGH + else -> throw OpenAIInvalidDataException("Unknown ContextLevel: $value") + } + + /** + * Returns this class instance's primitive wire representation. + * + * This differs from the [toString] method because that method is primarily for debugging + * and generally doesn't throw. + * + * @throws OpenAIInvalidDataException if this class instance's value does not have the + * expected primitive type. + */ + fun asString(): String = + _value().asString().orElseThrow { OpenAIInvalidDataException("Value is not a String") } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing fields. + * + * @throws OpenAIInvalidDataException if any value type in this object doesn't match its + * expected type. + */ + fun validate(): ContextLevel = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OpenAIInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is ContextLevel && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + class GroupBy @JsonCreator private constructor(private val value: JsonField) : Enum { + + /** + * Returns this class instance's raw value. + * + * This is usually only useful if this instance was deserialized from data that doesn't + * match any known member, and you want to know that value. For example, if the SDK is on an + * older version than the API, then the API may respond with new members that the SDK is + * unaware of. + */ + @com.fasterxml.jackson.annotation.JsonValue fun _value(): JsonField = value + + companion object { + + @JvmField val PROJECT_ID = of("project_id") + + @JvmField val USER_ID = of("user_id") + + @JvmField val API_KEY_ID = of("api_key_id") + + @JvmField val MODEL = of("model") + + @JvmField val CONTEXT_LEVEL = of("context_level") + + @JvmStatic fun of(value: String) = GroupBy(JsonField.of(value)) + } + + /** An enum containing [GroupBy]'s known values. */ + enum class Known { + PROJECT_ID, + USER_ID, + API_KEY_ID, + MODEL, + CONTEXT_LEVEL, + } + + /** + * An enum containing [GroupBy]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [GroupBy] can contain an unknown value in a couple of cases: + * - It was deserialized from data that doesn't match any known member. For example, if the + * SDK is on an older version than the API, then the API may respond with new members that + * the SDK is unaware of. + * - It was constructed with an arbitrary value using the [of] method. + */ + enum class Value { + PROJECT_ID, + USER_ID, + API_KEY_ID, + MODEL, + CONTEXT_LEVEL, + /** An enum member indicating that [GroupBy] was instantiated with an unknown value. */ + _UNKNOWN, + } + + /** + * Returns an enum member corresponding to this class instance's value, or [Value._UNKNOWN] + * if the class was instantiated with an unknown value. + * + * Use the [known] method instead if you're certain the value is always known or if you want + * to throw for the unknown case. + */ + fun value(): Value = + when (this) { + PROJECT_ID -> Value.PROJECT_ID + USER_ID -> Value.USER_ID + API_KEY_ID -> Value.API_KEY_ID + MODEL -> Value.MODEL + CONTEXT_LEVEL -> Value.CONTEXT_LEVEL + else -> Value._UNKNOWN + } + + /** + * Returns an enum member corresponding to this class instance's value. + * + * Use the [value] method instead if you're uncertain the value is always known and don't + * want to throw for the unknown case. + * + * @throws OpenAIInvalidDataException if this class instance's value is a not a known + * member. + */ + fun known(): Known = + when (this) { + PROJECT_ID -> Known.PROJECT_ID + USER_ID -> Known.USER_ID + API_KEY_ID -> Known.API_KEY_ID + MODEL -> Known.MODEL + CONTEXT_LEVEL -> Known.CONTEXT_LEVEL + else -> throw OpenAIInvalidDataException("Unknown GroupBy: $value") + } + + /** + * Returns this class instance's primitive wire representation. + * + * This differs from the [toString] method because that method is primarily for debugging + * and generally doesn't throw. + * + * @throws OpenAIInvalidDataException if this class instance's value does not have the + * expected primitive type. + */ + fun asString(): String = + _value().asString().orElseThrow { OpenAIInvalidDataException("Value is not a String") } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing fields. + * + * @throws OpenAIInvalidDataException if any value type in this object doesn't match its + * expected type. + */ + fun validate(): GroupBy = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OpenAIInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is GroupBy && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is UsageWebSearchCallsParams && + startTime == other.startTime && + apiKeyIds == other.apiKeyIds && + bucketWidth == other.bucketWidth && + contextLevels == other.contextLevels && + endTime == other.endTime && + groupBy == other.groupBy && + limit == other.limit && + models == other.models && + page == other.page && + projectIds == other.projectIds && + userIds == other.userIds && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams + } + + override fun hashCode(): Int = + Objects.hash( + startTime, + apiKeyIds, + bucketWidth, + contextLevels, + endTime, + groupBy, + limit, + models, + page, + projectIds, + userIds, + additionalHeaders, + additionalQueryParams, + ) + + override fun toString() = + "UsageWebSearchCallsParams{startTime=$startTime, apiKeyIds=$apiKeyIds, bucketWidth=$bucketWidth, contextLevels=$contextLevels, endTime=$endTime, groupBy=$groupBy, limit=$limit, models=$models, page=$page, projectIds=$projectIds, userIds=$userIds, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" +} diff --git a/openai-java-core/src/main/kotlin/com/openai/models/admin/organization/usage/UsageWebSearchCallsResponse.kt b/openai-java-core/src/main/kotlin/com/openai/models/admin/organization/usage/UsageWebSearchCallsResponse.kt new file mode 100644 index 000000000..f832f5474 --- /dev/null +++ b/openai-java-core/src/main/kotlin/com/openai/models/admin/organization/usage/UsageWebSearchCallsResponse.kt @@ -0,0 +1,6930 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.models.admin.organization.usage + +import com.fasterxml.jackson.annotation.JsonAnyGetter +import com.fasterxml.jackson.annotation.JsonAnySetter +import com.fasterxml.jackson.annotation.JsonCreator +import com.fasterxml.jackson.annotation.JsonProperty +import com.fasterxml.jackson.core.JsonGenerator +import com.fasterxml.jackson.core.ObjectCodec +import com.fasterxml.jackson.databind.JsonNode +import com.fasterxml.jackson.databind.SerializerProvider +import com.fasterxml.jackson.databind.annotation.JsonDeserialize +import com.fasterxml.jackson.databind.annotation.JsonSerialize +import com.fasterxml.jackson.module.kotlin.jacksonTypeRef +import com.openai.core.BaseDeserializer +import com.openai.core.BaseSerializer +import com.openai.core.ExcludeMissing +import com.openai.core.JsonField +import com.openai.core.JsonMissing +import com.openai.core.JsonValue +import com.openai.core.checkKnown +import com.openai.core.checkRequired +import com.openai.core.getOrThrow +import com.openai.core.toImmutable +import com.openai.errors.OpenAIInvalidDataException +import java.util.Collections +import java.util.Objects +import java.util.Optional +import kotlin.jvm.optionals.getOrNull + +class UsageWebSearchCallsResponse +@JsonCreator(mode = JsonCreator.Mode.DISABLED) +private constructor( + private val data: JsonField>, + private val hasMore: JsonField, + private val nextPage: JsonField, + private val object_: JsonValue, + private val additionalProperties: MutableMap, +) { + + @JsonCreator + private constructor( + @JsonProperty("data") @ExcludeMissing data: JsonField> = JsonMissing.of(), + @JsonProperty("has_more") @ExcludeMissing hasMore: JsonField = JsonMissing.of(), + @JsonProperty("next_page") @ExcludeMissing nextPage: JsonField = JsonMissing.of(), + @JsonProperty("object") @ExcludeMissing object_: JsonValue = JsonMissing.of(), + ) : this(data, hasMore, nextPage, object_, mutableMapOf()) + + /** + * @throws OpenAIInvalidDataException 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(): List = data.getRequired("data") + + /** + * @throws OpenAIInvalidDataException 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 hasMore(): Boolean = hasMore.getRequired("has_more") + + /** + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun nextPage(): Optional = nextPage.getOptional("next_page") + + /** + * Expected to always return the following: + * ```java + * JsonValue.from("page") + * ``` + * + * However, this method can be useful for debugging and logging (e.g. if the server responded + * with an unexpected value). + */ + @JsonProperty("object") @ExcludeMissing fun _object_(): JsonValue = object_ + + /** + * 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 + + /** + * Returns the raw JSON value of [hasMore]. + * + * Unlike [hasMore], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("has_more") @ExcludeMissing fun _hasMore(): JsonField = hasMore + + /** + * Returns the raw JSON value of [nextPage]. + * + * Unlike [nextPage], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("next_page") @ExcludeMissing fun _nextPage(): JsonField = nextPage + + @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 [UsageWebSearchCallsResponse]. + * + * The following fields are required: + * ```java + * .data() + * .hasMore() + * .nextPage() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [UsageWebSearchCallsResponse]. */ + class Builder internal constructor() { + + private var data: JsonField>? = null + private var hasMore: JsonField? = null + private var nextPage: JsonField? = null + private var object_: JsonValue = JsonValue.from("page") + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(usageWebSearchCallsResponse: UsageWebSearchCallsResponse) = apply { + data = usageWebSearchCallsResponse.data.map { it.toMutableList() } + hasMore = usageWebSearchCallsResponse.hasMore + nextPage = usageWebSearchCallsResponse.nextPage + object_ = usageWebSearchCallsResponse.object_ + additionalProperties = usageWebSearchCallsResponse.additionalProperties.toMutableMap() + } + + fun data(data: List) = data(JsonField.of(data)) + + /** + * Sets [Builder.data] to an arbitrary JSON value. + * + * You should usually call [Builder.data] with a well-typed `List` 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.map { it.toMutableList() } + } + + /** + * Adds a single [Data] to [Builder.data]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addData(data: Data) = apply { + this.data = + (this.data ?: JsonField.of(mutableListOf())).also { + checkKnown("data", it).add(data) + } + } + + fun hasMore(hasMore: Boolean) = hasMore(JsonField.of(hasMore)) + + /** + * Sets [Builder.hasMore] to an arbitrary JSON value. + * + * You should usually call [Builder.hasMore] with a well-typed [Boolean] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun hasMore(hasMore: JsonField) = apply { this.hasMore = hasMore } + + fun nextPage(nextPage: String?) = nextPage(JsonField.ofNullable(nextPage)) + + /** Alias for calling [Builder.nextPage] with `nextPage.orElse(null)`. */ + fun nextPage(nextPage: Optional) = nextPage(nextPage.getOrNull()) + + /** + * Sets [Builder.nextPage] to an arbitrary JSON value. + * + * You should usually call [Builder.nextPage] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun nextPage(nextPage: JsonField) = apply { this.nextPage = nextPage } + + /** + * Sets the field to an arbitrary JSON value. + * + * It is usually unnecessary to call this method because the field defaults to the + * following: + * ```java + * JsonValue.from("page") + * ``` + * + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun object_(object_: JsonValue) = apply { this.object_ = object_ } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [UsageWebSearchCallsResponse]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .data() + * .hasMore() + * .nextPage() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): UsageWebSearchCallsResponse = + UsageWebSearchCallsResponse( + checkRequired("data", data).map { it.toImmutable() }, + checkRequired("hasMore", hasMore), + checkRequired("nextPage", nextPage), + object_, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected types recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing fields. + * + * @throws OpenAIInvalidDataException if any value type in this object doesn't match its + * expected type. + */ + fun validate(): UsageWebSearchCallsResponse = apply { + if (validated) { + return@apply + } + + data().forEach { it.validate() } + hasMore() + nextPage() + _object_().let { + if (it != JsonValue.from("page")) { + throw OpenAIInvalidDataException("'object_' is invalid, received $it") + } + } + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OpenAIInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (data.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + + (if (hasMore.asKnown().isPresent) 1 else 0) + + (if (nextPage.asKnown().isPresent) 1 else 0) + + object_.let { if (it == JsonValue.from("page")) 1 else 0 } + + class Data + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val endTime: JsonField, + private val object_: JsonValue, + private val results: JsonField>, + private val startTime: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("end_time") @ExcludeMissing endTime: JsonField = JsonMissing.of(), + @JsonProperty("object") @ExcludeMissing object_: JsonValue = JsonMissing.of(), + @JsonProperty("results") + @ExcludeMissing + results: JsonField> = JsonMissing.of(), + @JsonProperty("start_time") + @ExcludeMissing + startTime: JsonField = JsonMissing.of(), + ) : this(endTime, object_, results, startTime, mutableMapOf()) + + /** + * @throws OpenAIInvalidDataException 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 endTime(): Long = endTime.getRequired("end_time") + + /** + * Expected to always return the following: + * ```java + * JsonValue.from("bucket") + * ``` + * + * However, this method can be useful for debugging and logging (e.g. if the server + * responded with an unexpected value). + */ + @JsonProperty("object") @ExcludeMissing fun _object_(): JsonValue = object_ + + /** + * @throws OpenAIInvalidDataException 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 results(): List = results.getRequired("results") + + /** + * @throws OpenAIInvalidDataException 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 startTime(): Long = startTime.getRequired("start_time") + + /** + * Returns the raw JSON value of [endTime]. + * + * Unlike [endTime], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("end_time") @ExcludeMissing fun _endTime(): JsonField = endTime + + /** + * Returns the raw JSON value of [results]. + * + * Unlike [results], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("results") @ExcludeMissing fun _results(): JsonField> = results + + /** + * Returns the raw JSON value of [startTime]. + * + * Unlike [startTime], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("start_time") @ExcludeMissing fun _startTime(): JsonField = startTime + + @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 [Data]. + * + * The following fields are required: + * ```java + * .endTime() + * .results() + * .startTime() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [Data]. */ + class Builder internal constructor() { + + private var endTime: JsonField? = null + private var object_: JsonValue = JsonValue.from("bucket") + private var results: JsonField>? = null + private var startTime: JsonField? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(data: Data) = apply { + endTime = data.endTime + object_ = data.object_ + results = data.results.map { it.toMutableList() } + startTime = data.startTime + additionalProperties = data.additionalProperties.toMutableMap() + } + + fun endTime(endTime: Long) = endTime(JsonField.of(endTime)) + + /** + * Sets [Builder.endTime] to an arbitrary JSON value. + * + * You should usually call [Builder.endTime] with a well-typed [Long] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun endTime(endTime: JsonField) = apply { this.endTime = endTime } + + /** + * Sets the field to an arbitrary JSON value. + * + * It is usually unnecessary to call this method because the field defaults to the + * following: + * ```java + * JsonValue.from("bucket") + * ``` + * + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun object_(object_: JsonValue) = apply { this.object_ = object_ } + + fun results(results: List) = results(JsonField.of(results)) + + /** + * Sets [Builder.results] to an arbitrary JSON value. + * + * You should usually call [Builder.results] with a well-typed `List` value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun results(results: JsonField>) = apply { + this.results = results.map { it.toMutableList() } + } + + /** + * Adds a single [Result] to [results]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addResult(result: Result) = apply { + results = + (results ?: JsonField.of(mutableListOf())).also { + checkKnown("results", it).add(result) + } + } + + /** + * Alias for calling [addResult] with + * `Result.ofOrganizationUsageCompletions(organizationUsageCompletions)`. + */ + fun addResult(organizationUsageCompletions: Result.OrganizationUsageCompletionsResult) = + addResult(Result.ofOrganizationUsageCompletions(organizationUsageCompletions)) + + /** + * Alias for calling [addResult] with + * `Result.ofOrganizationUsageEmbeddings(organizationUsageEmbeddings)`. + */ + fun addResult(organizationUsageEmbeddings: Result.OrganizationUsageEmbeddingsResult) = + addResult(Result.ofOrganizationUsageEmbeddings(organizationUsageEmbeddings)) + + /** + * Alias for calling [addResult] with + * `Result.ofOrganizationUsageModerations(organizationUsageModerations)`. + */ + fun addResult(organizationUsageModerations: Result.OrganizationUsageModerationsResult) = + addResult(Result.ofOrganizationUsageModerations(organizationUsageModerations)) + + /** + * Alias for calling [addResult] with + * `Result.ofOrganizationUsageImages(organizationUsageImages)`. + */ + fun addResult(organizationUsageImages: Result.OrganizationUsageImagesResult) = + addResult(Result.ofOrganizationUsageImages(organizationUsageImages)) + + /** + * Alias for calling [addResult] with + * `Result.ofOrganizationUsageAudioSpeeches(organizationUsageAudioSpeeches)`. + */ + fun addResult( + organizationUsageAudioSpeeches: Result.OrganizationUsageAudioSpeechesResult + ) = addResult(Result.ofOrganizationUsageAudioSpeeches(organizationUsageAudioSpeeches)) + + /** + * Alias for calling [addResult] with + * `Result.ofOrganizationUsageAudioTranscriptions(organizationUsageAudioTranscriptions)`. + */ + fun addResult( + organizationUsageAudioTranscriptions: + Result.OrganizationUsageAudioTranscriptionsResult + ) = + addResult( + Result.ofOrganizationUsageAudioTranscriptions( + organizationUsageAudioTranscriptions + ) + ) + + /** + * Alias for calling [addResult] with + * `Result.ofOrganizationUsageVectorStores(organizationUsageVectorStores)`. + */ + fun addResult( + organizationUsageVectorStores: Result.OrganizationUsageVectorStoresResult + ) = addResult(Result.ofOrganizationUsageVectorStores(organizationUsageVectorStores)) + + /** + * Alias for calling [addResult] with the following: + * ```java + * Result.OrganizationUsageVectorStoresResult.builder() + * .usageBytes(usageBytes) + * .build() + * ``` + */ + fun addOrganizationUsageVectorStoresResult(usageBytes: Long) = + addResult( + Result.OrganizationUsageVectorStoresResult.builder() + .usageBytes(usageBytes) + .build() + ) + + /** + * Alias for calling [addResult] with + * `Result.ofOrganizationUsageCodeInterpreterSessions(organizationUsageCodeInterpreterSessions)`. + */ + fun addResult( + organizationUsageCodeInterpreterSessions: + Result.OrganizationUsageCodeInterpreterSessionsResult + ) = + addResult( + Result.ofOrganizationUsageCodeInterpreterSessions( + organizationUsageCodeInterpreterSessions + ) + ) + + /** + * Alias for calling [addResult] with the following: + * ```java + * Result.OrganizationUsageCodeInterpreterSessionsResult.builder() + * .numSessions(numSessions) + * .build() + * ``` + */ + fun addOrganizationUsageCodeInterpreterSessionsResult(numSessions: Long) = + addResult( + Result.OrganizationUsageCodeInterpreterSessionsResult.builder() + .numSessions(numSessions) + .build() + ) + + /** + * Alias for calling [addResult] with + * `Result.ofOrganizationUsageFileSearches(organizationUsageFileSearches)`. + */ + fun addResult( + organizationUsageFileSearches: Result.OrganizationUsageFileSearchesResult + ) = addResult(Result.ofOrganizationUsageFileSearches(organizationUsageFileSearches)) + + /** + * Alias for calling [addResult] with the following: + * ```java + * Result.OrganizationUsageFileSearchesResult.builder() + * .numRequests(numRequests) + * .build() + * ``` + */ + fun addOrganizationUsageFileSearchesResult(numRequests: Long) = + addResult( + Result.OrganizationUsageFileSearchesResult.builder() + .numRequests(numRequests) + .build() + ) + + /** + * Alias for calling [addResult] with + * `Result.ofOrganizationUsageWebSearches(organizationUsageWebSearches)`. + */ + fun addResult(organizationUsageWebSearches: Result.OrganizationUsageWebSearchesResult) = + addResult(Result.ofOrganizationUsageWebSearches(organizationUsageWebSearches)) + + /** + * Alias for calling [addResult] with `Result.ofOrganizationCosts(organizationCosts)`. + */ + fun addResult(organizationCosts: Result.OrganizationCostsResult) = + addResult(Result.ofOrganizationCosts(organizationCosts)) + + fun startTime(startTime: Long) = startTime(JsonField.of(startTime)) + + /** + * Sets [Builder.startTime] to an arbitrary JSON value. + * + * You should usually call [Builder.startTime] with a well-typed [Long] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun startTime(startTime: JsonField) = apply { this.startTime = startTime } + + 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 [Data]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .endTime() + * .results() + * .startTime() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): Data = + Data( + checkRequired("endTime", endTime), + object_, + checkRequired("results", results).map { it.toImmutable() }, + checkRequired("startTime", startTime), + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing fields. + * + * @throws OpenAIInvalidDataException if any value type in this object doesn't match its + * expected type. + */ + fun validate(): Data = apply { + if (validated) { + return@apply + } + + endTime() + _object_().let { + if (it != JsonValue.from("bucket")) { + throw OpenAIInvalidDataException("'object_' is invalid, received $it") + } + } + results().forEach { it.validate() } + startTime() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OpenAIInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (if (endTime.asKnown().isPresent) 1 else 0) + + object_.let { if (it == JsonValue.from("bucket")) 1 else 0 } + + (results.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + + (if (startTime.asKnown().isPresent) 1 else 0) + + /** The aggregated completions usage details of the specific time bucket. */ + @JsonDeserialize(using = Result.Deserializer::class) + @JsonSerialize(using = Result.Serializer::class) + class Result + private constructor( + private val organizationUsageCompletions: OrganizationUsageCompletionsResult? = null, + private val organizationUsageEmbeddings: OrganizationUsageEmbeddingsResult? = null, + private val organizationUsageModerations: OrganizationUsageModerationsResult? = null, + private val organizationUsageImages: OrganizationUsageImagesResult? = null, + private val organizationUsageAudioSpeeches: OrganizationUsageAudioSpeechesResult? = + null, + private val organizationUsageAudioTranscriptions: + OrganizationUsageAudioTranscriptionsResult? = + null, + private val organizationUsageVectorStores: OrganizationUsageVectorStoresResult? = null, + private val organizationUsageCodeInterpreterSessions: + OrganizationUsageCodeInterpreterSessionsResult? = + null, + private val organizationUsageFileSearches: OrganizationUsageFileSearchesResult? = null, + private val organizationUsageWebSearches: OrganizationUsageWebSearchesResult? = null, + private val organizationCosts: OrganizationCostsResult? = null, + private val _json: JsonValue? = null, + ) { + + /** The aggregated completions usage details of the specific time bucket. */ + fun organizationUsageCompletions(): Optional = + Optional.ofNullable(organizationUsageCompletions) + + /** The aggregated embeddings usage details of the specific time bucket. */ + fun organizationUsageEmbeddings(): Optional = + Optional.ofNullable(organizationUsageEmbeddings) + + /** The aggregated moderations usage details of the specific time bucket. */ + fun organizationUsageModerations(): Optional = + Optional.ofNullable(organizationUsageModerations) + + /** The aggregated images usage details of the specific time bucket. */ + fun organizationUsageImages(): Optional = + Optional.ofNullable(organizationUsageImages) + + /** The aggregated audio speeches usage details of the specific time bucket. */ + fun organizationUsageAudioSpeeches(): Optional = + Optional.ofNullable(organizationUsageAudioSpeeches) + + /** The aggregated audio transcriptions usage details of the specific time bucket. */ + fun organizationUsageAudioTranscriptions(): + Optional = + Optional.ofNullable(organizationUsageAudioTranscriptions) + + /** The aggregated vector stores usage details of the specific time bucket. */ + fun organizationUsageVectorStores(): Optional = + Optional.ofNullable(organizationUsageVectorStores) + + /** + * The aggregated code interpreter sessions usage details of the specific time bucket. + */ + fun organizationUsageCodeInterpreterSessions(): + Optional = + Optional.ofNullable(organizationUsageCodeInterpreterSessions) + + /** The aggregated file search calls usage details of the specific time bucket. */ + fun organizationUsageFileSearches(): Optional = + Optional.ofNullable(organizationUsageFileSearches) + + /** The aggregated web search calls usage details of the specific time bucket. */ + fun organizationUsageWebSearches(): Optional = + Optional.ofNullable(organizationUsageWebSearches) + + /** The aggregated costs details of the specific time bucket. */ + fun organizationCosts(): Optional = + Optional.ofNullable(organizationCosts) + + fun isOrganizationUsageCompletions(): Boolean = organizationUsageCompletions != null + + fun isOrganizationUsageEmbeddings(): Boolean = organizationUsageEmbeddings != null + + fun isOrganizationUsageModerations(): Boolean = organizationUsageModerations != null + + fun isOrganizationUsageImages(): Boolean = organizationUsageImages != null + + fun isOrganizationUsageAudioSpeeches(): Boolean = organizationUsageAudioSpeeches != null + + fun isOrganizationUsageAudioTranscriptions(): Boolean = + organizationUsageAudioTranscriptions != null + + fun isOrganizationUsageVectorStores(): Boolean = organizationUsageVectorStores != null + + fun isOrganizationUsageCodeInterpreterSessions(): Boolean = + organizationUsageCodeInterpreterSessions != null + + fun isOrganizationUsageFileSearches(): Boolean = organizationUsageFileSearches != null + + fun isOrganizationUsageWebSearches(): Boolean = organizationUsageWebSearches != null + + fun isOrganizationCosts(): Boolean = organizationCosts != null + + /** The aggregated completions usage details of the specific time bucket. */ + fun asOrganizationUsageCompletions(): OrganizationUsageCompletionsResult = + organizationUsageCompletions.getOrThrow("organizationUsageCompletions") + + /** The aggregated embeddings usage details of the specific time bucket. */ + fun asOrganizationUsageEmbeddings(): OrganizationUsageEmbeddingsResult = + organizationUsageEmbeddings.getOrThrow("organizationUsageEmbeddings") + + /** The aggregated moderations usage details of the specific time bucket. */ + fun asOrganizationUsageModerations(): OrganizationUsageModerationsResult = + organizationUsageModerations.getOrThrow("organizationUsageModerations") + + /** The aggregated images usage details of the specific time bucket. */ + fun asOrganizationUsageImages(): OrganizationUsageImagesResult = + organizationUsageImages.getOrThrow("organizationUsageImages") + + /** The aggregated audio speeches usage details of the specific time bucket. */ + fun asOrganizationUsageAudioSpeeches(): OrganizationUsageAudioSpeechesResult = + organizationUsageAudioSpeeches.getOrThrow("organizationUsageAudioSpeeches") + + /** The aggregated audio transcriptions usage details of the specific time bucket. */ + fun asOrganizationUsageAudioTranscriptions(): + OrganizationUsageAudioTranscriptionsResult = + organizationUsageAudioTranscriptions.getOrThrow( + "organizationUsageAudioTranscriptions" + ) + + /** The aggregated vector stores usage details of the specific time bucket. */ + fun asOrganizationUsageVectorStores(): OrganizationUsageVectorStoresResult = + organizationUsageVectorStores.getOrThrow("organizationUsageVectorStores") + + /** + * The aggregated code interpreter sessions usage details of the specific time bucket. + */ + fun asOrganizationUsageCodeInterpreterSessions(): + OrganizationUsageCodeInterpreterSessionsResult = + organizationUsageCodeInterpreterSessions.getOrThrow( + "organizationUsageCodeInterpreterSessions" + ) + + /** The aggregated file search calls usage details of the specific time bucket. */ + fun asOrganizationUsageFileSearches(): OrganizationUsageFileSearchesResult = + organizationUsageFileSearches.getOrThrow("organizationUsageFileSearches") + + /** The aggregated web search calls usage details of the specific time bucket. */ + fun asOrganizationUsageWebSearches(): OrganizationUsageWebSearchesResult = + organizationUsageWebSearches.getOrThrow("organizationUsageWebSearches") + + /** The aggregated costs details of the specific time bucket. */ + fun asOrganizationCosts(): OrganizationCostsResult = + organizationCosts.getOrThrow("organizationCosts") + + fun _json(): Optional = Optional.ofNullable(_json) + + /** + * Maps this instance's current variant to a value of type [T] using the given + * [visitor]. + * + * Note that this method is _not_ forwards compatible with new variants from the API, + * unless [visitor] overrides [Visitor.unknown]. To handle variants not known to this + * version of the SDK gracefully, consider overriding [Visitor.unknown]: + * ```java + * import com.openai.core.JsonValue; + * import java.util.Optional; + * + * Optional result = result.accept(new Result.Visitor>() { + * @Override + * public Optional visitOrganizationUsageCompletions(OrganizationUsageCompletionsResult organizationUsageCompletions) { + * return Optional.of(organizationUsageCompletions.toString()); + * } + * + * // ... + * + * @Override + * public Optional unknown(JsonValue json) { + * // Or inspect the `json`. + * return Optional.empty(); + * } + * }); + * ``` + * + * @throws OpenAIInvalidDataException if [Visitor.unknown] is not overridden in + * [visitor] and the current variant is unknown. + */ + fun accept(visitor: Visitor): T = + when { + organizationUsageCompletions != null -> + visitor.visitOrganizationUsageCompletions(organizationUsageCompletions) + organizationUsageEmbeddings != null -> + visitor.visitOrganizationUsageEmbeddings(organizationUsageEmbeddings) + organizationUsageModerations != null -> + visitor.visitOrganizationUsageModerations(organizationUsageModerations) + organizationUsageImages != null -> + visitor.visitOrganizationUsageImages(organizationUsageImages) + organizationUsageAudioSpeeches != null -> + visitor.visitOrganizationUsageAudioSpeeches(organizationUsageAudioSpeeches) + organizationUsageAudioTranscriptions != null -> + visitor.visitOrganizationUsageAudioTranscriptions( + organizationUsageAudioTranscriptions + ) + organizationUsageVectorStores != null -> + visitor.visitOrganizationUsageVectorStores(organizationUsageVectorStores) + organizationUsageCodeInterpreterSessions != null -> + visitor.visitOrganizationUsageCodeInterpreterSessions( + organizationUsageCodeInterpreterSessions + ) + organizationUsageFileSearches != null -> + visitor.visitOrganizationUsageFileSearches(organizationUsageFileSearches) + organizationUsageWebSearches != null -> + visitor.visitOrganizationUsageWebSearches(organizationUsageWebSearches) + organizationCosts != null -> visitor.visitOrganizationCosts(organizationCosts) + else -> visitor.unknown(_json) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing + * fields. + * + * @throws OpenAIInvalidDataException if any value type in this object doesn't match its + * expected type. + */ + fun validate(): Result = apply { + if (validated) { + return@apply + } + + accept( + object : Visitor { + override fun visitOrganizationUsageCompletions( + organizationUsageCompletions: OrganizationUsageCompletionsResult + ) { + organizationUsageCompletions.validate() + } + + override fun visitOrganizationUsageEmbeddings( + organizationUsageEmbeddings: OrganizationUsageEmbeddingsResult + ) { + organizationUsageEmbeddings.validate() + } + + override fun visitOrganizationUsageModerations( + organizationUsageModerations: OrganizationUsageModerationsResult + ) { + organizationUsageModerations.validate() + } + + override fun visitOrganizationUsageImages( + organizationUsageImages: OrganizationUsageImagesResult + ) { + organizationUsageImages.validate() + } + + override fun visitOrganizationUsageAudioSpeeches( + organizationUsageAudioSpeeches: OrganizationUsageAudioSpeechesResult + ) { + organizationUsageAudioSpeeches.validate() + } + + override fun visitOrganizationUsageAudioTranscriptions( + organizationUsageAudioTranscriptions: + OrganizationUsageAudioTranscriptionsResult + ) { + organizationUsageAudioTranscriptions.validate() + } + + override fun visitOrganizationUsageVectorStores( + organizationUsageVectorStores: OrganizationUsageVectorStoresResult + ) { + organizationUsageVectorStores.validate() + } + + override fun visitOrganizationUsageCodeInterpreterSessions( + organizationUsageCodeInterpreterSessions: + OrganizationUsageCodeInterpreterSessionsResult + ) { + organizationUsageCodeInterpreterSessions.validate() + } + + override fun visitOrganizationUsageFileSearches( + organizationUsageFileSearches: OrganizationUsageFileSearchesResult + ) { + organizationUsageFileSearches.validate() + } + + override fun visitOrganizationUsageWebSearches( + organizationUsageWebSearches: OrganizationUsageWebSearchesResult + ) { + organizationUsageWebSearches.validate() + } + + override fun visitOrganizationCosts( + organizationCosts: OrganizationCostsResult + ) { + organizationCosts.validate() + } + } + ) + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OpenAIInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + accept( + object : Visitor { + override fun visitOrganizationUsageCompletions( + organizationUsageCompletions: OrganizationUsageCompletionsResult + ) = organizationUsageCompletions.validity() + + override fun visitOrganizationUsageEmbeddings( + organizationUsageEmbeddings: OrganizationUsageEmbeddingsResult + ) = organizationUsageEmbeddings.validity() + + override fun visitOrganizationUsageModerations( + organizationUsageModerations: OrganizationUsageModerationsResult + ) = organizationUsageModerations.validity() + + override fun visitOrganizationUsageImages( + organizationUsageImages: OrganizationUsageImagesResult + ) = organizationUsageImages.validity() + + override fun visitOrganizationUsageAudioSpeeches( + organizationUsageAudioSpeeches: OrganizationUsageAudioSpeechesResult + ) = organizationUsageAudioSpeeches.validity() + + override fun visitOrganizationUsageAudioTranscriptions( + organizationUsageAudioTranscriptions: + OrganizationUsageAudioTranscriptionsResult + ) = organizationUsageAudioTranscriptions.validity() + + override fun visitOrganizationUsageVectorStores( + organizationUsageVectorStores: OrganizationUsageVectorStoresResult + ) = organizationUsageVectorStores.validity() + + override fun visitOrganizationUsageCodeInterpreterSessions( + organizationUsageCodeInterpreterSessions: + OrganizationUsageCodeInterpreterSessionsResult + ) = organizationUsageCodeInterpreterSessions.validity() + + override fun visitOrganizationUsageFileSearches( + organizationUsageFileSearches: OrganizationUsageFileSearchesResult + ) = organizationUsageFileSearches.validity() + + override fun visitOrganizationUsageWebSearches( + organizationUsageWebSearches: OrganizationUsageWebSearchesResult + ) = organizationUsageWebSearches.validity() + + override fun visitOrganizationCosts( + organizationCosts: OrganizationCostsResult + ) = organizationCosts.validity() + + override fun unknown(json: JsonValue?) = 0 + } + ) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Result && + organizationUsageCompletions == other.organizationUsageCompletions && + organizationUsageEmbeddings == other.organizationUsageEmbeddings && + organizationUsageModerations == other.organizationUsageModerations && + organizationUsageImages == other.organizationUsageImages && + organizationUsageAudioSpeeches == other.organizationUsageAudioSpeeches && + organizationUsageAudioTranscriptions == + other.organizationUsageAudioTranscriptions && + organizationUsageVectorStores == other.organizationUsageVectorStores && + organizationUsageCodeInterpreterSessions == + other.organizationUsageCodeInterpreterSessions && + organizationUsageFileSearches == other.organizationUsageFileSearches && + organizationUsageWebSearches == other.organizationUsageWebSearches && + organizationCosts == other.organizationCosts + } + + override fun hashCode(): Int = + Objects.hash( + organizationUsageCompletions, + organizationUsageEmbeddings, + organizationUsageModerations, + organizationUsageImages, + organizationUsageAudioSpeeches, + organizationUsageAudioTranscriptions, + organizationUsageVectorStores, + organizationUsageCodeInterpreterSessions, + organizationUsageFileSearches, + organizationUsageWebSearches, + organizationCosts, + ) + + override fun toString(): String = + when { + organizationUsageCompletions != null -> + "Result{organizationUsageCompletions=$organizationUsageCompletions}" + organizationUsageEmbeddings != null -> + "Result{organizationUsageEmbeddings=$organizationUsageEmbeddings}" + organizationUsageModerations != null -> + "Result{organizationUsageModerations=$organizationUsageModerations}" + organizationUsageImages != null -> + "Result{organizationUsageImages=$organizationUsageImages}" + organizationUsageAudioSpeeches != null -> + "Result{organizationUsageAudioSpeeches=$organizationUsageAudioSpeeches}" + organizationUsageAudioTranscriptions != null -> + "Result{organizationUsageAudioTranscriptions=$organizationUsageAudioTranscriptions}" + organizationUsageVectorStores != null -> + "Result{organizationUsageVectorStores=$organizationUsageVectorStores}" + organizationUsageCodeInterpreterSessions != null -> + "Result{organizationUsageCodeInterpreterSessions=$organizationUsageCodeInterpreterSessions}" + organizationUsageFileSearches != null -> + "Result{organizationUsageFileSearches=$organizationUsageFileSearches}" + organizationUsageWebSearches != null -> + "Result{organizationUsageWebSearches=$organizationUsageWebSearches}" + organizationCosts != null -> "Result{organizationCosts=$organizationCosts}" + _json != null -> "Result{_unknown=$_json}" + else -> throw IllegalStateException("Invalid Result") + } + + companion object { + + /** The aggregated completions usage details of the specific time bucket. */ + @JvmStatic + fun ofOrganizationUsageCompletions( + organizationUsageCompletions: OrganizationUsageCompletionsResult + ) = Result(organizationUsageCompletions = organizationUsageCompletions) + + /** The aggregated embeddings usage details of the specific time bucket. */ + @JvmStatic + fun ofOrganizationUsageEmbeddings( + organizationUsageEmbeddings: OrganizationUsageEmbeddingsResult + ) = Result(organizationUsageEmbeddings = organizationUsageEmbeddings) + + /** The aggregated moderations usage details of the specific time bucket. */ + @JvmStatic + fun ofOrganizationUsageModerations( + organizationUsageModerations: OrganizationUsageModerationsResult + ) = Result(organizationUsageModerations = organizationUsageModerations) + + /** The aggregated images usage details of the specific time bucket. */ + @JvmStatic + fun ofOrganizationUsageImages( + organizationUsageImages: OrganizationUsageImagesResult + ) = Result(organizationUsageImages = organizationUsageImages) + + /** The aggregated audio speeches usage details of the specific time bucket. */ + @JvmStatic + fun ofOrganizationUsageAudioSpeeches( + organizationUsageAudioSpeeches: OrganizationUsageAudioSpeechesResult + ) = Result(organizationUsageAudioSpeeches = organizationUsageAudioSpeeches) + + /** + * The aggregated audio transcriptions usage details of the specific time bucket. + */ + @JvmStatic + fun ofOrganizationUsageAudioTranscriptions( + organizationUsageAudioTranscriptions: OrganizationUsageAudioTranscriptionsResult + ) = + Result( + organizationUsageAudioTranscriptions = organizationUsageAudioTranscriptions + ) + + /** The aggregated vector stores usage details of the specific time bucket. */ + @JvmStatic + fun ofOrganizationUsageVectorStores( + organizationUsageVectorStores: OrganizationUsageVectorStoresResult + ) = Result(organizationUsageVectorStores = organizationUsageVectorStores) + + /** + * The aggregated code interpreter sessions usage details of the specific time + * bucket. + */ + @JvmStatic + fun ofOrganizationUsageCodeInterpreterSessions( + organizationUsageCodeInterpreterSessions: + OrganizationUsageCodeInterpreterSessionsResult + ) = + Result( + organizationUsageCodeInterpreterSessions = + organizationUsageCodeInterpreterSessions + ) + + /** The aggregated file search calls usage details of the specific time bucket. */ + @JvmStatic + fun ofOrganizationUsageFileSearches( + organizationUsageFileSearches: OrganizationUsageFileSearchesResult + ) = Result(organizationUsageFileSearches = organizationUsageFileSearches) + + /** The aggregated web search calls usage details of the specific time bucket. */ + @JvmStatic + fun ofOrganizationUsageWebSearches( + organizationUsageWebSearches: OrganizationUsageWebSearchesResult + ) = Result(organizationUsageWebSearches = organizationUsageWebSearches) + + /** The aggregated costs details of the specific time bucket. */ + @JvmStatic + fun ofOrganizationCosts(organizationCosts: OrganizationCostsResult) = + Result(organizationCosts = organizationCosts) + } + + /** + * An interface that defines how to map each variant of [Result] to a value of type [T]. + */ + interface Visitor { + + /** The aggregated completions usage details of the specific time bucket. */ + fun visitOrganizationUsageCompletions( + organizationUsageCompletions: OrganizationUsageCompletionsResult + ): T + + /** The aggregated embeddings usage details of the specific time bucket. */ + fun visitOrganizationUsageEmbeddings( + organizationUsageEmbeddings: OrganizationUsageEmbeddingsResult + ): T + + /** The aggregated moderations usage details of the specific time bucket. */ + fun visitOrganizationUsageModerations( + organizationUsageModerations: OrganizationUsageModerationsResult + ): T + + /** The aggregated images usage details of the specific time bucket. */ + fun visitOrganizationUsageImages( + organizationUsageImages: OrganizationUsageImagesResult + ): T + + /** The aggregated audio speeches usage details of the specific time bucket. */ + fun visitOrganizationUsageAudioSpeeches( + organizationUsageAudioSpeeches: OrganizationUsageAudioSpeechesResult + ): T + + /** + * The aggregated audio transcriptions usage details of the specific time bucket. + */ + fun visitOrganizationUsageAudioTranscriptions( + organizationUsageAudioTranscriptions: OrganizationUsageAudioTranscriptionsResult + ): T + + /** The aggregated vector stores usage details of the specific time bucket. */ + fun visitOrganizationUsageVectorStores( + organizationUsageVectorStores: OrganizationUsageVectorStoresResult + ): T + + /** + * The aggregated code interpreter sessions usage details of the specific time + * bucket. + */ + fun visitOrganizationUsageCodeInterpreterSessions( + organizationUsageCodeInterpreterSessions: + OrganizationUsageCodeInterpreterSessionsResult + ): T + + /** The aggregated file search calls usage details of the specific time bucket. */ + fun visitOrganizationUsageFileSearches( + organizationUsageFileSearches: OrganizationUsageFileSearchesResult + ): T + + /** The aggregated web search calls usage details of the specific time bucket. */ + fun visitOrganizationUsageWebSearches( + organizationUsageWebSearches: OrganizationUsageWebSearchesResult + ): T + + /** The aggregated costs details of the specific time bucket. */ + fun visitOrganizationCosts(organizationCosts: OrganizationCostsResult): T + + /** + * Maps an unknown variant of [Result] to a value of type [T]. + * + * An instance of [Result] can contain an unknown variant if it was deserialized + * from data that doesn't match any known variant. For example, if the SDK is on an + * older version than the API, then the API may respond with new variants that the + * SDK is unaware of. + * + * @throws OpenAIInvalidDataException in the default implementation. + */ + fun unknown(json: JsonValue?): T { + throw OpenAIInvalidDataException("Unknown Result: $json") + } + } + + internal class Deserializer : BaseDeserializer(Result::class) { + + override fun ObjectCodec.deserialize(node: JsonNode): Result { + val json = JsonValue.fromJsonNode(node) + val object_ = + json.asObject().getOrNull()?.get("object")?.asString()?.getOrNull() + + when (object_) { + "organization.usage.completions.result" -> { + return tryDeserialize( + node, + jacksonTypeRef(), + ) + ?.let { Result(organizationUsageCompletions = it, _json = json) } + ?: Result(_json = json) + } + "organization.usage.embeddings.result" -> { + return tryDeserialize( + node, + jacksonTypeRef(), + ) + ?.let { Result(organizationUsageEmbeddings = it, _json = json) } + ?: Result(_json = json) + } + "organization.usage.moderations.result" -> { + return tryDeserialize( + node, + jacksonTypeRef(), + ) + ?.let { Result(organizationUsageModerations = it, _json = json) } + ?: Result(_json = json) + } + "organization.usage.images.result" -> { + return tryDeserialize( + node, + jacksonTypeRef(), + ) + ?.let { Result(organizationUsageImages = it, _json = json) } + ?: Result(_json = json) + } + "organization.usage.audio_speeches.result" -> { + return tryDeserialize( + node, + jacksonTypeRef(), + ) + ?.let { Result(organizationUsageAudioSpeeches = it, _json = json) } + ?: Result(_json = json) + } + "organization.usage.audio_transcriptions.result" -> { + return tryDeserialize( + node, + jacksonTypeRef(), + ) + ?.let { + Result(organizationUsageAudioTranscriptions = it, _json = json) + } ?: Result(_json = json) + } + "organization.usage.vector_stores.result" -> { + return tryDeserialize( + node, + jacksonTypeRef(), + ) + ?.let { Result(organizationUsageVectorStores = it, _json = json) } + ?: Result(_json = json) + } + "organization.usage.code_interpreter_sessions.result" -> { + return tryDeserialize( + node, + jacksonTypeRef(), + ) + ?.let { + Result( + organizationUsageCodeInterpreterSessions = it, + _json = json, + ) + } ?: Result(_json = json) + } + "organization.usage.file_searches.result" -> { + return tryDeserialize( + node, + jacksonTypeRef(), + ) + ?.let { Result(organizationUsageFileSearches = it, _json = json) } + ?: Result(_json = json) + } + "organization.usage.web_searches.result" -> { + return tryDeserialize( + node, + jacksonTypeRef(), + ) + ?.let { Result(organizationUsageWebSearches = it, _json = json) } + ?: Result(_json = json) + } + "organization.costs.result" -> { + return tryDeserialize(node, jacksonTypeRef()) + ?.let { Result(organizationCosts = it, _json = json) } + ?: Result(_json = json) + } + } + + return Result(_json = json) + } + } + + internal class Serializer : BaseSerializer(Result::class) { + + override fun serialize( + value: Result, + generator: JsonGenerator, + provider: SerializerProvider, + ) { + when { + value.organizationUsageCompletions != null -> + generator.writeObject(value.organizationUsageCompletions) + value.organizationUsageEmbeddings != null -> + generator.writeObject(value.organizationUsageEmbeddings) + value.organizationUsageModerations != null -> + generator.writeObject(value.organizationUsageModerations) + value.organizationUsageImages != null -> + generator.writeObject(value.organizationUsageImages) + value.organizationUsageAudioSpeeches != null -> + generator.writeObject(value.organizationUsageAudioSpeeches) + value.organizationUsageAudioTranscriptions != null -> + generator.writeObject(value.organizationUsageAudioTranscriptions) + value.organizationUsageVectorStores != null -> + generator.writeObject(value.organizationUsageVectorStores) + value.organizationUsageCodeInterpreterSessions != null -> + generator.writeObject(value.organizationUsageCodeInterpreterSessions) + value.organizationUsageFileSearches != null -> + generator.writeObject(value.organizationUsageFileSearches) + value.organizationUsageWebSearches != null -> + generator.writeObject(value.organizationUsageWebSearches) + value.organizationCosts != null -> + generator.writeObject(value.organizationCosts) + value._json != null -> generator.writeObject(value._json) + else -> throw IllegalStateException("Invalid Result") + } + } + } + + /** The aggregated completions usage details of the specific time bucket. */ + class OrganizationUsageCompletionsResult + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val inputTokens: JsonField, + private val numModelRequests: JsonField, + private val object_: JsonValue, + private val outputTokens: JsonField, + private val apiKeyId: JsonField, + private val batch: JsonField, + private val inputAudioTokens: JsonField, + private val inputCachedTokens: JsonField, + private val model: JsonField, + private val outputAudioTokens: JsonField, + private val projectId: JsonField, + private val serviceTier: JsonField, + private val userId: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("input_tokens") + @ExcludeMissing + inputTokens: JsonField = JsonMissing.of(), + @JsonProperty("num_model_requests") + @ExcludeMissing + numModelRequests: JsonField = JsonMissing.of(), + @JsonProperty("object") @ExcludeMissing object_: JsonValue = JsonMissing.of(), + @JsonProperty("output_tokens") + @ExcludeMissing + outputTokens: JsonField = JsonMissing.of(), + @JsonProperty("api_key_id") + @ExcludeMissing + apiKeyId: JsonField = JsonMissing.of(), + @JsonProperty("batch") + @ExcludeMissing + batch: JsonField = JsonMissing.of(), + @JsonProperty("input_audio_tokens") + @ExcludeMissing + inputAudioTokens: JsonField = JsonMissing.of(), + @JsonProperty("input_cached_tokens") + @ExcludeMissing + inputCachedTokens: JsonField = JsonMissing.of(), + @JsonProperty("model") + @ExcludeMissing + model: JsonField = JsonMissing.of(), + @JsonProperty("output_audio_tokens") + @ExcludeMissing + outputAudioTokens: JsonField = JsonMissing.of(), + @JsonProperty("project_id") + @ExcludeMissing + projectId: JsonField = JsonMissing.of(), + @JsonProperty("service_tier") + @ExcludeMissing + serviceTier: JsonField = JsonMissing.of(), + @JsonProperty("user_id") + @ExcludeMissing + userId: JsonField = JsonMissing.of(), + ) : this( + inputTokens, + numModelRequests, + object_, + outputTokens, + apiKeyId, + batch, + inputAudioTokens, + inputCachedTokens, + model, + outputAudioTokens, + projectId, + serviceTier, + userId, + mutableMapOf(), + ) + + /** + * The aggregated number of text input tokens used, including cached tokens. For + * customers subscribe to scale tier, this includes scale tier tokens. + * + * @throws OpenAIInvalidDataException 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 inputTokens(): Long = inputTokens.getRequired("input_tokens") + + /** + * The count of requests made to the model. + * + * @throws OpenAIInvalidDataException 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 numModelRequests(): Long = numModelRequests.getRequired("num_model_requests") + + /** + * Expected to always return the following: + * ```java + * JsonValue.from("organization.usage.completions.result") + * ``` + * + * However, this method can be useful for debugging and logging (e.g. if the server + * responded with an unexpected value). + */ + @JsonProperty("object") @ExcludeMissing fun _object_(): JsonValue = object_ + + /** + * The aggregated number of text output tokens used. For customers subscribe to + * scale tier, this includes scale tier tokens. + * + * @throws OpenAIInvalidDataException 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 outputTokens(): Long = outputTokens.getRequired("output_tokens") + + /** + * When `group_by=api_key_id`, this field provides the API key ID of the grouped + * usage result. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun apiKeyId(): Optional = apiKeyId.getOptional("api_key_id") + + /** + * When `group_by=batch`, this field tells whether the grouped usage result is batch + * or not. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun batch(): Optional = batch.getOptional("batch") + + /** + * The aggregated number of audio input tokens used, including cached tokens. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun inputAudioTokens(): Optional = + inputAudioTokens.getOptional("input_audio_tokens") + + /** + * The aggregated number of text input tokens that has been cached from previous + * requests. For customers subscribe to scale tier, this includes scale tier tokens. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun inputCachedTokens(): Optional = + inputCachedTokens.getOptional("input_cached_tokens") + + /** + * When `group_by=model`, this field provides the model name of the grouped usage + * result. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun model(): Optional = model.getOptional("model") + + /** + * The aggregated number of audio output tokens used. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun outputAudioTokens(): Optional = + outputAudioTokens.getOptional("output_audio_tokens") + + /** + * When `group_by=project_id`, this field provides the project ID of the grouped + * usage result. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun projectId(): Optional = projectId.getOptional("project_id") + + /** + * When `group_by=service_tier`, this field provides the service tier of the grouped + * usage result. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun serviceTier(): Optional = serviceTier.getOptional("service_tier") + + /** + * When `group_by=user_id`, this field provides the user ID of the grouped usage + * result. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun userId(): Optional = userId.getOptional("user_id") + + /** + * Returns the raw JSON value of [inputTokens]. + * + * Unlike [inputTokens], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("input_tokens") + @ExcludeMissing + fun _inputTokens(): JsonField = inputTokens + + /** + * Returns the raw JSON value of [numModelRequests]. + * + * Unlike [numModelRequests], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("num_model_requests") + @ExcludeMissing + fun _numModelRequests(): JsonField = numModelRequests + + /** + * Returns the raw JSON value of [outputTokens]. + * + * Unlike [outputTokens], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("output_tokens") + @ExcludeMissing + fun _outputTokens(): JsonField = outputTokens + + /** + * Returns the raw JSON value of [apiKeyId]. + * + * Unlike [apiKeyId], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("api_key_id") + @ExcludeMissing + fun _apiKeyId(): JsonField = apiKeyId + + /** + * Returns the raw JSON value of [batch]. + * + * Unlike [batch], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("batch") @ExcludeMissing fun _batch(): JsonField = batch + + /** + * Returns the raw JSON value of [inputAudioTokens]. + * + * Unlike [inputAudioTokens], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("input_audio_tokens") + @ExcludeMissing + fun _inputAudioTokens(): JsonField = inputAudioTokens + + /** + * Returns the raw JSON value of [inputCachedTokens]. + * + * Unlike [inputCachedTokens], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("input_cached_tokens") + @ExcludeMissing + fun _inputCachedTokens(): JsonField = inputCachedTokens + + /** + * Returns the raw JSON value of [model]. + * + * Unlike [model], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("model") @ExcludeMissing fun _model(): JsonField = model + + /** + * Returns the raw JSON value of [outputAudioTokens]. + * + * Unlike [outputAudioTokens], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("output_audio_tokens") + @ExcludeMissing + fun _outputAudioTokens(): JsonField = outputAudioTokens + + /** + * 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 [serviceTier]. + * + * Unlike [serviceTier], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("service_tier") + @ExcludeMissing + fun _serviceTier(): JsonField = serviceTier + + /** + * 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 + + @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 + * [OrganizationUsageCompletionsResult]. + * + * The following fields are required: + * ```java + * .inputTokens() + * .numModelRequests() + * .outputTokens() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [OrganizationUsageCompletionsResult]. */ + class Builder internal constructor() { + + private var inputTokens: JsonField? = null + private var numModelRequests: JsonField? = null + private var object_: JsonValue = + JsonValue.from("organization.usage.completions.result") + private var outputTokens: JsonField? = null + private var apiKeyId: JsonField = JsonMissing.of() + private var batch: JsonField = JsonMissing.of() + private var inputAudioTokens: JsonField = JsonMissing.of() + private var inputCachedTokens: JsonField = JsonMissing.of() + private var model: JsonField = JsonMissing.of() + private var outputAudioTokens: JsonField = JsonMissing.of() + private var projectId: JsonField = JsonMissing.of() + private var serviceTier: JsonField = JsonMissing.of() + private var userId: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from( + organizationUsageCompletionsResult: OrganizationUsageCompletionsResult + ) = apply { + inputTokens = organizationUsageCompletionsResult.inputTokens + numModelRequests = organizationUsageCompletionsResult.numModelRequests + object_ = organizationUsageCompletionsResult.object_ + outputTokens = organizationUsageCompletionsResult.outputTokens + apiKeyId = organizationUsageCompletionsResult.apiKeyId + batch = organizationUsageCompletionsResult.batch + inputAudioTokens = organizationUsageCompletionsResult.inputAudioTokens + inputCachedTokens = organizationUsageCompletionsResult.inputCachedTokens + model = organizationUsageCompletionsResult.model + outputAudioTokens = organizationUsageCompletionsResult.outputAudioTokens + projectId = organizationUsageCompletionsResult.projectId + serviceTier = organizationUsageCompletionsResult.serviceTier + userId = organizationUsageCompletionsResult.userId + additionalProperties = + organizationUsageCompletionsResult.additionalProperties.toMutableMap() + } + + /** + * The aggregated number of text input tokens used, including cached tokens. For + * customers subscribe to scale tier, this includes scale tier tokens. + */ + fun inputTokens(inputTokens: Long) = inputTokens(JsonField.of(inputTokens)) + + /** + * Sets [Builder.inputTokens] to an arbitrary JSON value. + * + * You should usually call [Builder.inputTokens] with a well-typed [Long] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun inputTokens(inputTokens: JsonField) = apply { + this.inputTokens = inputTokens + } + + /** The count of requests made to the model. */ + fun numModelRequests(numModelRequests: Long) = + numModelRequests(JsonField.of(numModelRequests)) + + /** + * Sets [Builder.numModelRequests] to an arbitrary JSON value. + * + * You should usually call [Builder.numModelRequests] with a well-typed [Long] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun numModelRequests(numModelRequests: JsonField) = apply { + this.numModelRequests = numModelRequests + } + + /** + * Sets the field to an arbitrary JSON value. + * + * It is usually unnecessary to call this method because the field defaults to + * the following: + * ```java + * JsonValue.from("organization.usage.completions.result") + * ``` + * + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun object_(object_: JsonValue) = apply { this.object_ = object_ } + + /** + * The aggregated number of text output tokens used. For customers subscribe to + * scale tier, this includes scale tier tokens. + */ + fun outputTokens(outputTokens: Long) = outputTokens(JsonField.of(outputTokens)) + + /** + * Sets [Builder.outputTokens] to an arbitrary JSON value. + * + * You should usually call [Builder.outputTokens] with a well-typed [Long] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun outputTokens(outputTokens: JsonField) = apply { + this.outputTokens = outputTokens + } + + /** + * When `group_by=api_key_id`, this field provides the API key ID of the grouped + * usage result. + */ + fun apiKeyId(apiKeyId: String?) = apiKeyId(JsonField.ofNullable(apiKeyId)) + + /** Alias for calling [Builder.apiKeyId] with `apiKeyId.orElse(null)`. */ + fun apiKeyId(apiKeyId: Optional) = apiKeyId(apiKeyId.getOrNull()) + + /** + * Sets [Builder.apiKeyId] to an arbitrary JSON value. + * + * You should usually call [Builder.apiKeyId] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun apiKeyId(apiKeyId: JsonField) = apply { this.apiKeyId = apiKeyId } + + /** + * When `group_by=batch`, this field tells whether the grouped usage result is + * batch or not. + */ + fun batch(batch: Boolean?) = batch(JsonField.ofNullable(batch)) + + /** + * Alias for [Builder.batch]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun batch(batch: Boolean) = batch(batch as Boolean?) + + /** Alias for calling [Builder.batch] with `batch.orElse(null)`. */ + fun batch(batch: Optional) = batch(batch.getOrNull()) + + /** + * Sets [Builder.batch] to an arbitrary JSON value. + * + * You should usually call [Builder.batch] with a well-typed [Boolean] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun batch(batch: JsonField) = apply { this.batch = batch } + + /** + * The aggregated number of audio input tokens used, including cached tokens. + */ + fun inputAudioTokens(inputAudioTokens: Long) = + inputAudioTokens(JsonField.of(inputAudioTokens)) + + /** + * Sets [Builder.inputAudioTokens] to an arbitrary JSON value. + * + * You should usually call [Builder.inputAudioTokens] with a well-typed [Long] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun inputAudioTokens(inputAudioTokens: JsonField) = apply { + this.inputAudioTokens = inputAudioTokens + } + + /** + * The aggregated number of text input tokens that has been cached from previous + * requests. For customers subscribe to scale tier, this includes scale tier + * tokens. + */ + fun inputCachedTokens(inputCachedTokens: Long) = + inputCachedTokens(JsonField.of(inputCachedTokens)) + + /** + * Sets [Builder.inputCachedTokens] to an arbitrary JSON value. + * + * You should usually call [Builder.inputCachedTokens] with a well-typed [Long] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun inputCachedTokens(inputCachedTokens: JsonField) = apply { + this.inputCachedTokens = inputCachedTokens + } + + /** + * When `group_by=model`, this field provides the model name of the grouped + * usage result. + */ + fun model(model: String?) = model(JsonField.ofNullable(model)) + + /** Alias for calling [Builder.model] with `model.orElse(null)`. */ + fun model(model: Optional) = model(model.getOrNull()) + + /** + * Sets [Builder.model] to an arbitrary JSON value. + * + * You should usually call [Builder.model] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun model(model: JsonField) = apply { this.model = model } + + /** The aggregated number of audio output tokens used. */ + fun outputAudioTokens(outputAudioTokens: Long) = + outputAudioTokens(JsonField.of(outputAudioTokens)) + + /** + * Sets [Builder.outputAudioTokens] to an arbitrary JSON value. + * + * You should usually call [Builder.outputAudioTokens] with a well-typed [Long] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun outputAudioTokens(outputAudioTokens: JsonField) = apply { + this.outputAudioTokens = outputAudioTokens + } + + /** + * When `group_by=project_id`, this field provides the project ID of the grouped + * usage result. + */ + fun projectId(projectId: String?) = projectId(JsonField.ofNullable(projectId)) + + /** Alias for calling [Builder.projectId] with `projectId.orElse(null)`. */ + fun projectId(projectId: Optional) = projectId(projectId.getOrNull()) + + /** + * 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 + } + + /** + * When `group_by=service_tier`, this field provides the service tier of the + * grouped usage result. + */ + fun serviceTier(serviceTier: String?) = + serviceTier(JsonField.ofNullable(serviceTier)) + + /** Alias for calling [Builder.serviceTier] with `serviceTier.orElse(null)`. */ + fun serviceTier(serviceTier: Optional) = + serviceTier(serviceTier.getOrNull()) + + /** + * Sets [Builder.serviceTier] to an arbitrary JSON value. + * + * You should usually call [Builder.serviceTier] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun serviceTier(serviceTier: JsonField) = apply { + this.serviceTier = serviceTier + } + + /** + * When `group_by=user_id`, this field provides the user ID of the grouped usage + * result. + */ + 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 } + + 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 [OrganizationUsageCompletionsResult]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .inputTokens() + * .numModelRequests() + * .outputTokens() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): OrganizationUsageCompletionsResult = + OrganizationUsageCompletionsResult( + checkRequired("inputTokens", inputTokens), + checkRequired("numModelRequests", numModelRequests), + object_, + checkRequired("outputTokens", outputTokens), + apiKeyId, + batch, + inputAudioTokens, + inputCachedTokens, + model, + outputAudioTokens, + projectId, + serviceTier, + userId, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing + * fields. + * + * @throws OpenAIInvalidDataException if any value type in this object doesn't match + * its expected type. + */ + fun validate(): OrganizationUsageCompletionsResult = apply { + if (validated) { + return@apply + } + + inputTokens() + numModelRequests() + _object_().let { + if (it != JsonValue.from("organization.usage.completions.result")) { + throw OpenAIInvalidDataException("'object_' is invalid, received $it") + } + } + outputTokens() + apiKeyId() + batch() + inputAudioTokens() + inputCachedTokens() + model() + outputAudioTokens() + projectId() + serviceTier() + userId() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OpenAIInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (if (inputTokens.asKnown().isPresent) 1 else 0) + + (if (numModelRequests.asKnown().isPresent) 1 else 0) + + object_.let { + if (it == JsonValue.from("organization.usage.completions.result")) 1 + else 0 + } + + (if (outputTokens.asKnown().isPresent) 1 else 0) + + (if (apiKeyId.asKnown().isPresent) 1 else 0) + + (if (batch.asKnown().isPresent) 1 else 0) + + (if (inputAudioTokens.asKnown().isPresent) 1 else 0) + + (if (inputCachedTokens.asKnown().isPresent) 1 else 0) + + (if (model.asKnown().isPresent) 1 else 0) + + (if (outputAudioTokens.asKnown().isPresent) 1 else 0) + + (if (projectId.asKnown().isPresent) 1 else 0) + + (if (serviceTier.asKnown().isPresent) 1 else 0) + + (if (userId.asKnown().isPresent) 1 else 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is OrganizationUsageCompletionsResult && + inputTokens == other.inputTokens && + numModelRequests == other.numModelRequests && + object_ == other.object_ && + outputTokens == other.outputTokens && + apiKeyId == other.apiKeyId && + batch == other.batch && + inputAudioTokens == other.inputAudioTokens && + inputCachedTokens == other.inputCachedTokens && + model == other.model && + outputAudioTokens == other.outputAudioTokens && + projectId == other.projectId && + serviceTier == other.serviceTier && + userId == other.userId && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + inputTokens, + numModelRequests, + object_, + outputTokens, + apiKeyId, + batch, + inputAudioTokens, + inputCachedTokens, + model, + outputAudioTokens, + projectId, + serviceTier, + userId, + additionalProperties, + ) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "OrganizationUsageCompletionsResult{inputTokens=$inputTokens, numModelRequests=$numModelRequests, object_=$object_, outputTokens=$outputTokens, apiKeyId=$apiKeyId, batch=$batch, inputAudioTokens=$inputAudioTokens, inputCachedTokens=$inputCachedTokens, model=$model, outputAudioTokens=$outputAudioTokens, projectId=$projectId, serviceTier=$serviceTier, userId=$userId, additionalProperties=$additionalProperties}" + } + + /** The aggregated embeddings usage details of the specific time bucket. */ + class OrganizationUsageEmbeddingsResult + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val inputTokens: JsonField, + private val numModelRequests: JsonField, + private val object_: JsonValue, + private val apiKeyId: JsonField, + private val model: JsonField, + private val projectId: JsonField, + private val userId: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("input_tokens") + @ExcludeMissing + inputTokens: JsonField = JsonMissing.of(), + @JsonProperty("num_model_requests") + @ExcludeMissing + numModelRequests: JsonField = JsonMissing.of(), + @JsonProperty("object") @ExcludeMissing object_: JsonValue = JsonMissing.of(), + @JsonProperty("api_key_id") + @ExcludeMissing + apiKeyId: JsonField = JsonMissing.of(), + @JsonProperty("model") + @ExcludeMissing + model: JsonField = JsonMissing.of(), + @JsonProperty("project_id") + @ExcludeMissing + projectId: JsonField = JsonMissing.of(), + @JsonProperty("user_id") + @ExcludeMissing + userId: JsonField = JsonMissing.of(), + ) : this( + inputTokens, + numModelRequests, + object_, + apiKeyId, + model, + projectId, + userId, + mutableMapOf(), + ) + + /** + * The aggregated number of input tokens used. + * + * @throws OpenAIInvalidDataException 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 inputTokens(): Long = inputTokens.getRequired("input_tokens") + + /** + * The count of requests made to the model. + * + * @throws OpenAIInvalidDataException 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 numModelRequests(): Long = numModelRequests.getRequired("num_model_requests") + + /** + * Expected to always return the following: + * ```java + * JsonValue.from("organization.usage.embeddings.result") + * ``` + * + * However, this method can be useful for debugging and logging (e.g. if the server + * responded with an unexpected value). + */ + @JsonProperty("object") @ExcludeMissing fun _object_(): JsonValue = object_ + + /** + * When `group_by=api_key_id`, this field provides the API key ID of the grouped + * usage result. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun apiKeyId(): Optional = apiKeyId.getOptional("api_key_id") + + /** + * When `group_by=model`, this field provides the model name of the grouped usage + * result. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun model(): Optional = model.getOptional("model") + + /** + * When `group_by=project_id`, this field provides the project ID of the grouped + * usage result. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun projectId(): Optional = projectId.getOptional("project_id") + + /** + * When `group_by=user_id`, this field provides the user ID of the grouped usage + * result. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun userId(): Optional = userId.getOptional("user_id") + + /** + * Returns the raw JSON value of [inputTokens]. + * + * Unlike [inputTokens], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("input_tokens") + @ExcludeMissing + fun _inputTokens(): JsonField = inputTokens + + /** + * Returns the raw JSON value of [numModelRequests]. + * + * Unlike [numModelRequests], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("num_model_requests") + @ExcludeMissing + fun _numModelRequests(): JsonField = numModelRequests + + /** + * Returns the raw JSON value of [apiKeyId]. + * + * Unlike [apiKeyId], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("api_key_id") + @ExcludeMissing + fun _apiKeyId(): JsonField = apiKeyId + + /** + * Returns the raw JSON value of [model]. + * + * Unlike [model], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("model") @ExcludeMissing fun _model(): JsonField = model + + /** + * 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 [userId]. + * + * Unlike [userId], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @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 = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of + * [OrganizationUsageEmbeddingsResult]. + * + * The following fields are required: + * ```java + * .inputTokens() + * .numModelRequests() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [OrganizationUsageEmbeddingsResult]. */ + class Builder internal constructor() { + + private var inputTokens: JsonField? = null + private var numModelRequests: JsonField? = null + private var object_: JsonValue = + JsonValue.from("organization.usage.embeddings.result") + private var apiKeyId: JsonField = JsonMissing.of() + private var model: JsonField = JsonMissing.of() + private var projectId: JsonField = JsonMissing.of() + private var userId: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from( + organizationUsageEmbeddingsResult: OrganizationUsageEmbeddingsResult + ) = apply { + inputTokens = organizationUsageEmbeddingsResult.inputTokens + numModelRequests = organizationUsageEmbeddingsResult.numModelRequests + object_ = organizationUsageEmbeddingsResult.object_ + apiKeyId = organizationUsageEmbeddingsResult.apiKeyId + model = organizationUsageEmbeddingsResult.model + projectId = organizationUsageEmbeddingsResult.projectId + userId = organizationUsageEmbeddingsResult.userId + additionalProperties = + organizationUsageEmbeddingsResult.additionalProperties.toMutableMap() + } + + /** The aggregated number of input tokens used. */ + fun inputTokens(inputTokens: Long) = inputTokens(JsonField.of(inputTokens)) + + /** + * Sets [Builder.inputTokens] to an arbitrary JSON value. + * + * You should usually call [Builder.inputTokens] with a well-typed [Long] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun inputTokens(inputTokens: JsonField) = apply { + this.inputTokens = inputTokens + } + + /** The count of requests made to the model. */ + fun numModelRequests(numModelRequests: Long) = + numModelRequests(JsonField.of(numModelRequests)) + + /** + * Sets [Builder.numModelRequests] to an arbitrary JSON value. + * + * You should usually call [Builder.numModelRequests] with a well-typed [Long] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun numModelRequests(numModelRequests: JsonField) = apply { + this.numModelRequests = numModelRequests + } + + /** + * Sets the field to an arbitrary JSON value. + * + * It is usually unnecessary to call this method because the field defaults to + * the following: + * ```java + * JsonValue.from("organization.usage.embeddings.result") + * ``` + * + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun object_(object_: JsonValue) = apply { this.object_ = object_ } + + /** + * When `group_by=api_key_id`, this field provides the API key ID of the grouped + * usage result. + */ + fun apiKeyId(apiKeyId: String?) = apiKeyId(JsonField.ofNullable(apiKeyId)) + + /** Alias for calling [Builder.apiKeyId] with `apiKeyId.orElse(null)`. */ + fun apiKeyId(apiKeyId: Optional) = apiKeyId(apiKeyId.getOrNull()) + + /** + * Sets [Builder.apiKeyId] to an arbitrary JSON value. + * + * You should usually call [Builder.apiKeyId] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun apiKeyId(apiKeyId: JsonField) = apply { this.apiKeyId = apiKeyId } + + /** + * When `group_by=model`, this field provides the model name of the grouped + * usage result. + */ + fun model(model: String?) = model(JsonField.ofNullable(model)) + + /** Alias for calling [Builder.model] with `model.orElse(null)`. */ + fun model(model: Optional) = model(model.getOrNull()) + + /** + * Sets [Builder.model] to an arbitrary JSON value. + * + * You should usually call [Builder.model] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun model(model: JsonField) = apply { this.model = model } + + /** + * When `group_by=project_id`, this field provides the project ID of the grouped + * usage result. + */ + fun projectId(projectId: String?) = projectId(JsonField.ofNullable(projectId)) + + /** Alias for calling [Builder.projectId] with `projectId.orElse(null)`. */ + fun projectId(projectId: Optional) = projectId(projectId.getOrNull()) + + /** + * 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 + } + + /** + * When `group_by=user_id`, this field provides the user ID of the grouped usage + * result. + */ + 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 } + + 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 [OrganizationUsageEmbeddingsResult]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .inputTokens() + * .numModelRequests() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): OrganizationUsageEmbeddingsResult = + OrganizationUsageEmbeddingsResult( + checkRequired("inputTokens", inputTokens), + checkRequired("numModelRequests", numModelRequests), + object_, + apiKeyId, + model, + projectId, + userId, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing + * fields. + * + * @throws OpenAIInvalidDataException if any value type in this object doesn't match + * its expected type. + */ + fun validate(): OrganizationUsageEmbeddingsResult = apply { + if (validated) { + return@apply + } + + inputTokens() + numModelRequests() + _object_().let { + if (it != JsonValue.from("organization.usage.embeddings.result")) { + throw OpenAIInvalidDataException("'object_' is invalid, received $it") + } + } + apiKeyId() + model() + projectId() + userId() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OpenAIInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (if (inputTokens.asKnown().isPresent) 1 else 0) + + (if (numModelRequests.asKnown().isPresent) 1 else 0) + + object_.let { + if (it == JsonValue.from("organization.usage.embeddings.result")) 1 + else 0 + } + + (if (apiKeyId.asKnown().isPresent) 1 else 0) + + (if (model.asKnown().isPresent) 1 else 0) + + (if (projectId.asKnown().isPresent) 1 else 0) + + (if (userId.asKnown().isPresent) 1 else 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is OrganizationUsageEmbeddingsResult && + inputTokens == other.inputTokens && + numModelRequests == other.numModelRequests && + object_ == other.object_ && + apiKeyId == other.apiKeyId && + model == other.model && + projectId == other.projectId && + userId == other.userId && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + inputTokens, + numModelRequests, + object_, + apiKeyId, + model, + projectId, + userId, + additionalProperties, + ) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "OrganizationUsageEmbeddingsResult{inputTokens=$inputTokens, numModelRequests=$numModelRequests, object_=$object_, apiKeyId=$apiKeyId, model=$model, projectId=$projectId, userId=$userId, additionalProperties=$additionalProperties}" + } + + /** The aggregated moderations usage details of the specific time bucket. */ + class OrganizationUsageModerationsResult + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val inputTokens: JsonField, + private val numModelRequests: JsonField, + private val object_: JsonValue, + private val apiKeyId: JsonField, + private val model: JsonField, + private val projectId: JsonField, + private val userId: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("input_tokens") + @ExcludeMissing + inputTokens: JsonField = JsonMissing.of(), + @JsonProperty("num_model_requests") + @ExcludeMissing + numModelRequests: JsonField = JsonMissing.of(), + @JsonProperty("object") @ExcludeMissing object_: JsonValue = JsonMissing.of(), + @JsonProperty("api_key_id") + @ExcludeMissing + apiKeyId: JsonField = JsonMissing.of(), + @JsonProperty("model") + @ExcludeMissing + model: JsonField = JsonMissing.of(), + @JsonProperty("project_id") + @ExcludeMissing + projectId: JsonField = JsonMissing.of(), + @JsonProperty("user_id") + @ExcludeMissing + userId: JsonField = JsonMissing.of(), + ) : this( + inputTokens, + numModelRequests, + object_, + apiKeyId, + model, + projectId, + userId, + mutableMapOf(), + ) + + /** + * The aggregated number of input tokens used. + * + * @throws OpenAIInvalidDataException 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 inputTokens(): Long = inputTokens.getRequired("input_tokens") + + /** + * The count of requests made to the model. + * + * @throws OpenAIInvalidDataException 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 numModelRequests(): Long = numModelRequests.getRequired("num_model_requests") + + /** + * Expected to always return the following: + * ```java + * JsonValue.from("organization.usage.moderations.result") + * ``` + * + * However, this method can be useful for debugging and logging (e.g. if the server + * responded with an unexpected value). + */ + @JsonProperty("object") @ExcludeMissing fun _object_(): JsonValue = object_ + + /** + * When `group_by=api_key_id`, this field provides the API key ID of the grouped + * usage result. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun apiKeyId(): Optional = apiKeyId.getOptional("api_key_id") + + /** + * When `group_by=model`, this field provides the model name of the grouped usage + * result. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun model(): Optional = model.getOptional("model") + + /** + * When `group_by=project_id`, this field provides the project ID of the grouped + * usage result. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun projectId(): Optional = projectId.getOptional("project_id") + + /** + * When `group_by=user_id`, this field provides the user ID of the grouped usage + * result. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun userId(): Optional = userId.getOptional("user_id") + + /** + * Returns the raw JSON value of [inputTokens]. + * + * Unlike [inputTokens], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("input_tokens") + @ExcludeMissing + fun _inputTokens(): JsonField = inputTokens + + /** + * Returns the raw JSON value of [numModelRequests]. + * + * Unlike [numModelRequests], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("num_model_requests") + @ExcludeMissing + fun _numModelRequests(): JsonField = numModelRequests + + /** + * Returns the raw JSON value of [apiKeyId]. + * + * Unlike [apiKeyId], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("api_key_id") + @ExcludeMissing + fun _apiKeyId(): JsonField = apiKeyId + + /** + * Returns the raw JSON value of [model]. + * + * Unlike [model], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("model") @ExcludeMissing fun _model(): JsonField = model + + /** + * 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 [userId]. + * + * Unlike [userId], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @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 = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of + * [OrganizationUsageModerationsResult]. + * + * The following fields are required: + * ```java + * .inputTokens() + * .numModelRequests() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [OrganizationUsageModerationsResult]. */ + class Builder internal constructor() { + + private var inputTokens: JsonField? = null + private var numModelRequests: JsonField? = null + private var object_: JsonValue = + JsonValue.from("organization.usage.moderations.result") + private var apiKeyId: JsonField = JsonMissing.of() + private var model: JsonField = JsonMissing.of() + private var projectId: JsonField = JsonMissing.of() + private var userId: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from( + organizationUsageModerationsResult: OrganizationUsageModerationsResult + ) = apply { + inputTokens = organizationUsageModerationsResult.inputTokens + numModelRequests = organizationUsageModerationsResult.numModelRequests + object_ = organizationUsageModerationsResult.object_ + apiKeyId = organizationUsageModerationsResult.apiKeyId + model = organizationUsageModerationsResult.model + projectId = organizationUsageModerationsResult.projectId + userId = organizationUsageModerationsResult.userId + additionalProperties = + organizationUsageModerationsResult.additionalProperties.toMutableMap() + } + + /** The aggregated number of input tokens used. */ + fun inputTokens(inputTokens: Long) = inputTokens(JsonField.of(inputTokens)) + + /** + * Sets [Builder.inputTokens] to an arbitrary JSON value. + * + * You should usually call [Builder.inputTokens] with a well-typed [Long] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun inputTokens(inputTokens: JsonField) = apply { + this.inputTokens = inputTokens + } + + /** The count of requests made to the model. */ + fun numModelRequests(numModelRequests: Long) = + numModelRequests(JsonField.of(numModelRequests)) + + /** + * Sets [Builder.numModelRequests] to an arbitrary JSON value. + * + * You should usually call [Builder.numModelRequests] with a well-typed [Long] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun numModelRequests(numModelRequests: JsonField) = apply { + this.numModelRequests = numModelRequests + } + + /** + * Sets the field to an arbitrary JSON value. + * + * It is usually unnecessary to call this method because the field defaults to + * the following: + * ```java + * JsonValue.from("organization.usage.moderations.result") + * ``` + * + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun object_(object_: JsonValue) = apply { this.object_ = object_ } + + /** + * When `group_by=api_key_id`, this field provides the API key ID of the grouped + * usage result. + */ + fun apiKeyId(apiKeyId: String?) = apiKeyId(JsonField.ofNullable(apiKeyId)) + + /** Alias for calling [Builder.apiKeyId] with `apiKeyId.orElse(null)`. */ + fun apiKeyId(apiKeyId: Optional) = apiKeyId(apiKeyId.getOrNull()) + + /** + * Sets [Builder.apiKeyId] to an arbitrary JSON value. + * + * You should usually call [Builder.apiKeyId] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun apiKeyId(apiKeyId: JsonField) = apply { this.apiKeyId = apiKeyId } + + /** + * When `group_by=model`, this field provides the model name of the grouped + * usage result. + */ + fun model(model: String?) = model(JsonField.ofNullable(model)) + + /** Alias for calling [Builder.model] with `model.orElse(null)`. */ + fun model(model: Optional) = model(model.getOrNull()) + + /** + * Sets [Builder.model] to an arbitrary JSON value. + * + * You should usually call [Builder.model] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun model(model: JsonField) = apply { this.model = model } + + /** + * When `group_by=project_id`, this field provides the project ID of the grouped + * usage result. + */ + fun projectId(projectId: String?) = projectId(JsonField.ofNullable(projectId)) + + /** Alias for calling [Builder.projectId] with `projectId.orElse(null)`. */ + fun projectId(projectId: Optional) = projectId(projectId.getOrNull()) + + /** + * 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 + } + + /** + * When `group_by=user_id`, this field provides the user ID of the grouped usage + * result. + */ + 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 } + + 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 [OrganizationUsageModerationsResult]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .inputTokens() + * .numModelRequests() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): OrganizationUsageModerationsResult = + OrganizationUsageModerationsResult( + checkRequired("inputTokens", inputTokens), + checkRequired("numModelRequests", numModelRequests), + object_, + apiKeyId, + model, + projectId, + userId, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing + * fields. + * + * @throws OpenAIInvalidDataException if any value type in this object doesn't match + * its expected type. + */ + fun validate(): OrganizationUsageModerationsResult = apply { + if (validated) { + return@apply + } + + inputTokens() + numModelRequests() + _object_().let { + if (it != JsonValue.from("organization.usage.moderations.result")) { + throw OpenAIInvalidDataException("'object_' is invalid, received $it") + } + } + apiKeyId() + model() + projectId() + userId() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OpenAIInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (if (inputTokens.asKnown().isPresent) 1 else 0) + + (if (numModelRequests.asKnown().isPresent) 1 else 0) + + object_.let { + if (it == JsonValue.from("organization.usage.moderations.result")) 1 + else 0 + } + + (if (apiKeyId.asKnown().isPresent) 1 else 0) + + (if (model.asKnown().isPresent) 1 else 0) + + (if (projectId.asKnown().isPresent) 1 else 0) + + (if (userId.asKnown().isPresent) 1 else 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is OrganizationUsageModerationsResult && + inputTokens == other.inputTokens && + numModelRequests == other.numModelRequests && + object_ == other.object_ && + apiKeyId == other.apiKeyId && + model == other.model && + projectId == other.projectId && + userId == other.userId && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + inputTokens, + numModelRequests, + object_, + apiKeyId, + model, + projectId, + userId, + additionalProperties, + ) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "OrganizationUsageModerationsResult{inputTokens=$inputTokens, numModelRequests=$numModelRequests, object_=$object_, apiKeyId=$apiKeyId, model=$model, projectId=$projectId, userId=$userId, additionalProperties=$additionalProperties}" + } + + /** The aggregated images usage details of the specific time bucket. */ + class OrganizationUsageImagesResult + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val images: JsonField, + private val numModelRequests: JsonField, + private val object_: JsonValue, + private val apiKeyId: JsonField, + private val model: JsonField, + private val projectId: JsonField, + private val size: JsonField, + private val source: JsonField, + private val userId: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("images") + @ExcludeMissing + images: JsonField = JsonMissing.of(), + @JsonProperty("num_model_requests") + @ExcludeMissing + numModelRequests: JsonField = JsonMissing.of(), + @JsonProperty("object") @ExcludeMissing object_: JsonValue = JsonMissing.of(), + @JsonProperty("api_key_id") + @ExcludeMissing + apiKeyId: JsonField = JsonMissing.of(), + @JsonProperty("model") + @ExcludeMissing + model: JsonField = JsonMissing.of(), + @JsonProperty("project_id") + @ExcludeMissing + projectId: JsonField = JsonMissing.of(), + @JsonProperty("size") + @ExcludeMissing + size: JsonField = JsonMissing.of(), + @JsonProperty("source") + @ExcludeMissing + source: JsonField = JsonMissing.of(), + @JsonProperty("user_id") + @ExcludeMissing + userId: JsonField = JsonMissing.of(), + ) : this( + images, + numModelRequests, + object_, + apiKeyId, + model, + projectId, + size, + source, + userId, + mutableMapOf(), + ) + + /** + * The number of images processed. + * + * @throws OpenAIInvalidDataException 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 images(): Long = images.getRequired("images") + + /** + * The count of requests made to the model. + * + * @throws OpenAIInvalidDataException 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 numModelRequests(): Long = numModelRequests.getRequired("num_model_requests") + + /** + * Expected to always return the following: + * ```java + * JsonValue.from("organization.usage.images.result") + * ``` + * + * However, this method can be useful for debugging and logging (e.g. if the server + * responded with an unexpected value). + */ + @JsonProperty("object") @ExcludeMissing fun _object_(): JsonValue = object_ + + /** + * When `group_by=api_key_id`, this field provides the API key ID of the grouped + * usage result. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun apiKeyId(): Optional = apiKeyId.getOptional("api_key_id") + + /** + * When `group_by=model`, this field provides the model name of the grouped usage + * result. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun model(): Optional = model.getOptional("model") + + /** + * When `group_by=project_id`, this field provides the project ID of the grouped + * usage result. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun projectId(): Optional = projectId.getOptional("project_id") + + /** + * When `group_by=size`, this field provides the image size of the grouped usage + * result. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun size(): Optional = size.getOptional("size") + + /** + * When `group_by=source`, this field provides the source of the grouped usage + * result, possible values are `image.generation`, `image.edit`, `image.variation`. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun source(): Optional = source.getOptional("source") + + /** + * When `group_by=user_id`, this field provides the user ID of the grouped usage + * result. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun userId(): Optional = userId.getOptional("user_id") + + /** + * Returns the raw JSON value of [images]. + * + * Unlike [images], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("images") @ExcludeMissing fun _images(): JsonField = images + + /** + * Returns the raw JSON value of [numModelRequests]. + * + * Unlike [numModelRequests], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("num_model_requests") + @ExcludeMissing + fun _numModelRequests(): JsonField = numModelRequests + + /** + * Returns the raw JSON value of [apiKeyId]. + * + * Unlike [apiKeyId], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("api_key_id") + @ExcludeMissing + fun _apiKeyId(): JsonField = apiKeyId + + /** + * Returns the raw JSON value of [model]. + * + * Unlike [model], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("model") @ExcludeMissing fun _model(): JsonField = model + + /** + * 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 [size]. + * + * Unlike [size], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("size") @ExcludeMissing fun _size(): JsonField = size + + /** + * Returns the raw JSON value of [source]. + * + * Unlike [source], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("source") @ExcludeMissing fun _source(): JsonField = source + + /** + * 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 + + @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 + * [OrganizationUsageImagesResult]. + * + * The following fields are required: + * ```java + * .images() + * .numModelRequests() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [OrganizationUsageImagesResult]. */ + class Builder internal constructor() { + + private var images: JsonField? = null + private var numModelRequests: JsonField? = null + private var object_: JsonValue = + JsonValue.from("organization.usage.images.result") + private var apiKeyId: JsonField = JsonMissing.of() + private var model: JsonField = JsonMissing.of() + private var projectId: JsonField = JsonMissing.of() + private var size: JsonField = JsonMissing.of() + private var source: JsonField = JsonMissing.of() + private var userId: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from( + organizationUsageImagesResult: OrganizationUsageImagesResult + ) = apply { + images = organizationUsageImagesResult.images + numModelRequests = organizationUsageImagesResult.numModelRequests + object_ = organizationUsageImagesResult.object_ + apiKeyId = organizationUsageImagesResult.apiKeyId + model = organizationUsageImagesResult.model + projectId = organizationUsageImagesResult.projectId + size = organizationUsageImagesResult.size + source = organizationUsageImagesResult.source + userId = organizationUsageImagesResult.userId + additionalProperties = + organizationUsageImagesResult.additionalProperties.toMutableMap() + } + + /** The number of images processed. */ + fun images(images: Long) = images(JsonField.of(images)) + + /** + * Sets [Builder.images] to an arbitrary JSON value. + * + * You should usually call [Builder.images] with a well-typed [Long] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun images(images: JsonField) = apply { this.images = images } + + /** The count of requests made to the model. */ + fun numModelRequests(numModelRequests: Long) = + numModelRequests(JsonField.of(numModelRequests)) + + /** + * Sets [Builder.numModelRequests] to an arbitrary JSON value. + * + * You should usually call [Builder.numModelRequests] with a well-typed [Long] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun numModelRequests(numModelRequests: JsonField) = apply { + this.numModelRequests = numModelRequests + } + + /** + * Sets the field to an arbitrary JSON value. + * + * It is usually unnecessary to call this method because the field defaults to + * the following: + * ```java + * JsonValue.from("organization.usage.images.result") + * ``` + * + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun object_(object_: JsonValue) = apply { this.object_ = object_ } + + /** + * When `group_by=api_key_id`, this field provides the API key ID of the grouped + * usage result. + */ + fun apiKeyId(apiKeyId: String?) = apiKeyId(JsonField.ofNullable(apiKeyId)) + + /** Alias for calling [Builder.apiKeyId] with `apiKeyId.orElse(null)`. */ + fun apiKeyId(apiKeyId: Optional) = apiKeyId(apiKeyId.getOrNull()) + + /** + * Sets [Builder.apiKeyId] to an arbitrary JSON value. + * + * You should usually call [Builder.apiKeyId] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun apiKeyId(apiKeyId: JsonField) = apply { this.apiKeyId = apiKeyId } + + /** + * When `group_by=model`, this field provides the model name of the grouped + * usage result. + */ + fun model(model: String?) = model(JsonField.ofNullable(model)) + + /** Alias for calling [Builder.model] with `model.orElse(null)`. */ + fun model(model: Optional) = model(model.getOrNull()) + + /** + * Sets [Builder.model] to an arbitrary JSON value. + * + * You should usually call [Builder.model] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun model(model: JsonField) = apply { this.model = model } + + /** + * When `group_by=project_id`, this field provides the project ID of the grouped + * usage result. + */ + fun projectId(projectId: String?) = projectId(JsonField.ofNullable(projectId)) + + /** Alias for calling [Builder.projectId] with `projectId.orElse(null)`. */ + fun projectId(projectId: Optional) = projectId(projectId.getOrNull()) + + /** + * 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 + } + + /** + * When `group_by=size`, this field provides the image size of the grouped usage + * result. + */ + fun size(size: String?) = size(JsonField.ofNullable(size)) + + /** Alias for calling [Builder.size] with `size.orElse(null)`. */ + fun size(size: Optional) = size(size.getOrNull()) + + /** + * Sets [Builder.size] to an arbitrary JSON value. + * + * You should usually call [Builder.size] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun size(size: JsonField) = apply { this.size = size } + + /** + * When `group_by=source`, this field provides the source of the grouped usage + * result, possible values are `image.generation`, `image.edit`, + * `image.variation`. + */ + fun source(source: String?) = source(JsonField.ofNullable(source)) + + /** Alias for calling [Builder.source] with `source.orElse(null)`. */ + fun source(source: Optional) = source(source.getOrNull()) + + /** + * Sets [Builder.source] to an arbitrary JSON value. + * + * You should usually call [Builder.source] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun source(source: JsonField) = apply { this.source = source } + + /** + * When `group_by=user_id`, this field provides the user ID of the grouped usage + * result. + */ + 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 } + + 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 [OrganizationUsageImagesResult]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .images() + * .numModelRequests() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): OrganizationUsageImagesResult = + OrganizationUsageImagesResult( + checkRequired("images", images), + checkRequired("numModelRequests", numModelRequests), + object_, + apiKeyId, + model, + projectId, + size, + source, + userId, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing + * fields. + * + * @throws OpenAIInvalidDataException if any value type in this object doesn't match + * its expected type. + */ + fun validate(): OrganizationUsageImagesResult = apply { + if (validated) { + return@apply + } + + images() + numModelRequests() + _object_().let { + if (it != JsonValue.from("organization.usage.images.result")) { + throw OpenAIInvalidDataException("'object_' is invalid, received $it") + } + } + apiKeyId() + model() + projectId() + size() + source() + userId() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OpenAIInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (if (images.asKnown().isPresent) 1 else 0) + + (if (numModelRequests.asKnown().isPresent) 1 else 0) + + object_.let { + if (it == JsonValue.from("organization.usage.images.result")) 1 else 0 + } + + (if (apiKeyId.asKnown().isPresent) 1 else 0) + + (if (model.asKnown().isPresent) 1 else 0) + + (if (projectId.asKnown().isPresent) 1 else 0) + + (if (size.asKnown().isPresent) 1 else 0) + + (if (source.asKnown().isPresent) 1 else 0) + + (if (userId.asKnown().isPresent) 1 else 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is OrganizationUsageImagesResult && + images == other.images && + numModelRequests == other.numModelRequests && + object_ == other.object_ && + apiKeyId == other.apiKeyId && + model == other.model && + projectId == other.projectId && + size == other.size && + source == other.source && + userId == other.userId && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + images, + numModelRequests, + object_, + apiKeyId, + model, + projectId, + size, + source, + userId, + additionalProperties, + ) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "OrganizationUsageImagesResult{images=$images, numModelRequests=$numModelRequests, object_=$object_, apiKeyId=$apiKeyId, model=$model, projectId=$projectId, size=$size, source=$source, userId=$userId, additionalProperties=$additionalProperties}" + } + + /** The aggregated audio speeches usage details of the specific time bucket. */ + class OrganizationUsageAudioSpeechesResult + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val characters: JsonField, + private val numModelRequests: JsonField, + private val object_: JsonValue, + private val apiKeyId: JsonField, + private val model: JsonField, + private val projectId: JsonField, + private val userId: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("characters") + @ExcludeMissing + characters: JsonField = JsonMissing.of(), + @JsonProperty("num_model_requests") + @ExcludeMissing + numModelRequests: JsonField = JsonMissing.of(), + @JsonProperty("object") @ExcludeMissing object_: JsonValue = JsonMissing.of(), + @JsonProperty("api_key_id") + @ExcludeMissing + apiKeyId: JsonField = JsonMissing.of(), + @JsonProperty("model") + @ExcludeMissing + model: JsonField = JsonMissing.of(), + @JsonProperty("project_id") + @ExcludeMissing + projectId: JsonField = JsonMissing.of(), + @JsonProperty("user_id") + @ExcludeMissing + userId: JsonField = JsonMissing.of(), + ) : this( + characters, + numModelRequests, + object_, + apiKeyId, + model, + projectId, + userId, + mutableMapOf(), + ) + + /** + * The number of characters processed. + * + * @throws OpenAIInvalidDataException 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 characters(): Long = characters.getRequired("characters") + + /** + * The count of requests made to the model. + * + * @throws OpenAIInvalidDataException 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 numModelRequests(): Long = numModelRequests.getRequired("num_model_requests") + + /** + * Expected to always return the following: + * ```java + * JsonValue.from("organization.usage.audio_speeches.result") + * ``` + * + * However, this method can be useful for debugging and logging (e.g. if the server + * responded with an unexpected value). + */ + @JsonProperty("object") @ExcludeMissing fun _object_(): JsonValue = object_ + + /** + * When `group_by=api_key_id`, this field provides the API key ID of the grouped + * usage result. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun apiKeyId(): Optional = apiKeyId.getOptional("api_key_id") + + /** + * When `group_by=model`, this field provides the model name of the grouped usage + * result. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun model(): Optional = model.getOptional("model") + + /** + * When `group_by=project_id`, this field provides the project ID of the grouped + * usage result. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun projectId(): Optional = projectId.getOptional("project_id") + + /** + * When `group_by=user_id`, this field provides the user ID of the grouped usage + * result. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun userId(): Optional = userId.getOptional("user_id") + + /** + * Returns the raw JSON value of [characters]. + * + * Unlike [characters], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("characters") + @ExcludeMissing + fun _characters(): JsonField = characters + + /** + * Returns the raw JSON value of [numModelRequests]. + * + * Unlike [numModelRequests], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("num_model_requests") + @ExcludeMissing + fun _numModelRequests(): JsonField = numModelRequests + + /** + * Returns the raw JSON value of [apiKeyId]. + * + * Unlike [apiKeyId], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("api_key_id") + @ExcludeMissing + fun _apiKeyId(): JsonField = apiKeyId + + /** + * Returns the raw JSON value of [model]. + * + * Unlike [model], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("model") @ExcludeMissing fun _model(): JsonField = model + + /** + * 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 [userId]. + * + * Unlike [userId], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @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 = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of + * [OrganizationUsageAudioSpeechesResult]. + * + * The following fields are required: + * ```java + * .characters() + * .numModelRequests() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [OrganizationUsageAudioSpeechesResult]. */ + class Builder internal constructor() { + + private var characters: JsonField? = null + private var numModelRequests: JsonField? = null + private var object_: JsonValue = + JsonValue.from("organization.usage.audio_speeches.result") + private var apiKeyId: JsonField = JsonMissing.of() + private var model: JsonField = JsonMissing.of() + private var projectId: JsonField = JsonMissing.of() + private var userId: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from( + organizationUsageAudioSpeechesResult: OrganizationUsageAudioSpeechesResult + ) = apply { + characters = organizationUsageAudioSpeechesResult.characters + numModelRequests = organizationUsageAudioSpeechesResult.numModelRequests + object_ = organizationUsageAudioSpeechesResult.object_ + apiKeyId = organizationUsageAudioSpeechesResult.apiKeyId + model = organizationUsageAudioSpeechesResult.model + projectId = organizationUsageAudioSpeechesResult.projectId + userId = organizationUsageAudioSpeechesResult.userId + additionalProperties = + organizationUsageAudioSpeechesResult.additionalProperties.toMutableMap() + } + + /** The number of characters processed. */ + fun characters(characters: Long) = characters(JsonField.of(characters)) + + /** + * Sets [Builder.characters] to an arbitrary JSON value. + * + * You should usually call [Builder.characters] with a well-typed [Long] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun characters(characters: JsonField) = apply { + this.characters = characters + } + + /** The count of requests made to the model. */ + fun numModelRequests(numModelRequests: Long) = + numModelRequests(JsonField.of(numModelRequests)) + + /** + * Sets [Builder.numModelRequests] to an arbitrary JSON value. + * + * You should usually call [Builder.numModelRequests] with a well-typed [Long] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun numModelRequests(numModelRequests: JsonField) = apply { + this.numModelRequests = numModelRequests + } + + /** + * Sets the field to an arbitrary JSON value. + * + * It is usually unnecessary to call this method because the field defaults to + * the following: + * ```java + * JsonValue.from("organization.usage.audio_speeches.result") + * ``` + * + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun object_(object_: JsonValue) = apply { this.object_ = object_ } + + /** + * When `group_by=api_key_id`, this field provides the API key ID of the grouped + * usage result. + */ + fun apiKeyId(apiKeyId: String?) = apiKeyId(JsonField.ofNullable(apiKeyId)) + + /** Alias for calling [Builder.apiKeyId] with `apiKeyId.orElse(null)`. */ + fun apiKeyId(apiKeyId: Optional) = apiKeyId(apiKeyId.getOrNull()) + + /** + * Sets [Builder.apiKeyId] to an arbitrary JSON value. + * + * You should usually call [Builder.apiKeyId] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun apiKeyId(apiKeyId: JsonField) = apply { this.apiKeyId = apiKeyId } + + /** + * When `group_by=model`, this field provides the model name of the grouped + * usage result. + */ + fun model(model: String?) = model(JsonField.ofNullable(model)) + + /** Alias for calling [Builder.model] with `model.orElse(null)`. */ + fun model(model: Optional) = model(model.getOrNull()) + + /** + * Sets [Builder.model] to an arbitrary JSON value. + * + * You should usually call [Builder.model] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun model(model: JsonField) = apply { this.model = model } + + /** + * When `group_by=project_id`, this field provides the project ID of the grouped + * usage result. + */ + fun projectId(projectId: String?) = projectId(JsonField.ofNullable(projectId)) + + /** Alias for calling [Builder.projectId] with `projectId.orElse(null)`. */ + fun projectId(projectId: Optional) = projectId(projectId.getOrNull()) + + /** + * 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 + } + + /** + * When `group_by=user_id`, this field provides the user ID of the grouped usage + * result. + */ + 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 } + + 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 [OrganizationUsageAudioSpeechesResult]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .characters() + * .numModelRequests() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): OrganizationUsageAudioSpeechesResult = + OrganizationUsageAudioSpeechesResult( + checkRequired("characters", characters), + checkRequired("numModelRequests", numModelRequests), + object_, + apiKeyId, + model, + projectId, + userId, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing + * fields. + * + * @throws OpenAIInvalidDataException if any value type in this object doesn't match + * its expected type. + */ + fun validate(): OrganizationUsageAudioSpeechesResult = apply { + if (validated) { + return@apply + } + + characters() + numModelRequests() + _object_().let { + if (it != JsonValue.from("organization.usage.audio_speeches.result")) { + throw OpenAIInvalidDataException("'object_' is invalid, received $it") + } + } + apiKeyId() + model() + projectId() + userId() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OpenAIInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (if (characters.asKnown().isPresent) 1 else 0) + + (if (numModelRequests.asKnown().isPresent) 1 else 0) + + object_.let { + if (it == JsonValue.from("organization.usage.audio_speeches.result")) 1 + else 0 + } + + (if (apiKeyId.asKnown().isPresent) 1 else 0) + + (if (model.asKnown().isPresent) 1 else 0) + + (if (projectId.asKnown().isPresent) 1 else 0) + + (if (userId.asKnown().isPresent) 1 else 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is OrganizationUsageAudioSpeechesResult && + characters == other.characters && + numModelRequests == other.numModelRequests && + object_ == other.object_ && + apiKeyId == other.apiKeyId && + model == other.model && + projectId == other.projectId && + userId == other.userId && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + characters, + numModelRequests, + object_, + apiKeyId, + model, + projectId, + userId, + additionalProperties, + ) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "OrganizationUsageAudioSpeechesResult{characters=$characters, numModelRequests=$numModelRequests, object_=$object_, apiKeyId=$apiKeyId, model=$model, projectId=$projectId, userId=$userId, additionalProperties=$additionalProperties}" + } + + /** The aggregated audio transcriptions usage details of the specific time bucket. */ + class OrganizationUsageAudioTranscriptionsResult + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val numModelRequests: JsonField, + private val object_: JsonValue, + private val seconds: JsonField, + private val apiKeyId: JsonField, + private val model: JsonField, + private val projectId: JsonField, + private val userId: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("num_model_requests") + @ExcludeMissing + numModelRequests: JsonField = JsonMissing.of(), + @JsonProperty("object") @ExcludeMissing object_: JsonValue = JsonMissing.of(), + @JsonProperty("seconds") + @ExcludeMissing + seconds: JsonField = JsonMissing.of(), + @JsonProperty("api_key_id") + @ExcludeMissing + apiKeyId: JsonField = JsonMissing.of(), + @JsonProperty("model") + @ExcludeMissing + model: JsonField = JsonMissing.of(), + @JsonProperty("project_id") + @ExcludeMissing + projectId: JsonField = JsonMissing.of(), + @JsonProperty("user_id") + @ExcludeMissing + userId: JsonField = JsonMissing.of(), + ) : this( + numModelRequests, + object_, + seconds, + apiKeyId, + model, + projectId, + userId, + mutableMapOf(), + ) + + /** + * The count of requests made to the model. + * + * @throws OpenAIInvalidDataException 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 numModelRequests(): Long = numModelRequests.getRequired("num_model_requests") + + /** + * Expected to always return the following: + * ```java + * JsonValue.from("organization.usage.audio_transcriptions.result") + * ``` + * + * However, this method can be useful for debugging and logging (e.g. if the server + * responded with an unexpected value). + */ + @JsonProperty("object") @ExcludeMissing fun _object_(): JsonValue = object_ + + /** + * The number of seconds processed. + * + * @throws OpenAIInvalidDataException 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 seconds(): Long = seconds.getRequired("seconds") + + /** + * When `group_by=api_key_id`, this field provides the API key ID of the grouped + * usage result. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun apiKeyId(): Optional = apiKeyId.getOptional("api_key_id") + + /** + * When `group_by=model`, this field provides the model name of the grouped usage + * result. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun model(): Optional = model.getOptional("model") + + /** + * When `group_by=project_id`, this field provides the project ID of the grouped + * usage result. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun projectId(): Optional = projectId.getOptional("project_id") + + /** + * When `group_by=user_id`, this field provides the user ID of the grouped usage + * result. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun userId(): Optional = userId.getOptional("user_id") + + /** + * Returns the raw JSON value of [numModelRequests]. + * + * Unlike [numModelRequests], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("num_model_requests") + @ExcludeMissing + fun _numModelRequests(): JsonField = numModelRequests + + /** + * Returns the raw JSON value of [seconds]. + * + * Unlike [seconds], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("seconds") @ExcludeMissing fun _seconds(): JsonField = seconds + + /** + * Returns the raw JSON value of [apiKeyId]. + * + * Unlike [apiKeyId], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("api_key_id") + @ExcludeMissing + fun _apiKeyId(): JsonField = apiKeyId + + /** + * Returns the raw JSON value of [model]. + * + * Unlike [model], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("model") @ExcludeMissing fun _model(): JsonField = model + + /** + * 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 [userId]. + * + * Unlike [userId], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @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 = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of + * [OrganizationUsageAudioTranscriptionsResult]. + * + * The following fields are required: + * ```java + * .numModelRequests() + * .seconds() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [OrganizationUsageAudioTranscriptionsResult]. */ + class Builder internal constructor() { + + private var numModelRequests: JsonField? = null + private var object_: JsonValue = + JsonValue.from("organization.usage.audio_transcriptions.result") + private var seconds: JsonField? = null + private var apiKeyId: JsonField = JsonMissing.of() + private var model: JsonField = JsonMissing.of() + private var projectId: JsonField = JsonMissing.of() + private var userId: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from( + organizationUsageAudioTranscriptionsResult: + OrganizationUsageAudioTranscriptionsResult + ) = apply { + numModelRequests = + organizationUsageAudioTranscriptionsResult.numModelRequests + object_ = organizationUsageAudioTranscriptionsResult.object_ + seconds = organizationUsageAudioTranscriptionsResult.seconds + apiKeyId = organizationUsageAudioTranscriptionsResult.apiKeyId + model = organizationUsageAudioTranscriptionsResult.model + projectId = organizationUsageAudioTranscriptionsResult.projectId + userId = organizationUsageAudioTranscriptionsResult.userId + additionalProperties = + organizationUsageAudioTranscriptionsResult.additionalProperties + .toMutableMap() + } + + /** The count of requests made to the model. */ + fun numModelRequests(numModelRequests: Long) = + numModelRequests(JsonField.of(numModelRequests)) + + /** + * Sets [Builder.numModelRequests] to an arbitrary JSON value. + * + * You should usually call [Builder.numModelRequests] with a well-typed [Long] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun numModelRequests(numModelRequests: JsonField) = apply { + this.numModelRequests = numModelRequests + } + + /** + * Sets the field to an arbitrary JSON value. + * + * It is usually unnecessary to call this method because the field defaults to + * the following: + * ```java + * JsonValue.from("organization.usage.audio_transcriptions.result") + * ``` + * + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun object_(object_: JsonValue) = apply { this.object_ = object_ } + + /** The number of seconds processed. */ + fun seconds(seconds: Long) = seconds(JsonField.of(seconds)) + + /** + * Sets [Builder.seconds] to an arbitrary JSON value. + * + * You should usually call [Builder.seconds] with a well-typed [Long] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun seconds(seconds: JsonField) = apply { this.seconds = seconds } + + /** + * When `group_by=api_key_id`, this field provides the API key ID of the grouped + * usage result. + */ + fun apiKeyId(apiKeyId: String?) = apiKeyId(JsonField.ofNullable(apiKeyId)) + + /** Alias for calling [Builder.apiKeyId] with `apiKeyId.orElse(null)`. */ + fun apiKeyId(apiKeyId: Optional) = apiKeyId(apiKeyId.getOrNull()) + + /** + * Sets [Builder.apiKeyId] to an arbitrary JSON value. + * + * You should usually call [Builder.apiKeyId] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun apiKeyId(apiKeyId: JsonField) = apply { this.apiKeyId = apiKeyId } + + /** + * When `group_by=model`, this field provides the model name of the grouped + * usage result. + */ + fun model(model: String?) = model(JsonField.ofNullable(model)) + + /** Alias for calling [Builder.model] with `model.orElse(null)`. */ + fun model(model: Optional) = model(model.getOrNull()) + + /** + * Sets [Builder.model] to an arbitrary JSON value. + * + * You should usually call [Builder.model] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun model(model: JsonField) = apply { this.model = model } + + /** + * When `group_by=project_id`, this field provides the project ID of the grouped + * usage result. + */ + fun projectId(projectId: String?) = projectId(JsonField.ofNullable(projectId)) + + /** Alias for calling [Builder.projectId] with `projectId.orElse(null)`. */ + fun projectId(projectId: Optional) = projectId(projectId.getOrNull()) + + /** + * 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 + } + + /** + * When `group_by=user_id`, this field provides the user ID of the grouped usage + * result. + */ + 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 } + + 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 + * [OrganizationUsageAudioTranscriptionsResult]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .numModelRequests() + * .seconds() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): OrganizationUsageAudioTranscriptionsResult = + OrganizationUsageAudioTranscriptionsResult( + checkRequired("numModelRequests", numModelRequests), + object_, + checkRequired("seconds", seconds), + apiKeyId, + model, + projectId, + userId, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing + * fields. + * + * @throws OpenAIInvalidDataException if any value type in this object doesn't match + * its expected type. + */ + fun validate(): OrganizationUsageAudioTranscriptionsResult = apply { + if (validated) { + return@apply + } + + numModelRequests() + _object_().let { + if ( + it != JsonValue.from("organization.usage.audio_transcriptions.result") + ) { + throw OpenAIInvalidDataException("'object_' is invalid, received $it") + } + } + seconds() + apiKeyId() + model() + projectId() + userId() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OpenAIInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (if (numModelRequests.asKnown().isPresent) 1 else 0) + + object_.let { + if ( + it == + JsonValue.from("organization.usage.audio_transcriptions.result") + ) + 1 + else 0 + } + + (if (seconds.asKnown().isPresent) 1 else 0) + + (if (apiKeyId.asKnown().isPresent) 1 else 0) + + (if (model.asKnown().isPresent) 1 else 0) + + (if (projectId.asKnown().isPresent) 1 else 0) + + (if (userId.asKnown().isPresent) 1 else 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is OrganizationUsageAudioTranscriptionsResult && + numModelRequests == other.numModelRequests && + object_ == other.object_ && + seconds == other.seconds && + apiKeyId == other.apiKeyId && + model == other.model && + projectId == other.projectId && + userId == other.userId && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + numModelRequests, + object_, + seconds, + apiKeyId, + model, + projectId, + userId, + additionalProperties, + ) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "OrganizationUsageAudioTranscriptionsResult{numModelRequests=$numModelRequests, object_=$object_, seconds=$seconds, apiKeyId=$apiKeyId, model=$model, projectId=$projectId, userId=$userId, additionalProperties=$additionalProperties}" + } + + /** The aggregated vector stores usage details of the specific time bucket. */ + class OrganizationUsageVectorStoresResult + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val object_: JsonValue, + private val usageBytes: JsonField, + private val projectId: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("object") @ExcludeMissing object_: JsonValue = JsonMissing.of(), + @JsonProperty("usage_bytes") + @ExcludeMissing + usageBytes: JsonField = JsonMissing.of(), + @JsonProperty("project_id") + @ExcludeMissing + projectId: JsonField = JsonMissing.of(), + ) : this(object_, usageBytes, projectId, mutableMapOf()) + + /** + * Expected to always return the following: + * ```java + * JsonValue.from("organization.usage.vector_stores.result") + * ``` + * + * However, this method can be useful for debugging and logging (e.g. if the server + * responded with an unexpected value). + */ + @JsonProperty("object") @ExcludeMissing fun _object_(): JsonValue = object_ + + /** + * The vector stores usage in bytes. + * + * @throws OpenAIInvalidDataException 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 usageBytes(): Long = usageBytes.getRequired("usage_bytes") + + /** + * When `group_by=project_id`, this field provides the project ID of the grouped + * usage result. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun projectId(): Optional = projectId.getOptional("project_id") + + /** + * Returns the raw JSON value of [usageBytes]. + * + * Unlike [usageBytes], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("usage_bytes") + @ExcludeMissing + fun _usageBytes(): JsonField = usageBytes + + /** + * 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 + + @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 + * [OrganizationUsageVectorStoresResult]. + * + * The following fields are required: + * ```java + * .usageBytes() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [OrganizationUsageVectorStoresResult]. */ + class Builder internal constructor() { + + private var object_: JsonValue = + JsonValue.from("organization.usage.vector_stores.result") + private var usageBytes: JsonField? = null + private var projectId: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from( + organizationUsageVectorStoresResult: OrganizationUsageVectorStoresResult + ) = apply { + object_ = organizationUsageVectorStoresResult.object_ + usageBytes = organizationUsageVectorStoresResult.usageBytes + projectId = organizationUsageVectorStoresResult.projectId + additionalProperties = + organizationUsageVectorStoresResult.additionalProperties.toMutableMap() + } + + /** + * Sets the field to an arbitrary JSON value. + * + * It is usually unnecessary to call this method because the field defaults to + * the following: + * ```java + * JsonValue.from("organization.usage.vector_stores.result") + * ``` + * + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun object_(object_: JsonValue) = apply { this.object_ = object_ } + + /** The vector stores usage in bytes. */ + fun usageBytes(usageBytes: Long) = usageBytes(JsonField.of(usageBytes)) + + /** + * Sets [Builder.usageBytes] to an arbitrary JSON value. + * + * You should usually call [Builder.usageBytes] with a well-typed [Long] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun usageBytes(usageBytes: JsonField) = apply { + this.usageBytes = usageBytes + } + + /** + * When `group_by=project_id`, this field provides the project ID of the grouped + * usage result. + */ + fun projectId(projectId: String?) = projectId(JsonField.ofNullable(projectId)) + + /** Alias for calling [Builder.projectId] with `projectId.orElse(null)`. */ + fun projectId(projectId: Optional) = projectId(projectId.getOrNull()) + + /** + * 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 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 [OrganizationUsageVectorStoresResult]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .usageBytes() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): OrganizationUsageVectorStoresResult = + OrganizationUsageVectorStoresResult( + object_, + checkRequired("usageBytes", usageBytes), + projectId, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing + * fields. + * + * @throws OpenAIInvalidDataException if any value type in this object doesn't match + * its expected type. + */ + fun validate(): OrganizationUsageVectorStoresResult = apply { + if (validated) { + return@apply + } + + _object_().let { + if (it != JsonValue.from("organization.usage.vector_stores.result")) { + throw OpenAIInvalidDataException("'object_' is invalid, received $it") + } + } + usageBytes() + projectId() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OpenAIInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + object_.let { + if (it == JsonValue.from("organization.usage.vector_stores.result")) 1 + else 0 + } + + (if (usageBytes.asKnown().isPresent) 1 else 0) + + (if (projectId.asKnown().isPresent) 1 else 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is OrganizationUsageVectorStoresResult && + object_ == other.object_ && + usageBytes == other.usageBytes && + projectId == other.projectId && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(object_, usageBytes, projectId, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "OrganizationUsageVectorStoresResult{object_=$object_, usageBytes=$usageBytes, projectId=$projectId, additionalProperties=$additionalProperties}" + } + + /** + * The aggregated code interpreter sessions usage details of the specific time bucket. + */ + class OrganizationUsageCodeInterpreterSessionsResult + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val numSessions: JsonField, + private val object_: JsonValue, + private val projectId: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("num_sessions") + @ExcludeMissing + numSessions: JsonField = JsonMissing.of(), + @JsonProperty("object") @ExcludeMissing object_: JsonValue = JsonMissing.of(), + @JsonProperty("project_id") + @ExcludeMissing + projectId: JsonField = JsonMissing.of(), + ) : this(numSessions, object_, projectId, mutableMapOf()) + + /** + * The number of code interpreter sessions. + * + * @throws OpenAIInvalidDataException 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 numSessions(): Long = numSessions.getRequired("num_sessions") + + /** + * Expected to always return the following: + * ```java + * JsonValue.from("organization.usage.code_interpreter_sessions.result") + * ``` + * + * However, this method can be useful for debugging and logging (e.g. if the server + * responded with an unexpected value). + */ + @JsonProperty("object") @ExcludeMissing fun _object_(): JsonValue = object_ + + /** + * When `group_by=project_id`, this field provides the project ID of the grouped + * usage result. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun projectId(): Optional = projectId.getOptional("project_id") + + /** + * Returns the raw JSON value of [numSessions]. + * + * Unlike [numSessions], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("num_sessions") + @ExcludeMissing + fun _numSessions(): JsonField = numSessions + + /** + * 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 + + @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 + * [OrganizationUsageCodeInterpreterSessionsResult]. + * + * The following fields are required: + * ```java + * .numSessions() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [OrganizationUsageCodeInterpreterSessionsResult]. */ + class Builder internal constructor() { + + private var numSessions: JsonField? = null + private var object_: JsonValue = + JsonValue.from("organization.usage.code_interpreter_sessions.result") + private var projectId: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from( + organizationUsageCodeInterpreterSessionsResult: + OrganizationUsageCodeInterpreterSessionsResult + ) = apply { + numSessions = organizationUsageCodeInterpreterSessionsResult.numSessions + object_ = organizationUsageCodeInterpreterSessionsResult.object_ + projectId = organizationUsageCodeInterpreterSessionsResult.projectId + additionalProperties = + organizationUsageCodeInterpreterSessionsResult.additionalProperties + .toMutableMap() + } + + /** The number of code interpreter sessions. */ + fun numSessions(numSessions: Long) = numSessions(JsonField.of(numSessions)) + + /** + * Sets [Builder.numSessions] to an arbitrary JSON value. + * + * You should usually call [Builder.numSessions] with a well-typed [Long] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun numSessions(numSessions: JsonField) = apply { + this.numSessions = numSessions + } + + /** + * Sets the field to an arbitrary JSON value. + * + * It is usually unnecessary to call this method because the field defaults to + * the following: + * ```java + * JsonValue.from("organization.usage.code_interpreter_sessions.result") + * ``` + * + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun object_(object_: JsonValue) = apply { this.object_ = object_ } + + /** + * When `group_by=project_id`, this field provides the project ID of the grouped + * usage result. + */ + fun projectId(projectId: String?) = projectId(JsonField.ofNullable(projectId)) + + /** Alias for calling [Builder.projectId] with `projectId.orElse(null)`. */ + fun projectId(projectId: Optional) = projectId(projectId.getOrNull()) + + /** + * 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 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 + * [OrganizationUsageCodeInterpreterSessionsResult]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .numSessions() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): OrganizationUsageCodeInterpreterSessionsResult = + OrganizationUsageCodeInterpreterSessionsResult( + checkRequired("numSessions", numSessions), + object_, + projectId, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing + * fields. + * + * @throws OpenAIInvalidDataException if any value type in this object doesn't match + * its expected type. + */ + fun validate(): OrganizationUsageCodeInterpreterSessionsResult = apply { + if (validated) { + return@apply + } + + numSessions() + _object_().let { + if ( + it != + JsonValue.from( + "organization.usage.code_interpreter_sessions.result" + ) + ) { + throw OpenAIInvalidDataException("'object_' is invalid, received $it") + } + } + projectId() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OpenAIInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (if (numSessions.asKnown().isPresent) 1 else 0) + + object_.let { + if ( + it == + JsonValue.from( + "organization.usage.code_interpreter_sessions.result" + ) + ) + 1 + else 0 + } + + (if (projectId.asKnown().isPresent) 1 else 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is OrganizationUsageCodeInterpreterSessionsResult && + numSessions == other.numSessions && + object_ == other.object_ && + projectId == other.projectId && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(numSessions, object_, projectId, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "OrganizationUsageCodeInterpreterSessionsResult{numSessions=$numSessions, object_=$object_, projectId=$projectId, additionalProperties=$additionalProperties}" + } + + /** The aggregated file search calls usage details of the specific time bucket. */ + class OrganizationUsageFileSearchesResult + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val numRequests: JsonField, + private val object_: JsonValue, + private val apiKeyId: JsonField, + private val projectId: JsonField, + private val userId: JsonField, + private val vectorStoreId: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("num_requests") + @ExcludeMissing + numRequests: JsonField = JsonMissing.of(), + @JsonProperty("object") @ExcludeMissing object_: JsonValue = JsonMissing.of(), + @JsonProperty("api_key_id") + @ExcludeMissing + apiKeyId: JsonField = JsonMissing.of(), + @JsonProperty("project_id") + @ExcludeMissing + projectId: JsonField = JsonMissing.of(), + @JsonProperty("user_id") + @ExcludeMissing + userId: JsonField = JsonMissing.of(), + @JsonProperty("vector_store_id") + @ExcludeMissing + vectorStoreId: JsonField = JsonMissing.of(), + ) : this( + numRequests, + object_, + apiKeyId, + projectId, + userId, + vectorStoreId, + mutableMapOf(), + ) + + /** + * The count of file search calls. + * + * @throws OpenAIInvalidDataException 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 numRequests(): Long = numRequests.getRequired("num_requests") + + /** + * Expected to always return the following: + * ```java + * JsonValue.from("organization.usage.file_searches.result") + * ``` + * + * However, this method can be useful for debugging and logging (e.g. if the server + * responded with an unexpected value). + */ + @JsonProperty("object") @ExcludeMissing fun _object_(): JsonValue = object_ + + /** + * When `group_by=api_key_id`, this field provides the API key ID of the grouped + * usage result. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun apiKeyId(): Optional = apiKeyId.getOptional("api_key_id") + + /** + * When `group_by=project_id`, this field provides the project ID of the grouped + * usage result. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun projectId(): Optional = projectId.getOptional("project_id") + + /** + * When `group_by=user_id`, this field provides the user ID of the grouped usage + * result. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun userId(): Optional = userId.getOptional("user_id") + + /** + * When `group_by=vector_store_id`, this field provides the vector store ID of the + * grouped usage result. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun vectorStoreId(): Optional = vectorStoreId.getOptional("vector_store_id") + + /** + * Returns the raw JSON value of [numRequests]. + * + * Unlike [numRequests], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("num_requests") + @ExcludeMissing + fun _numRequests(): JsonField = numRequests + + /** + * Returns the raw JSON value of [apiKeyId]. + * + * Unlike [apiKeyId], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("api_key_id") + @ExcludeMissing + fun _apiKeyId(): JsonField = apiKeyId + + /** + * 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 [userId]. + * + * Unlike [userId], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("user_id") @ExcludeMissing fun _userId(): JsonField = userId + + /** + * Returns the raw JSON value of [vectorStoreId]. + * + * Unlike [vectorStoreId], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("vector_store_id") + @ExcludeMissing + fun _vectorStoreId(): JsonField = vectorStoreId + + @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 + * [OrganizationUsageFileSearchesResult]. + * + * The following fields are required: + * ```java + * .numRequests() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [OrganizationUsageFileSearchesResult]. */ + class Builder internal constructor() { + + private var numRequests: JsonField? = null + private var object_: JsonValue = + JsonValue.from("organization.usage.file_searches.result") + private var apiKeyId: JsonField = JsonMissing.of() + private var projectId: JsonField = JsonMissing.of() + private var userId: JsonField = JsonMissing.of() + private var vectorStoreId: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from( + organizationUsageFileSearchesResult: OrganizationUsageFileSearchesResult + ) = apply { + numRequests = organizationUsageFileSearchesResult.numRequests + object_ = organizationUsageFileSearchesResult.object_ + apiKeyId = organizationUsageFileSearchesResult.apiKeyId + projectId = organizationUsageFileSearchesResult.projectId + userId = organizationUsageFileSearchesResult.userId + vectorStoreId = organizationUsageFileSearchesResult.vectorStoreId + additionalProperties = + organizationUsageFileSearchesResult.additionalProperties.toMutableMap() + } + + /** The count of file search calls. */ + fun numRequests(numRequests: Long) = numRequests(JsonField.of(numRequests)) + + /** + * Sets [Builder.numRequests] to an arbitrary JSON value. + * + * You should usually call [Builder.numRequests] with a well-typed [Long] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun numRequests(numRequests: JsonField) = apply { + this.numRequests = numRequests + } + + /** + * Sets the field to an arbitrary JSON value. + * + * It is usually unnecessary to call this method because the field defaults to + * the following: + * ```java + * JsonValue.from("organization.usage.file_searches.result") + * ``` + * + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun object_(object_: JsonValue) = apply { this.object_ = object_ } + + /** + * When `group_by=api_key_id`, this field provides the API key ID of the grouped + * usage result. + */ + fun apiKeyId(apiKeyId: String?) = apiKeyId(JsonField.ofNullable(apiKeyId)) + + /** Alias for calling [Builder.apiKeyId] with `apiKeyId.orElse(null)`. */ + fun apiKeyId(apiKeyId: Optional) = apiKeyId(apiKeyId.getOrNull()) + + /** + * Sets [Builder.apiKeyId] to an arbitrary JSON value. + * + * You should usually call [Builder.apiKeyId] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun apiKeyId(apiKeyId: JsonField) = apply { this.apiKeyId = apiKeyId } + + /** + * When `group_by=project_id`, this field provides the project ID of the grouped + * usage result. + */ + fun projectId(projectId: String?) = projectId(JsonField.ofNullable(projectId)) + + /** Alias for calling [Builder.projectId] with `projectId.orElse(null)`. */ + fun projectId(projectId: Optional) = projectId(projectId.getOrNull()) + + /** + * 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 + } + + /** + * When `group_by=user_id`, this field provides the user ID of the grouped usage + * result. + */ + 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 } + + /** + * When `group_by=vector_store_id`, this field provides the vector store ID of + * the grouped usage result. + */ + fun vectorStoreId(vectorStoreId: String?) = + vectorStoreId(JsonField.ofNullable(vectorStoreId)) + + /** + * Alias for calling [Builder.vectorStoreId] with `vectorStoreId.orElse(null)`. + */ + fun vectorStoreId(vectorStoreId: Optional) = + vectorStoreId(vectorStoreId.getOrNull()) + + /** + * Sets [Builder.vectorStoreId] to an arbitrary JSON value. + * + * You should usually call [Builder.vectorStoreId] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun vectorStoreId(vectorStoreId: JsonField) = apply { + this.vectorStoreId = vectorStoreId + } + + 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 [OrganizationUsageFileSearchesResult]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .numRequests() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): OrganizationUsageFileSearchesResult = + OrganizationUsageFileSearchesResult( + checkRequired("numRequests", numRequests), + object_, + apiKeyId, + projectId, + userId, + vectorStoreId, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing + * fields. + * + * @throws OpenAIInvalidDataException if any value type in this object doesn't match + * its expected type. + */ + fun validate(): OrganizationUsageFileSearchesResult = apply { + if (validated) { + return@apply + } + + numRequests() + _object_().let { + if (it != JsonValue.from("organization.usage.file_searches.result")) { + throw OpenAIInvalidDataException("'object_' is invalid, received $it") + } + } + apiKeyId() + projectId() + userId() + vectorStoreId() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OpenAIInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (if (numRequests.asKnown().isPresent) 1 else 0) + + object_.let { + if (it == JsonValue.from("organization.usage.file_searches.result")) 1 + else 0 + } + + (if (apiKeyId.asKnown().isPresent) 1 else 0) + + (if (projectId.asKnown().isPresent) 1 else 0) + + (if (userId.asKnown().isPresent) 1 else 0) + + (if (vectorStoreId.asKnown().isPresent) 1 else 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is OrganizationUsageFileSearchesResult && + numRequests == other.numRequests && + object_ == other.object_ && + apiKeyId == other.apiKeyId && + projectId == other.projectId && + userId == other.userId && + vectorStoreId == other.vectorStoreId && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + numRequests, + object_, + apiKeyId, + projectId, + userId, + vectorStoreId, + additionalProperties, + ) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "OrganizationUsageFileSearchesResult{numRequests=$numRequests, object_=$object_, apiKeyId=$apiKeyId, projectId=$projectId, userId=$userId, vectorStoreId=$vectorStoreId, additionalProperties=$additionalProperties}" + } + + /** The aggregated web search calls usage details of the specific time bucket. */ + class OrganizationUsageWebSearchesResult + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val numModelRequests: JsonField, + private val numRequests: JsonField, + private val object_: JsonValue, + private val apiKeyId: JsonField, + private val contextLevel: JsonField, + private val model: JsonField, + private val projectId: JsonField, + private val userId: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("num_model_requests") + @ExcludeMissing + numModelRequests: JsonField = JsonMissing.of(), + @JsonProperty("num_requests") + @ExcludeMissing + numRequests: JsonField = JsonMissing.of(), + @JsonProperty("object") @ExcludeMissing object_: JsonValue = JsonMissing.of(), + @JsonProperty("api_key_id") + @ExcludeMissing + apiKeyId: JsonField = JsonMissing.of(), + @JsonProperty("context_level") + @ExcludeMissing + contextLevel: JsonField = JsonMissing.of(), + @JsonProperty("model") + @ExcludeMissing + model: JsonField = JsonMissing.of(), + @JsonProperty("project_id") + @ExcludeMissing + projectId: JsonField = JsonMissing.of(), + @JsonProperty("user_id") + @ExcludeMissing + userId: JsonField = JsonMissing.of(), + ) : this( + numModelRequests, + numRequests, + object_, + apiKeyId, + contextLevel, + model, + projectId, + userId, + mutableMapOf(), + ) + + /** + * The count of model requests. + * + * @throws OpenAIInvalidDataException 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 numModelRequests(): Long = numModelRequests.getRequired("num_model_requests") + + /** + * The count of web search calls. + * + * @throws OpenAIInvalidDataException 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 numRequests(): Long = numRequests.getRequired("num_requests") + + /** + * Expected to always return the following: + * ```java + * JsonValue.from("organization.usage.web_searches.result") + * ``` + * + * However, this method can be useful for debugging and logging (e.g. if the server + * responded with an unexpected value). + */ + @JsonProperty("object") @ExcludeMissing fun _object_(): JsonValue = object_ + + /** + * When `group_by=api_key_id`, this field provides the API key ID of the grouped + * usage result. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun apiKeyId(): Optional = apiKeyId.getOptional("api_key_id") + + /** + * When `group_by=context_level`, this field provides the search context size of the + * grouped usage result. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun contextLevel(): Optional = contextLevel.getOptional("context_level") + + /** + * When `group_by=model`, this field provides the model name of the grouped usage + * result. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun model(): Optional = model.getOptional("model") + + /** + * When `group_by=project_id`, this field provides the project ID of the grouped + * usage result. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun projectId(): Optional = projectId.getOptional("project_id") + + /** + * When `group_by=user_id`, this field provides the user ID of the grouped usage + * result. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun userId(): Optional = userId.getOptional("user_id") + + /** + * Returns the raw JSON value of [numModelRequests]. + * + * Unlike [numModelRequests], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("num_model_requests") + @ExcludeMissing + fun _numModelRequests(): JsonField = numModelRequests + + /** + * Returns the raw JSON value of [numRequests]. + * + * Unlike [numRequests], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("num_requests") + @ExcludeMissing + fun _numRequests(): JsonField = numRequests + + /** + * Returns the raw JSON value of [apiKeyId]. + * + * Unlike [apiKeyId], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("api_key_id") + @ExcludeMissing + fun _apiKeyId(): JsonField = apiKeyId + + /** + * Returns the raw JSON value of [contextLevel]. + * + * Unlike [contextLevel], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("context_level") + @ExcludeMissing + fun _contextLevel(): JsonField = contextLevel + + /** + * Returns the raw JSON value of [model]. + * + * Unlike [model], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("model") @ExcludeMissing fun _model(): JsonField = model + + /** + * 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 [userId]. + * + * Unlike [userId], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @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 = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of + * [OrganizationUsageWebSearchesResult]. + * + * The following fields are required: + * ```java + * .numModelRequests() + * .numRequests() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [OrganizationUsageWebSearchesResult]. */ + class Builder internal constructor() { + + private var numModelRequests: JsonField? = null + private var numRequests: JsonField? = null + private var object_: JsonValue = + JsonValue.from("organization.usage.web_searches.result") + private var apiKeyId: JsonField = JsonMissing.of() + private var contextLevel: JsonField = JsonMissing.of() + private var model: JsonField = JsonMissing.of() + private var projectId: JsonField = JsonMissing.of() + private var userId: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from( + organizationUsageWebSearchesResult: OrganizationUsageWebSearchesResult + ) = apply { + numModelRequests = organizationUsageWebSearchesResult.numModelRequests + numRequests = organizationUsageWebSearchesResult.numRequests + object_ = organizationUsageWebSearchesResult.object_ + apiKeyId = organizationUsageWebSearchesResult.apiKeyId + contextLevel = organizationUsageWebSearchesResult.contextLevel + model = organizationUsageWebSearchesResult.model + projectId = organizationUsageWebSearchesResult.projectId + userId = organizationUsageWebSearchesResult.userId + additionalProperties = + organizationUsageWebSearchesResult.additionalProperties.toMutableMap() + } + + /** The count of model requests. */ + fun numModelRequests(numModelRequests: Long) = + numModelRequests(JsonField.of(numModelRequests)) + + /** + * Sets [Builder.numModelRequests] to an arbitrary JSON value. + * + * You should usually call [Builder.numModelRequests] with a well-typed [Long] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun numModelRequests(numModelRequests: JsonField) = apply { + this.numModelRequests = numModelRequests + } + + /** The count of web search calls. */ + fun numRequests(numRequests: Long) = numRequests(JsonField.of(numRequests)) + + /** + * Sets [Builder.numRequests] to an arbitrary JSON value. + * + * You should usually call [Builder.numRequests] with a well-typed [Long] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun numRequests(numRequests: JsonField) = apply { + this.numRequests = numRequests + } + + /** + * Sets the field to an arbitrary JSON value. + * + * It is usually unnecessary to call this method because the field defaults to + * the following: + * ```java + * JsonValue.from("organization.usage.web_searches.result") + * ``` + * + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun object_(object_: JsonValue) = apply { this.object_ = object_ } + + /** + * When `group_by=api_key_id`, this field provides the API key ID of the grouped + * usage result. + */ + fun apiKeyId(apiKeyId: String?) = apiKeyId(JsonField.ofNullable(apiKeyId)) + + /** Alias for calling [Builder.apiKeyId] with `apiKeyId.orElse(null)`. */ + fun apiKeyId(apiKeyId: Optional) = apiKeyId(apiKeyId.getOrNull()) + + /** + * Sets [Builder.apiKeyId] to an arbitrary JSON value. + * + * You should usually call [Builder.apiKeyId] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun apiKeyId(apiKeyId: JsonField) = apply { this.apiKeyId = apiKeyId } + + /** + * When `group_by=context_level`, this field provides the search context size of + * the grouped usage result. + */ + fun contextLevel(contextLevel: String?) = + contextLevel(JsonField.ofNullable(contextLevel)) + + /** + * Alias for calling [Builder.contextLevel] with `contextLevel.orElse(null)`. + */ + fun contextLevel(contextLevel: Optional) = + contextLevel(contextLevel.getOrNull()) + + /** + * Sets [Builder.contextLevel] to an arbitrary JSON value. + * + * You should usually call [Builder.contextLevel] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun contextLevel(contextLevel: JsonField) = apply { + this.contextLevel = contextLevel + } + + /** + * When `group_by=model`, this field provides the model name of the grouped + * usage result. + */ + fun model(model: String?) = model(JsonField.ofNullable(model)) + + /** Alias for calling [Builder.model] with `model.orElse(null)`. */ + fun model(model: Optional) = model(model.getOrNull()) + + /** + * Sets [Builder.model] to an arbitrary JSON value. + * + * You should usually call [Builder.model] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun model(model: JsonField) = apply { this.model = model } + + /** + * When `group_by=project_id`, this field provides the project ID of the grouped + * usage result. + */ + fun projectId(projectId: String?) = projectId(JsonField.ofNullable(projectId)) + + /** Alias for calling [Builder.projectId] with `projectId.orElse(null)`. */ + fun projectId(projectId: Optional) = projectId(projectId.getOrNull()) + + /** + * 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 + } + + /** + * When `group_by=user_id`, this field provides the user ID of the grouped usage + * result. + */ + 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 } + + 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 [OrganizationUsageWebSearchesResult]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .numModelRequests() + * .numRequests() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): OrganizationUsageWebSearchesResult = + OrganizationUsageWebSearchesResult( + checkRequired("numModelRequests", numModelRequests), + checkRequired("numRequests", numRequests), + object_, + apiKeyId, + contextLevel, + model, + projectId, + userId, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing + * fields. + * + * @throws OpenAIInvalidDataException if any value type in this object doesn't match + * its expected type. + */ + fun validate(): OrganizationUsageWebSearchesResult = apply { + if (validated) { + return@apply + } + + numModelRequests() + numRequests() + _object_().let { + if (it != JsonValue.from("organization.usage.web_searches.result")) { + throw OpenAIInvalidDataException("'object_' is invalid, received $it") + } + } + apiKeyId() + contextLevel() + model() + projectId() + userId() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OpenAIInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (if (numModelRequests.asKnown().isPresent) 1 else 0) + + (if (numRequests.asKnown().isPresent) 1 else 0) + + object_.let { + if (it == JsonValue.from("organization.usage.web_searches.result")) 1 + else 0 + } + + (if (apiKeyId.asKnown().isPresent) 1 else 0) + + (if (contextLevel.asKnown().isPresent) 1 else 0) + + (if (model.asKnown().isPresent) 1 else 0) + + (if (projectId.asKnown().isPresent) 1 else 0) + + (if (userId.asKnown().isPresent) 1 else 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is OrganizationUsageWebSearchesResult && + numModelRequests == other.numModelRequests && + numRequests == other.numRequests && + object_ == other.object_ && + apiKeyId == other.apiKeyId && + contextLevel == other.contextLevel && + model == other.model && + projectId == other.projectId && + userId == other.userId && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + numModelRequests, + numRequests, + object_, + apiKeyId, + contextLevel, + model, + projectId, + userId, + additionalProperties, + ) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "OrganizationUsageWebSearchesResult{numModelRequests=$numModelRequests, numRequests=$numRequests, object_=$object_, apiKeyId=$apiKeyId, contextLevel=$contextLevel, model=$model, projectId=$projectId, userId=$userId, additionalProperties=$additionalProperties}" + } + + /** The aggregated costs details of the specific time bucket. */ + class OrganizationCostsResult + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val object_: JsonValue, + private val amount: JsonField, + private val apiKeyId: JsonField, + private val lineItem: JsonField, + private val projectId: JsonField, + private val quantity: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("object") @ExcludeMissing object_: JsonValue = JsonMissing.of(), + @JsonProperty("amount") + @ExcludeMissing + amount: JsonField = JsonMissing.of(), + @JsonProperty("api_key_id") + @ExcludeMissing + apiKeyId: JsonField = JsonMissing.of(), + @JsonProperty("line_item") + @ExcludeMissing + lineItem: JsonField = JsonMissing.of(), + @JsonProperty("project_id") + @ExcludeMissing + projectId: JsonField = JsonMissing.of(), + @JsonProperty("quantity") + @ExcludeMissing + quantity: JsonField = JsonMissing.of(), + ) : this(object_, amount, apiKeyId, lineItem, projectId, quantity, mutableMapOf()) + + /** + * Expected to always return the following: + * ```java + * JsonValue.from("organization.costs.result") + * ``` + * + * However, this method can be useful for debugging and logging (e.g. if the server + * responded with an unexpected value). + */ + @JsonProperty("object") @ExcludeMissing fun _object_(): JsonValue = object_ + + /** + * The monetary value in its associated currency. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun amount(): Optional = amount.getOptional("amount") + + /** + * When `group_by=api_key_id`, this field provides the API Key ID of the grouped + * costs result. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun apiKeyId(): Optional = apiKeyId.getOptional("api_key_id") + + /** + * When `group_by=line_item`, this field provides the line item of the grouped costs + * result. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun lineItem(): Optional = lineItem.getOptional("line_item") + + /** + * When `group_by=project_id`, this field provides the project ID of the grouped + * costs result. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun projectId(): Optional = projectId.getOptional("project_id") + + /** + * When `group_by=line_item`, this field provides the quantity of the grouped costs + * result. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun quantity(): Optional = quantity.getOptional("quantity") + + /** + * Returns the raw JSON value of [amount]. + * + * Unlike [amount], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("amount") @ExcludeMissing fun _amount(): JsonField = amount + + /** + * Returns the raw JSON value of [apiKeyId]. + * + * Unlike [apiKeyId], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("api_key_id") + @ExcludeMissing + fun _apiKeyId(): JsonField = apiKeyId + + /** + * Returns the raw JSON value of [lineItem]. + * + * Unlike [lineItem], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("line_item") + @ExcludeMissing + fun _lineItem(): JsonField = lineItem + + /** + * 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 [quantity]. + * + * Unlike [quantity], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("quantity") + @ExcludeMissing + fun _quantity(): JsonField = quantity + + @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 + * [OrganizationCostsResult]. + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [OrganizationCostsResult]. */ + class Builder internal constructor() { + + private var object_: JsonValue = JsonValue.from("organization.costs.result") + private var amount: JsonField = JsonMissing.of() + private var apiKeyId: JsonField = JsonMissing.of() + private var lineItem: JsonField = JsonMissing.of() + private var projectId: JsonField = JsonMissing.of() + private var quantity: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(organizationCostsResult: OrganizationCostsResult) = apply { + object_ = organizationCostsResult.object_ + amount = organizationCostsResult.amount + apiKeyId = organizationCostsResult.apiKeyId + lineItem = organizationCostsResult.lineItem + projectId = organizationCostsResult.projectId + quantity = organizationCostsResult.quantity + additionalProperties = + organizationCostsResult.additionalProperties.toMutableMap() + } + + /** + * Sets the field to an arbitrary JSON value. + * + * It is usually unnecessary to call this method because the field defaults to + * the following: + * ```java + * JsonValue.from("organization.costs.result") + * ``` + * + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun object_(object_: JsonValue) = apply { this.object_ = object_ } + + /** The monetary value in its associated currency. */ + fun amount(amount: Amount) = amount(JsonField.of(amount)) + + /** + * Sets [Builder.amount] to an arbitrary JSON value. + * + * You should usually call [Builder.amount] with a well-typed [Amount] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun amount(amount: JsonField) = apply { this.amount = amount } + + /** + * When `group_by=api_key_id`, this field provides the API Key ID of the grouped + * costs result. + */ + fun apiKeyId(apiKeyId: String?) = apiKeyId(JsonField.ofNullable(apiKeyId)) + + /** Alias for calling [Builder.apiKeyId] with `apiKeyId.orElse(null)`. */ + fun apiKeyId(apiKeyId: Optional) = apiKeyId(apiKeyId.getOrNull()) + + /** + * Sets [Builder.apiKeyId] to an arbitrary JSON value. + * + * You should usually call [Builder.apiKeyId] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun apiKeyId(apiKeyId: JsonField) = apply { this.apiKeyId = apiKeyId } + + /** + * When `group_by=line_item`, this field provides the line item of the grouped + * costs result. + */ + fun lineItem(lineItem: String?) = lineItem(JsonField.ofNullable(lineItem)) + + /** Alias for calling [Builder.lineItem] with `lineItem.orElse(null)`. */ + fun lineItem(lineItem: Optional) = lineItem(lineItem.getOrNull()) + + /** + * Sets [Builder.lineItem] to an arbitrary JSON value. + * + * You should usually call [Builder.lineItem] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun lineItem(lineItem: JsonField) = apply { this.lineItem = lineItem } + + /** + * When `group_by=project_id`, this field provides the project ID of the grouped + * costs result. + */ + fun projectId(projectId: String?) = projectId(JsonField.ofNullable(projectId)) + + /** Alias for calling [Builder.projectId] with `projectId.orElse(null)`. */ + fun projectId(projectId: Optional) = projectId(projectId.getOrNull()) + + /** + * 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 + } + + /** + * When `group_by=line_item`, this field provides the quantity of the grouped + * costs result. + */ + fun quantity(quantity: Double?) = quantity(JsonField.ofNullable(quantity)) + + /** + * Alias for [Builder.quantity]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun quantity(quantity: Double) = quantity(quantity as Double?) + + /** Alias for calling [Builder.quantity] with `quantity.orElse(null)`. */ + fun quantity(quantity: Optional) = quantity(quantity.getOrNull()) + + /** + * Sets [Builder.quantity] to an arbitrary JSON value. + * + * You should usually call [Builder.quantity] with a well-typed [Double] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun quantity(quantity: JsonField) = apply { this.quantity = quantity } + + 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 [OrganizationCostsResult]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): OrganizationCostsResult = + OrganizationCostsResult( + object_, + amount, + apiKeyId, + lineItem, + projectId, + quantity, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing + * fields. + * + * @throws OpenAIInvalidDataException if any value type in this object doesn't match + * its expected type. + */ + fun validate(): OrganizationCostsResult = apply { + if (validated) { + return@apply + } + + _object_().let { + if (it != JsonValue.from("organization.costs.result")) { + throw OpenAIInvalidDataException("'object_' is invalid, received $it") + } + } + amount().ifPresent { it.validate() } + apiKeyId() + lineItem() + projectId() + quantity() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OpenAIInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + object_.let { + if (it == JsonValue.from("organization.costs.result")) 1 else 0 + } + + (amount.asKnown().getOrNull()?.validity() ?: 0) + + (if (apiKeyId.asKnown().isPresent) 1 else 0) + + (if (lineItem.asKnown().isPresent) 1 else 0) + + (if (projectId.asKnown().isPresent) 1 else 0) + + (if (quantity.asKnown().isPresent) 1 else 0) + + /** The monetary value in its associated currency. */ + class Amount + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val currency: JsonField, + private val value: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("currency") + @ExcludeMissing + currency: JsonField = JsonMissing.of(), + @JsonProperty("value") + @ExcludeMissing + value: JsonField = JsonMissing.of(), + ) : this(currency, value, mutableMapOf()) + + /** + * Lowercase ISO-4217 currency e.g. "usd" + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun currency(): Optional = currency.getOptional("currency") + + /** + * The numeric value of the cost. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun value(): Optional = value.getOptional("value") + + /** + * Returns the raw JSON value of [currency]. + * + * Unlike [currency], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("currency") + @ExcludeMissing + fun _currency(): JsonField = currency + + /** + * 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 [Amount]. */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [Amount]. */ + class Builder internal constructor() { + + private var currency: JsonField = JsonMissing.of() + private var value: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = + mutableMapOf() + + @JvmSynthetic + internal fun from(amount: Amount) = apply { + currency = amount.currency + value = amount.value + additionalProperties = amount.additionalProperties.toMutableMap() + } + + /** Lowercase ISO-4217 currency e.g. "usd" */ + fun currency(currency: String) = currency(JsonField.of(currency)) + + /** + * Sets [Builder.currency] to an arbitrary JSON value. + * + * You should usually call [Builder.currency] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun currency(currency: JsonField) = apply { + this.currency = currency + } + + /** The numeric value of the cost. */ + fun value(value: Double) = value(JsonField.of(value)) + + /** + * Sets [Builder.value] to an arbitrary JSON value. + * + * You should usually call [Builder.value] with a well-typed [Double] 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 [Amount]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): Amount = + Amount(currency, value, additionalProperties.toMutableMap()) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected + * types recursively. + * + * This method is _not_ forwards compatible with new types from the API for + * existing fields. + * + * @throws OpenAIInvalidDataException if any value type in this object doesn't + * match its expected type. + */ + fun validate(): Amount = apply { + if (validated) { + return@apply + } + + currency() + value() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OpenAIInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (if (currency.asKnown().isPresent) 1 else 0) + + (if (value.asKnown().isPresent) 1 else 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Amount && + currency == other.currency && + value == other.value && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(currency, value, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Amount{currency=$currency, value=$value, additionalProperties=$additionalProperties}" + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is OrganizationCostsResult && + object_ == other.object_ && + amount == other.amount && + apiKeyId == other.apiKeyId && + lineItem == other.lineItem && + projectId == other.projectId && + quantity == other.quantity && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + object_, + amount, + apiKeyId, + lineItem, + projectId, + quantity, + additionalProperties, + ) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "OrganizationCostsResult{object_=$object_, amount=$amount, apiKeyId=$apiKeyId, lineItem=$lineItem, projectId=$projectId, quantity=$quantity, additionalProperties=$additionalProperties}" + } + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Data && + endTime == other.endTime && + object_ == other.object_ && + results == other.results && + startTime == other.startTime && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(endTime, object_, results, startTime, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Data{endTime=$endTime, object_=$object_, results=$results, startTime=$startTime, additionalProperties=$additionalProperties}" + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is UsageWebSearchCallsResponse && + data == other.data && + hasMore == other.hasMore && + nextPage == other.nextPage && + object_ == other.object_ && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(data, hasMore, nextPage, object_, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "UsageWebSearchCallsResponse{data=$data, hasMore=$hasMore, nextPage=$nextPage, object_=$object_, additionalProperties=$additionalProperties}" +} diff --git a/openai-java-core/src/main/kotlin/com/openai/services/async/admin/organization/ProjectServiceAsync.kt b/openai-java-core/src/main/kotlin/com/openai/services/async/admin/organization/ProjectServiceAsync.kt index baf4d6123..d8b62335d 100644 --- a/openai-java-core/src/main/kotlin/com/openai/services/async/admin/organization/ProjectServiceAsync.kt +++ b/openai-java-core/src/main/kotlin/com/openai/services/async/admin/organization/ProjectServiceAsync.kt @@ -15,6 +15,8 @@ import com.openai.models.admin.organization.projects.ProjectUpdateParams import com.openai.services.async.admin.organization.projects.ApiKeyServiceAsync import com.openai.services.async.admin.organization.projects.CertificateServiceAsync import com.openai.services.async.admin.organization.projects.GroupServiceAsync +import com.openai.services.async.admin.organization.projects.HostedToolPermissionServiceAsync +import com.openai.services.async.admin.organization.projects.ModelPermissionServiceAsync import com.openai.services.async.admin.organization.projects.RateLimitServiceAsync import com.openai.services.async.admin.organization.projects.RoleServiceAsync import com.openai.services.async.admin.organization.projects.ServiceAccountServiceAsync @@ -44,6 +46,10 @@ interface ProjectServiceAsync { fun rateLimits(): RateLimitServiceAsync + fun modelPermissions(): ModelPermissionServiceAsync + + fun hostedToolPermissions(): HostedToolPermissionServiceAsync + fun groups(): GroupServiceAsync fun roles(): RoleServiceAsync @@ -199,6 +205,10 @@ interface ProjectServiceAsync { fun rateLimits(): RateLimitServiceAsync.WithRawResponse + fun modelPermissions(): ModelPermissionServiceAsync.WithRawResponse + + fun hostedToolPermissions(): HostedToolPermissionServiceAsync.WithRawResponse + fun groups(): GroupServiceAsync.WithRawResponse fun roles(): RoleServiceAsync.WithRawResponse diff --git a/openai-java-core/src/main/kotlin/com/openai/services/async/admin/organization/ProjectServiceAsyncImpl.kt b/openai-java-core/src/main/kotlin/com/openai/services/async/admin/organization/ProjectServiceAsyncImpl.kt index 051583f63..b26eb0faa 100644 --- a/openai-java-core/src/main/kotlin/com/openai/services/async/admin/organization/ProjectServiceAsyncImpl.kt +++ b/openai-java-core/src/main/kotlin/com/openai/services/async/admin/organization/ProjectServiceAsyncImpl.kt @@ -31,6 +31,10 @@ import com.openai.services.async.admin.organization.projects.CertificateServiceA import com.openai.services.async.admin.organization.projects.CertificateServiceAsyncImpl import com.openai.services.async.admin.organization.projects.GroupServiceAsync import com.openai.services.async.admin.organization.projects.GroupServiceAsyncImpl +import com.openai.services.async.admin.organization.projects.HostedToolPermissionServiceAsync +import com.openai.services.async.admin.organization.projects.HostedToolPermissionServiceAsyncImpl +import com.openai.services.async.admin.organization.projects.ModelPermissionServiceAsync +import com.openai.services.async.admin.organization.projects.ModelPermissionServiceAsyncImpl import com.openai.services.async.admin.organization.projects.RateLimitServiceAsync import com.openai.services.async.admin.organization.projects.RateLimitServiceAsyncImpl import com.openai.services.async.admin.organization.projects.RoleServiceAsync @@ -62,6 +66,14 @@ class ProjectServiceAsyncImpl internal constructor(private val clientOptions: Cl RateLimitServiceAsyncImpl(clientOptions) } + private val modelPermissions: ModelPermissionServiceAsync by lazy { + ModelPermissionServiceAsyncImpl(clientOptions) + } + + private val hostedToolPermissions: HostedToolPermissionServiceAsync by lazy { + HostedToolPermissionServiceAsyncImpl(clientOptions) + } + private val groups: GroupServiceAsync by lazy { GroupServiceAsyncImpl(clientOptions) } private val roles: RoleServiceAsync by lazy { RoleServiceAsyncImpl(clientOptions) } @@ -83,6 +95,10 @@ class ProjectServiceAsyncImpl internal constructor(private val clientOptions: Cl override fun rateLimits(): RateLimitServiceAsync = rateLimits + override fun modelPermissions(): ModelPermissionServiceAsync = modelPermissions + + override fun hostedToolPermissions(): HostedToolPermissionServiceAsync = hostedToolPermissions + override fun groups(): GroupServiceAsync = groups override fun roles(): RoleServiceAsync = roles @@ -146,6 +162,15 @@ class ProjectServiceAsyncImpl internal constructor(private val clientOptions: Cl RateLimitServiceAsyncImpl.WithRawResponseImpl(clientOptions) } + private val modelPermissions: ModelPermissionServiceAsync.WithRawResponse by lazy { + ModelPermissionServiceAsyncImpl.WithRawResponseImpl(clientOptions) + } + + private val hostedToolPermissions: + HostedToolPermissionServiceAsync.WithRawResponse by lazy { + HostedToolPermissionServiceAsyncImpl.WithRawResponseImpl(clientOptions) + } + private val groups: GroupServiceAsync.WithRawResponse by lazy { GroupServiceAsyncImpl.WithRawResponseImpl(clientOptions) } @@ -173,6 +198,12 @@ class ProjectServiceAsyncImpl internal constructor(private val clientOptions: Cl override fun rateLimits(): RateLimitServiceAsync.WithRawResponse = rateLimits + override fun modelPermissions(): ModelPermissionServiceAsync.WithRawResponse = + modelPermissions + + override fun hostedToolPermissions(): HostedToolPermissionServiceAsync.WithRawResponse = + hostedToolPermissions + override fun groups(): GroupServiceAsync.WithRawResponse = groups override fun roles(): RoleServiceAsync.WithRawResponse = roles diff --git a/openai-java-core/src/main/kotlin/com/openai/services/async/admin/organization/UsageServiceAsync.kt b/openai-java-core/src/main/kotlin/com/openai/services/async/admin/organization/UsageServiceAsync.kt index e96454943..5ec1e60fa 100644 --- a/openai-java-core/src/main/kotlin/com/openai/services/async/admin/organization/UsageServiceAsync.kt +++ b/openai-java-core/src/main/kotlin/com/openai/services/async/admin/organization/UsageServiceAsync.kt @@ -17,12 +17,16 @@ import com.openai.models.admin.organization.usage.UsageCostsParams import com.openai.models.admin.organization.usage.UsageCostsResponse import com.openai.models.admin.organization.usage.UsageEmbeddingsParams import com.openai.models.admin.organization.usage.UsageEmbeddingsResponse +import com.openai.models.admin.organization.usage.UsageFileSearchCallsParams +import com.openai.models.admin.organization.usage.UsageFileSearchCallsResponse import com.openai.models.admin.organization.usage.UsageImagesParams import com.openai.models.admin.organization.usage.UsageImagesResponse import com.openai.models.admin.organization.usage.UsageModerationsParams import com.openai.models.admin.organization.usage.UsageModerationsResponse import com.openai.models.admin.organization.usage.UsageVectorStoresParams import com.openai.models.admin.organization.usage.UsageVectorStoresResponse +import com.openai.models.admin.organization.usage.UsageWebSearchCallsParams +import com.openai.models.admin.organization.usage.UsageWebSearchCallsResponse import java.util.concurrent.CompletableFuture import java.util.function.Consumer @@ -105,6 +109,18 @@ interface UsageServiceAsync { requestOptions: RequestOptions = RequestOptions.none(), ): CompletableFuture + /** Get file search calls usage details for the organization. */ + fun fileSearchCalls( + params: UsageFileSearchCallsParams + ): CompletableFuture = + fileSearchCalls(params, RequestOptions.none()) + + /** @see fileSearchCalls */ + fun fileSearchCalls( + params: UsageFileSearchCallsParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture + /** Get images usage details for the organization. */ fun images(params: UsageImagesParams): CompletableFuture = images(params, RequestOptions.none()) @@ -136,6 +152,18 @@ interface UsageServiceAsync { requestOptions: RequestOptions = RequestOptions.none(), ): CompletableFuture + /** Get web search calls usage details for the organization. */ + fun webSearchCalls( + params: UsageWebSearchCallsParams + ): CompletableFuture = + webSearchCalls(params, RequestOptions.none()) + + /** @see webSearchCalls */ + fun webSearchCalls( + params: UsageWebSearchCallsParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture + /** A view of [UsageServiceAsync] that provides access to raw HTTP responses for each method. */ interface WithRawResponse { @@ -238,6 +266,21 @@ interface UsageServiceAsync { requestOptions: RequestOptions = RequestOptions.none(), ): CompletableFuture> + /** + * Returns a raw HTTP response for `get /organization/usage/file_search_calls`, but is + * otherwise the same as [UsageServiceAsync.fileSearchCalls]. + */ + fun fileSearchCalls( + params: UsageFileSearchCallsParams + ): CompletableFuture> = + fileSearchCalls(params, RequestOptions.none()) + + /** @see fileSearchCalls */ + fun fileSearchCalls( + params: UsageFileSearchCallsParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture> + /** * Returns a raw HTTP response for `get /organization/usage/images`, but is otherwise the * same as [UsageServiceAsync.images]. @@ -282,5 +325,20 @@ interface UsageServiceAsync { params: UsageVectorStoresParams, requestOptions: RequestOptions = RequestOptions.none(), ): CompletableFuture> + + /** + * Returns a raw HTTP response for `get /organization/usage/web_search_calls`, but is + * otherwise the same as [UsageServiceAsync.webSearchCalls]. + */ + fun webSearchCalls( + params: UsageWebSearchCallsParams + ): CompletableFuture> = + webSearchCalls(params, RequestOptions.none()) + + /** @see webSearchCalls */ + fun webSearchCalls( + params: UsageWebSearchCallsParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture> } } diff --git a/openai-java-core/src/main/kotlin/com/openai/services/async/admin/organization/UsageServiceAsyncImpl.kt b/openai-java-core/src/main/kotlin/com/openai/services/async/admin/organization/UsageServiceAsyncImpl.kt index 46fe462b2..076e81e1a 100644 --- a/openai-java-core/src/main/kotlin/com/openai/services/async/admin/organization/UsageServiceAsyncImpl.kt +++ b/openai-java-core/src/main/kotlin/com/openai/services/async/admin/organization/UsageServiceAsyncImpl.kt @@ -27,12 +27,16 @@ import com.openai.models.admin.organization.usage.UsageCostsParams import com.openai.models.admin.organization.usage.UsageCostsResponse import com.openai.models.admin.organization.usage.UsageEmbeddingsParams import com.openai.models.admin.organization.usage.UsageEmbeddingsResponse +import com.openai.models.admin.organization.usage.UsageFileSearchCallsParams +import com.openai.models.admin.organization.usage.UsageFileSearchCallsResponse import com.openai.models.admin.organization.usage.UsageImagesParams import com.openai.models.admin.organization.usage.UsageImagesResponse import com.openai.models.admin.organization.usage.UsageModerationsParams import com.openai.models.admin.organization.usage.UsageModerationsResponse import com.openai.models.admin.organization.usage.UsageVectorStoresParams import com.openai.models.admin.organization.usage.UsageVectorStoresResponse +import com.openai.models.admin.organization.usage.UsageWebSearchCallsParams +import com.openai.models.admin.organization.usage.UsageWebSearchCallsResponse import java.util.concurrent.CompletableFuture import java.util.function.Consumer @@ -90,6 +94,13 @@ class UsageServiceAsyncImpl internal constructor(private val clientOptions: Clie // get /organization/usage/embeddings withRawResponse().embeddings(params, requestOptions).thenApply { it.parse() } + override fun fileSearchCalls( + params: UsageFileSearchCallsParams, + requestOptions: RequestOptions, + ): CompletableFuture = + // get /organization/usage/file_search_calls + withRawResponse().fileSearchCalls(params, requestOptions).thenApply { it.parse() } + override fun images( params: UsageImagesParams, requestOptions: RequestOptions, @@ -111,6 +122,13 @@ class UsageServiceAsyncImpl internal constructor(private val clientOptions: Clie // get /organization/usage/vector_stores withRawResponse().vectorStores(params, requestOptions).thenApply { it.parse() } + override fun webSearchCalls( + params: UsageWebSearchCallsParams, + requestOptions: RequestOptions, + ): CompletableFuture = + // get /organization/usage/web_search_calls + withRawResponse().webSearchCalls(params, requestOptions).thenApply { it.parse() } + class WithRawResponseImpl internal constructor(private val clientOptions: ClientOptions) : UsageServiceAsync.WithRawResponse { @@ -328,6 +346,40 @@ class UsageServiceAsyncImpl internal constructor(private val clientOptions: Clie } } + private val fileSearchCallsHandler: Handler = + jsonHandler(clientOptions.jsonMapper) + + override fun fileSearchCalls( + params: UsageFileSearchCallsParams, + requestOptions: RequestOptions, + ): CompletableFuture> { + val request = + HttpRequest.builder() + .method(HttpMethod.GET) + .baseUrl(clientOptions.baseUrl()) + .addPathSegments("organization", "usage", "file_search_calls") + .build() + .prepareAsync( + clientOptions, + params, + SecurityOptions.builder().adminApiKeyAuth(true).build(), + ) + val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) + return request + .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } + .thenApply { response -> + errorHandler.handle(response).parseable { + response + .use { fileSearchCallsHandler.handle(it) } + .also { + if (requestOptions.responseValidation!!) { + it.validate() + } + } + } + } + } + private val imagesHandler: Handler = jsonHandler(clientOptions.jsonMapper) @@ -429,5 +481,39 @@ class UsageServiceAsyncImpl internal constructor(private val clientOptions: Clie } } } + + private val webSearchCallsHandler: Handler = + jsonHandler(clientOptions.jsonMapper) + + override fun webSearchCalls( + params: UsageWebSearchCallsParams, + requestOptions: RequestOptions, + ): CompletableFuture> { + val request = + HttpRequest.builder() + .method(HttpMethod.GET) + .baseUrl(clientOptions.baseUrl()) + .addPathSegments("organization", "usage", "web_search_calls") + .build() + .prepareAsync( + clientOptions, + params, + SecurityOptions.builder().adminApiKeyAuth(true).build(), + ) + val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) + return request + .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } + .thenApply { response -> + errorHandler.handle(response).parseable { + response + .use { webSearchCallsHandler.handle(it) } + .also { + if (requestOptions.responseValidation!!) { + it.validate() + } + } + } + } + } } } diff --git a/openai-java-core/src/main/kotlin/com/openai/services/async/admin/organization/projects/HostedToolPermissionServiceAsync.kt b/openai-java-core/src/main/kotlin/com/openai/services/async/admin/organization/projects/HostedToolPermissionServiceAsync.kt new file mode 100644 index 000000000..cc79b93ab --- /dev/null +++ b/openai-java-core/src/main/kotlin/com/openai/services/async/admin/organization/projects/HostedToolPermissionServiceAsync.kt @@ -0,0 +1,205 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.services.async.admin.organization.projects + +import com.openai.core.ClientOptions +import com.openai.core.RequestOptions +import com.openai.core.http.HttpResponseFor +import com.openai.models.admin.organization.projects.hostedtoolpermissions.HostedToolPermissionRetrieveParams +import com.openai.models.admin.organization.projects.hostedtoolpermissions.HostedToolPermissionUpdateParams +import com.openai.models.admin.organization.projects.hostedtoolpermissions.ProjectHostedToolPermissions +import java.util.concurrent.CompletableFuture +import java.util.function.Consumer + +interface HostedToolPermissionServiceAsync { + + /** + * Returns a view of this service that provides access to raw HTTP responses for each method. + */ + fun withRawResponse(): WithRawResponse + + /** + * Returns a view of this service with the given option modifications applied. + * + * The original service is not modified. + */ + fun withOptions(modifier: Consumer): HostedToolPermissionServiceAsync + + /** Returns hosted tool permissions for a project. */ + fun retrieve(projectId: String): CompletableFuture = + retrieve(projectId, HostedToolPermissionRetrieveParams.none()) + + /** @see retrieve */ + fun retrieve( + projectId: String, + params: HostedToolPermissionRetrieveParams = HostedToolPermissionRetrieveParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture = + retrieve(params.toBuilder().projectId(projectId).build(), requestOptions) + + /** @see retrieve */ + fun retrieve( + projectId: String, + params: HostedToolPermissionRetrieveParams = HostedToolPermissionRetrieveParams.none(), + ): CompletableFuture = + retrieve(projectId, params, RequestOptions.none()) + + /** @see retrieve */ + fun retrieve( + params: HostedToolPermissionRetrieveParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture + + /** @see retrieve */ + fun retrieve( + params: HostedToolPermissionRetrieveParams + ): CompletableFuture = retrieve(params, RequestOptions.none()) + + /** @see retrieve */ + fun retrieve( + projectId: String, + requestOptions: RequestOptions, + ): CompletableFuture = + retrieve(projectId, HostedToolPermissionRetrieveParams.none(), requestOptions) + + /** Updates hosted tool permissions for a project. */ + fun update(projectId: String): CompletableFuture = + update(projectId, HostedToolPermissionUpdateParams.none()) + + /** @see update */ + fun update( + projectId: String, + params: HostedToolPermissionUpdateParams = HostedToolPermissionUpdateParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture = + update(params.toBuilder().projectId(projectId).build(), requestOptions) + + /** @see update */ + fun update( + projectId: String, + params: HostedToolPermissionUpdateParams = HostedToolPermissionUpdateParams.none(), + ): CompletableFuture = + update(projectId, params, RequestOptions.none()) + + /** @see update */ + fun update( + params: HostedToolPermissionUpdateParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture + + /** @see update */ + fun update( + params: HostedToolPermissionUpdateParams + ): CompletableFuture = update(params, RequestOptions.none()) + + /** @see update */ + fun update( + projectId: String, + requestOptions: RequestOptions, + ): CompletableFuture = + update(projectId, HostedToolPermissionUpdateParams.none(), requestOptions) + + /** + * A view of [HostedToolPermissionServiceAsync] that provides access to raw HTTP responses for + * each method. + */ + interface WithRawResponse { + + /** + * Returns a view of this service with the given option modifications applied. + * + * The original service is not modified. + */ + fun withOptions( + modifier: Consumer + ): HostedToolPermissionServiceAsync.WithRawResponse + + /** + * Returns a raw HTTP response for `get + * /organization/projects/{project_id}/hosted_tool_permissions`, but is otherwise the same + * as [HostedToolPermissionServiceAsync.retrieve]. + */ + fun retrieve( + projectId: String + ): CompletableFuture> = + retrieve(projectId, HostedToolPermissionRetrieveParams.none()) + + /** @see retrieve */ + fun retrieve( + projectId: String, + params: HostedToolPermissionRetrieveParams = HostedToolPermissionRetrieveParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture> = + retrieve(params.toBuilder().projectId(projectId).build(), requestOptions) + + /** @see retrieve */ + fun retrieve( + projectId: String, + params: HostedToolPermissionRetrieveParams = HostedToolPermissionRetrieveParams.none(), + ): CompletableFuture> = + retrieve(projectId, params, RequestOptions.none()) + + /** @see retrieve */ + fun retrieve( + params: HostedToolPermissionRetrieveParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture> + + /** @see retrieve */ + fun retrieve( + params: HostedToolPermissionRetrieveParams + ): CompletableFuture> = + retrieve(params, RequestOptions.none()) + + /** @see retrieve */ + fun retrieve( + projectId: String, + requestOptions: RequestOptions, + ): CompletableFuture> = + retrieve(projectId, HostedToolPermissionRetrieveParams.none(), requestOptions) + + /** + * Returns a raw HTTP response for `post + * /organization/projects/{project_id}/hosted_tool_permissions`, but is otherwise the same + * as [HostedToolPermissionServiceAsync.update]. + */ + fun update( + projectId: String + ): CompletableFuture> = + update(projectId, HostedToolPermissionUpdateParams.none()) + + /** @see update */ + fun update( + projectId: String, + params: HostedToolPermissionUpdateParams = HostedToolPermissionUpdateParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture> = + update(params.toBuilder().projectId(projectId).build(), requestOptions) + + /** @see update */ + fun update( + projectId: String, + params: HostedToolPermissionUpdateParams = HostedToolPermissionUpdateParams.none(), + ): CompletableFuture> = + update(projectId, params, RequestOptions.none()) + + /** @see update */ + fun update( + params: HostedToolPermissionUpdateParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture> + + /** @see update */ + fun update( + params: HostedToolPermissionUpdateParams + ): CompletableFuture> = + update(params, RequestOptions.none()) + + /** @see update */ + fun update( + projectId: String, + requestOptions: RequestOptions, + ): CompletableFuture> = + update(projectId, HostedToolPermissionUpdateParams.none(), requestOptions) + } +} diff --git a/openai-java-core/src/main/kotlin/com/openai/services/async/admin/organization/projects/HostedToolPermissionServiceAsyncImpl.kt b/openai-java-core/src/main/kotlin/com/openai/services/async/admin/organization/projects/HostedToolPermissionServiceAsyncImpl.kt new file mode 100644 index 000000000..b8f60b830 --- /dev/null +++ b/openai-java-core/src/main/kotlin/com/openai/services/async/admin/organization/projects/HostedToolPermissionServiceAsyncImpl.kt @@ -0,0 +1,156 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.services.async.admin.organization.projects + +import com.openai.core.ClientOptions +import com.openai.core.RequestOptions +import com.openai.core.SecurityOptions +import com.openai.core.checkRequired +import com.openai.core.handlers.errorBodyHandler +import com.openai.core.handlers.errorHandler +import com.openai.core.handlers.jsonHandler +import com.openai.core.http.HttpMethod +import com.openai.core.http.HttpRequest +import com.openai.core.http.HttpResponse +import com.openai.core.http.HttpResponse.Handler +import com.openai.core.http.HttpResponseFor +import com.openai.core.http.json +import com.openai.core.http.parseable +import com.openai.core.prepareAsync +import com.openai.models.admin.organization.projects.hostedtoolpermissions.HostedToolPermissionRetrieveParams +import com.openai.models.admin.organization.projects.hostedtoolpermissions.HostedToolPermissionUpdateParams +import com.openai.models.admin.organization.projects.hostedtoolpermissions.ProjectHostedToolPermissions +import java.util.concurrent.CompletableFuture +import java.util.function.Consumer +import kotlin.jvm.optionals.getOrNull + +class HostedToolPermissionServiceAsyncImpl +internal constructor(private val clientOptions: ClientOptions) : HostedToolPermissionServiceAsync { + + private val withRawResponse: HostedToolPermissionServiceAsync.WithRawResponse by lazy { + WithRawResponseImpl(clientOptions) + } + + override fun withRawResponse(): HostedToolPermissionServiceAsync.WithRawResponse = + withRawResponse + + override fun withOptions( + modifier: Consumer + ): HostedToolPermissionServiceAsync = + HostedToolPermissionServiceAsyncImpl( + clientOptions.toBuilder().apply(modifier::accept).build() + ) + + override fun retrieve( + params: HostedToolPermissionRetrieveParams, + requestOptions: RequestOptions, + ): CompletableFuture = + // get /organization/projects/{project_id}/hosted_tool_permissions + withRawResponse().retrieve(params, requestOptions).thenApply { it.parse() } + + override fun update( + params: HostedToolPermissionUpdateParams, + requestOptions: RequestOptions, + ): CompletableFuture = + // post /organization/projects/{project_id}/hosted_tool_permissions + withRawResponse().update(params, requestOptions).thenApply { it.parse() } + + class WithRawResponseImpl internal constructor(private val clientOptions: ClientOptions) : + HostedToolPermissionServiceAsync.WithRawResponse { + + private val errorHandler: Handler = + errorHandler(errorBodyHandler(clientOptions.jsonMapper)) + + override fun withOptions( + modifier: Consumer + ): HostedToolPermissionServiceAsync.WithRawResponse = + HostedToolPermissionServiceAsyncImpl.WithRawResponseImpl( + clientOptions.toBuilder().apply(modifier::accept).build() + ) + + private val retrieveHandler: Handler = + jsonHandler(clientOptions.jsonMapper) + + override fun retrieve( + params: HostedToolPermissionRetrieveParams, + requestOptions: RequestOptions, + ): CompletableFuture> { + // We check here instead of in the params builder because this can be specified + // positionally or in the params class. + checkRequired("projectId", params.projectId().getOrNull()) + val request = + HttpRequest.builder() + .method(HttpMethod.GET) + .baseUrl(clientOptions.baseUrl()) + .addPathSegments( + "organization", + "projects", + params._pathParam(0), + "hosted_tool_permissions", + ) + .build() + .prepareAsync( + clientOptions, + params, + SecurityOptions.builder().adminApiKeyAuth(true).build(), + ) + val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) + return request + .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } + .thenApply { response -> + errorHandler.handle(response).parseable { + response + .use { retrieveHandler.handle(it) } + .also { + if (requestOptions.responseValidation!!) { + it.validate() + } + } + } + } + } + + private val updateHandler: Handler = + jsonHandler(clientOptions.jsonMapper) + + override fun update( + params: HostedToolPermissionUpdateParams, + requestOptions: RequestOptions, + ): CompletableFuture> { + // We check here instead of in the params builder because this can be specified + // positionally or in the params class. + checkRequired("projectId", params.projectId().getOrNull()) + val request = + HttpRequest.builder() + .method(HttpMethod.POST) + .baseUrl(clientOptions.baseUrl()) + .addPathSegments( + "organization", + "projects", + params._pathParam(0), + "hosted_tool_permissions", + ) + .body(json(clientOptions.jsonMapper, params._body())) + .build() + .prepareAsync( + clientOptions, + params, + SecurityOptions.builder().adminApiKeyAuth(true).build(), + ) + val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) + return request + .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } + .thenApply { response -> + errorHandler.handle(response).parseable { + response + .use { updateHandler.handle(it) } + .also { + if (requestOptions.responseValidation!!) { + it.validate() + } + } + } + } + } + } +} diff --git a/openai-java-core/src/main/kotlin/com/openai/services/async/admin/organization/projects/ModelPermissionServiceAsync.kt b/openai-java-core/src/main/kotlin/com/openai/services/async/admin/organization/projects/ModelPermissionServiceAsync.kt new file mode 100644 index 000000000..c3f78e55a --- /dev/null +++ b/openai-java-core/src/main/kotlin/com/openai/services/async/admin/organization/projects/ModelPermissionServiceAsync.kt @@ -0,0 +1,262 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.services.async.admin.organization.projects + +import com.openai.core.ClientOptions +import com.openai.core.RequestOptions +import com.openai.core.http.HttpResponseFor +import com.openai.models.admin.organization.projects.modelpermissions.ModelPermissionDeleteParams +import com.openai.models.admin.organization.projects.modelpermissions.ModelPermissionRetrieveParams +import com.openai.models.admin.organization.projects.modelpermissions.ModelPermissionUpdateParams +import com.openai.models.admin.organization.projects.modelpermissions.ProjectModelPermissions +import com.openai.models.admin.organization.projects.modelpermissions.ProjectModelPermissionsDeleted +import java.util.concurrent.CompletableFuture +import java.util.function.Consumer + +interface ModelPermissionServiceAsync { + + /** + * Returns a view of this service that provides access to raw HTTP responses for each method. + */ + fun withRawResponse(): WithRawResponse + + /** + * Returns a view of this service with the given option modifications applied. + * + * The original service is not modified. + */ + fun withOptions(modifier: Consumer): ModelPermissionServiceAsync + + /** Returns model permissions for a project. */ + fun retrieve(projectId: String): CompletableFuture = + retrieve(projectId, ModelPermissionRetrieveParams.none()) + + /** @see retrieve */ + fun retrieve( + projectId: String, + params: ModelPermissionRetrieveParams = ModelPermissionRetrieveParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture = + retrieve(params.toBuilder().projectId(projectId).build(), requestOptions) + + /** @see retrieve */ + fun retrieve( + projectId: String, + params: ModelPermissionRetrieveParams = ModelPermissionRetrieveParams.none(), + ): CompletableFuture = + retrieve(projectId, params, RequestOptions.none()) + + /** @see retrieve */ + fun retrieve( + params: ModelPermissionRetrieveParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture + + /** @see retrieve */ + fun retrieve( + params: ModelPermissionRetrieveParams + ): CompletableFuture = retrieve(params, RequestOptions.none()) + + /** @see retrieve */ + fun retrieve( + projectId: String, + requestOptions: RequestOptions, + ): CompletableFuture = + retrieve(projectId, ModelPermissionRetrieveParams.none(), requestOptions) + + /** Updates model permissions for a project. */ + fun update( + projectId: String, + params: ModelPermissionUpdateParams, + ): CompletableFuture = update(projectId, params, RequestOptions.none()) + + /** @see update */ + fun update( + projectId: String, + params: ModelPermissionUpdateParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture = + update(params.toBuilder().projectId(projectId).build(), requestOptions) + + /** @see update */ + fun update(params: ModelPermissionUpdateParams): CompletableFuture = + update(params, RequestOptions.none()) + + /** @see update */ + fun update( + params: ModelPermissionUpdateParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture + + /** Deletes model permissions for a project. */ + fun delete(projectId: String): CompletableFuture = + delete(projectId, ModelPermissionDeleteParams.none()) + + /** @see delete */ + fun delete( + projectId: String, + params: ModelPermissionDeleteParams = ModelPermissionDeleteParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture = + delete(params.toBuilder().projectId(projectId).build(), requestOptions) + + /** @see delete */ + fun delete( + projectId: String, + params: ModelPermissionDeleteParams = ModelPermissionDeleteParams.none(), + ): CompletableFuture = + delete(projectId, params, RequestOptions.none()) + + /** @see delete */ + fun delete( + params: ModelPermissionDeleteParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture + + /** @see delete */ + fun delete( + params: ModelPermissionDeleteParams + ): CompletableFuture = delete(params, RequestOptions.none()) + + /** @see delete */ + fun delete( + projectId: String, + requestOptions: RequestOptions, + ): CompletableFuture = + delete(projectId, ModelPermissionDeleteParams.none(), requestOptions) + + /** + * A view of [ModelPermissionServiceAsync] that provides access to raw HTTP responses for each + * method. + */ + interface WithRawResponse { + + /** + * Returns a view of this service with the given option modifications applied. + * + * The original service is not modified. + */ + fun withOptions( + modifier: Consumer + ): ModelPermissionServiceAsync.WithRawResponse + + /** + * Returns a raw HTTP response for `get + * /organization/projects/{project_id}/model_permissions`, but is otherwise the same as + * [ModelPermissionServiceAsync.retrieve]. + */ + fun retrieve( + projectId: String + ): CompletableFuture> = + retrieve(projectId, ModelPermissionRetrieveParams.none()) + + /** @see retrieve */ + fun retrieve( + projectId: String, + params: ModelPermissionRetrieveParams = ModelPermissionRetrieveParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture> = + retrieve(params.toBuilder().projectId(projectId).build(), requestOptions) + + /** @see retrieve */ + fun retrieve( + projectId: String, + params: ModelPermissionRetrieveParams = ModelPermissionRetrieveParams.none(), + ): CompletableFuture> = + retrieve(projectId, params, RequestOptions.none()) + + /** @see retrieve */ + fun retrieve( + params: ModelPermissionRetrieveParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture> + + /** @see retrieve */ + fun retrieve( + params: ModelPermissionRetrieveParams + ): CompletableFuture> = + retrieve(params, RequestOptions.none()) + + /** @see retrieve */ + fun retrieve( + projectId: String, + requestOptions: RequestOptions, + ): CompletableFuture> = + retrieve(projectId, ModelPermissionRetrieveParams.none(), requestOptions) + + /** + * Returns a raw HTTP response for `post + * /organization/projects/{project_id}/model_permissions`, but is otherwise the same as + * [ModelPermissionServiceAsync.update]. + */ + fun update( + projectId: String, + params: ModelPermissionUpdateParams, + ): CompletableFuture> = + update(projectId, params, RequestOptions.none()) + + /** @see update */ + fun update( + projectId: String, + params: ModelPermissionUpdateParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture> = + update(params.toBuilder().projectId(projectId).build(), requestOptions) + + /** @see update */ + fun update( + params: ModelPermissionUpdateParams + ): CompletableFuture> = + update(params, RequestOptions.none()) + + /** @see update */ + fun update( + params: ModelPermissionUpdateParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture> + + /** + * Returns a raw HTTP response for `delete + * /organization/projects/{project_id}/model_permissions`, but is otherwise the same as + * [ModelPermissionServiceAsync.delete]. + */ + fun delete( + projectId: String + ): CompletableFuture> = + delete(projectId, ModelPermissionDeleteParams.none()) + + /** @see delete */ + fun delete( + projectId: String, + params: ModelPermissionDeleteParams = ModelPermissionDeleteParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture> = + delete(params.toBuilder().projectId(projectId).build(), requestOptions) + + /** @see delete */ + fun delete( + projectId: String, + params: ModelPermissionDeleteParams = ModelPermissionDeleteParams.none(), + ): CompletableFuture> = + delete(projectId, params, RequestOptions.none()) + + /** @see delete */ + fun delete( + params: ModelPermissionDeleteParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture> + + /** @see delete */ + fun delete( + params: ModelPermissionDeleteParams + ): CompletableFuture> = + delete(params, RequestOptions.none()) + + /** @see delete */ + fun delete( + projectId: String, + requestOptions: RequestOptions, + ): CompletableFuture> = + delete(projectId, ModelPermissionDeleteParams.none(), requestOptions) + } +} diff --git a/openai-java-core/src/main/kotlin/com/openai/services/async/admin/organization/projects/ModelPermissionServiceAsyncImpl.kt b/openai-java-core/src/main/kotlin/com/openai/services/async/admin/organization/projects/ModelPermissionServiceAsyncImpl.kt new file mode 100644 index 000000000..52427b9af --- /dev/null +++ b/openai-java-core/src/main/kotlin/com/openai/services/async/admin/organization/projects/ModelPermissionServiceAsyncImpl.kt @@ -0,0 +1,205 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.services.async.admin.organization.projects + +import com.openai.core.ClientOptions +import com.openai.core.RequestOptions +import com.openai.core.SecurityOptions +import com.openai.core.checkRequired +import com.openai.core.handlers.errorBodyHandler +import com.openai.core.handlers.errorHandler +import com.openai.core.handlers.jsonHandler +import com.openai.core.http.HttpMethod +import com.openai.core.http.HttpRequest +import com.openai.core.http.HttpResponse +import com.openai.core.http.HttpResponse.Handler +import com.openai.core.http.HttpResponseFor +import com.openai.core.http.json +import com.openai.core.http.parseable +import com.openai.core.prepareAsync +import com.openai.models.admin.organization.projects.modelpermissions.ModelPermissionDeleteParams +import com.openai.models.admin.organization.projects.modelpermissions.ModelPermissionRetrieveParams +import com.openai.models.admin.organization.projects.modelpermissions.ModelPermissionUpdateParams +import com.openai.models.admin.organization.projects.modelpermissions.ProjectModelPermissions +import com.openai.models.admin.organization.projects.modelpermissions.ProjectModelPermissionsDeleted +import java.util.concurrent.CompletableFuture +import java.util.function.Consumer +import kotlin.jvm.optionals.getOrNull + +class ModelPermissionServiceAsyncImpl +internal constructor(private val clientOptions: ClientOptions) : ModelPermissionServiceAsync { + + private val withRawResponse: ModelPermissionServiceAsync.WithRawResponse by lazy { + WithRawResponseImpl(clientOptions) + } + + override fun withRawResponse(): ModelPermissionServiceAsync.WithRawResponse = withRawResponse + + override fun withOptions( + modifier: Consumer + ): ModelPermissionServiceAsync = + ModelPermissionServiceAsyncImpl(clientOptions.toBuilder().apply(modifier::accept).build()) + + override fun retrieve( + params: ModelPermissionRetrieveParams, + requestOptions: RequestOptions, + ): CompletableFuture = + // get /organization/projects/{project_id}/model_permissions + withRawResponse().retrieve(params, requestOptions).thenApply { it.parse() } + + override fun update( + params: ModelPermissionUpdateParams, + requestOptions: RequestOptions, + ): CompletableFuture = + // post /organization/projects/{project_id}/model_permissions + withRawResponse().update(params, requestOptions).thenApply { it.parse() } + + override fun delete( + params: ModelPermissionDeleteParams, + requestOptions: RequestOptions, + ): CompletableFuture = + // delete /organization/projects/{project_id}/model_permissions + withRawResponse().delete(params, requestOptions).thenApply { it.parse() } + + class WithRawResponseImpl internal constructor(private val clientOptions: ClientOptions) : + ModelPermissionServiceAsync.WithRawResponse { + + private val errorHandler: Handler = + errorHandler(errorBodyHandler(clientOptions.jsonMapper)) + + override fun withOptions( + modifier: Consumer + ): ModelPermissionServiceAsync.WithRawResponse = + ModelPermissionServiceAsyncImpl.WithRawResponseImpl( + clientOptions.toBuilder().apply(modifier::accept).build() + ) + + private val retrieveHandler: Handler = + jsonHandler(clientOptions.jsonMapper) + + override fun retrieve( + params: ModelPermissionRetrieveParams, + requestOptions: RequestOptions, + ): CompletableFuture> { + // We check here instead of in the params builder because this can be specified + // positionally or in the params class. + checkRequired("projectId", params.projectId().getOrNull()) + val request = + HttpRequest.builder() + .method(HttpMethod.GET) + .baseUrl(clientOptions.baseUrl()) + .addPathSegments( + "organization", + "projects", + params._pathParam(0), + "model_permissions", + ) + .build() + .prepareAsync( + clientOptions, + params, + SecurityOptions.builder().adminApiKeyAuth(true).build(), + ) + val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) + return request + .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } + .thenApply { response -> + errorHandler.handle(response).parseable { + response + .use { retrieveHandler.handle(it) } + .also { + if (requestOptions.responseValidation!!) { + it.validate() + } + } + } + } + } + + private val updateHandler: Handler = + jsonHandler(clientOptions.jsonMapper) + + override fun update( + params: ModelPermissionUpdateParams, + requestOptions: RequestOptions, + ): CompletableFuture> { + // We check here instead of in the params builder because this can be specified + // positionally or in the params class. + checkRequired("projectId", params.projectId().getOrNull()) + val request = + HttpRequest.builder() + .method(HttpMethod.POST) + .baseUrl(clientOptions.baseUrl()) + .addPathSegments( + "organization", + "projects", + params._pathParam(0), + "model_permissions", + ) + .body(json(clientOptions.jsonMapper, params._body())) + .build() + .prepareAsync( + clientOptions, + params, + SecurityOptions.builder().adminApiKeyAuth(true).build(), + ) + val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) + return request + .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } + .thenApply { response -> + errorHandler.handle(response).parseable { + response + .use { updateHandler.handle(it) } + .also { + if (requestOptions.responseValidation!!) { + it.validate() + } + } + } + } + } + + private val deleteHandler: Handler = + jsonHandler(clientOptions.jsonMapper) + + override fun delete( + params: ModelPermissionDeleteParams, + requestOptions: RequestOptions, + ): CompletableFuture> { + // We check here instead of in the params builder because this can be specified + // positionally or in the params class. + checkRequired("projectId", params.projectId().getOrNull()) + val request = + HttpRequest.builder() + .method(HttpMethod.DELETE) + .baseUrl(clientOptions.baseUrl()) + .addPathSegments( + "organization", + "projects", + params._pathParam(0), + "model_permissions", + ) + .apply { params._body().ifPresent { body(json(clientOptions.jsonMapper, it)) } } + .build() + .prepareAsync( + clientOptions, + params, + SecurityOptions.builder().adminApiKeyAuth(true).build(), + ) + val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) + return request + .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } + .thenApply { response -> + errorHandler.handle(response).parseable { + response + .use { deleteHandler.handle(it) } + .also { + if (requestOptions.responseValidation!!) { + it.validate() + } + } + } + } + } + } +} diff --git a/openai-java-core/src/main/kotlin/com/openai/services/blocking/admin/organization/ProjectService.kt b/openai-java-core/src/main/kotlin/com/openai/services/blocking/admin/organization/ProjectService.kt index 2c153406e..f9b591515 100644 --- a/openai-java-core/src/main/kotlin/com/openai/services/blocking/admin/organization/ProjectService.kt +++ b/openai-java-core/src/main/kotlin/com/openai/services/blocking/admin/organization/ProjectService.kt @@ -16,6 +16,8 @@ import com.openai.models.admin.organization.projects.ProjectUpdateParams import com.openai.services.blocking.admin.organization.projects.ApiKeyService import com.openai.services.blocking.admin.organization.projects.CertificateService import com.openai.services.blocking.admin.organization.projects.GroupService +import com.openai.services.blocking.admin.organization.projects.HostedToolPermissionService +import com.openai.services.blocking.admin.organization.projects.ModelPermissionService import com.openai.services.blocking.admin.organization.projects.RateLimitService import com.openai.services.blocking.admin.organization.projects.RoleService import com.openai.services.blocking.admin.organization.projects.ServiceAccountService @@ -44,6 +46,10 @@ interface ProjectService { fun rateLimits(): RateLimitService + fun modelPermissions(): ModelPermissionService + + fun hostedToolPermissions(): HostedToolPermissionService + fun groups(): GroupService fun roles(): RoleService @@ -184,6 +190,10 @@ interface ProjectService { fun rateLimits(): RateLimitService.WithRawResponse + fun modelPermissions(): ModelPermissionService.WithRawResponse + + fun hostedToolPermissions(): HostedToolPermissionService.WithRawResponse + fun groups(): GroupService.WithRawResponse fun roles(): RoleService.WithRawResponse diff --git a/openai-java-core/src/main/kotlin/com/openai/services/blocking/admin/organization/ProjectServiceImpl.kt b/openai-java-core/src/main/kotlin/com/openai/services/blocking/admin/organization/ProjectServiceImpl.kt index 16ad1f4d3..aacb422fd 100644 --- a/openai-java-core/src/main/kotlin/com/openai/services/blocking/admin/organization/ProjectServiceImpl.kt +++ b/openai-java-core/src/main/kotlin/com/openai/services/blocking/admin/organization/ProjectServiceImpl.kt @@ -31,6 +31,10 @@ import com.openai.services.blocking.admin.organization.projects.CertificateServi import com.openai.services.blocking.admin.organization.projects.CertificateServiceImpl import com.openai.services.blocking.admin.organization.projects.GroupService import com.openai.services.blocking.admin.organization.projects.GroupServiceImpl +import com.openai.services.blocking.admin.organization.projects.HostedToolPermissionService +import com.openai.services.blocking.admin.organization.projects.HostedToolPermissionServiceImpl +import com.openai.services.blocking.admin.organization.projects.ModelPermissionService +import com.openai.services.blocking.admin.organization.projects.ModelPermissionServiceImpl import com.openai.services.blocking.admin.organization.projects.RateLimitService import com.openai.services.blocking.admin.organization.projects.RateLimitServiceImpl import com.openai.services.blocking.admin.organization.projects.RoleService @@ -59,6 +63,14 @@ class ProjectServiceImpl internal constructor(private val clientOptions: ClientO private val rateLimits: RateLimitService by lazy { RateLimitServiceImpl(clientOptions) } + private val modelPermissions: ModelPermissionService by lazy { + ModelPermissionServiceImpl(clientOptions) + } + + private val hostedToolPermissions: HostedToolPermissionService by lazy { + HostedToolPermissionServiceImpl(clientOptions) + } + private val groups: GroupService by lazy { GroupServiceImpl(clientOptions) } private val roles: RoleService by lazy { RoleServiceImpl(clientOptions) } @@ -78,6 +90,10 @@ class ProjectServiceImpl internal constructor(private val clientOptions: ClientO override fun rateLimits(): RateLimitService = rateLimits + override fun modelPermissions(): ModelPermissionService = modelPermissions + + override fun hostedToolPermissions(): HostedToolPermissionService = hostedToolPermissions + override fun groups(): GroupService = groups override fun roles(): RoleService = roles @@ -126,6 +142,14 @@ class ProjectServiceImpl internal constructor(private val clientOptions: ClientO RateLimitServiceImpl.WithRawResponseImpl(clientOptions) } + private val modelPermissions: ModelPermissionService.WithRawResponse by lazy { + ModelPermissionServiceImpl.WithRawResponseImpl(clientOptions) + } + + private val hostedToolPermissions: HostedToolPermissionService.WithRawResponse by lazy { + HostedToolPermissionServiceImpl.WithRawResponseImpl(clientOptions) + } + private val groups: GroupService.WithRawResponse by lazy { GroupServiceImpl.WithRawResponseImpl(clientOptions) } @@ -153,6 +177,11 @@ class ProjectServiceImpl internal constructor(private val clientOptions: ClientO override fun rateLimits(): RateLimitService.WithRawResponse = rateLimits + override fun modelPermissions(): ModelPermissionService.WithRawResponse = modelPermissions + + override fun hostedToolPermissions(): HostedToolPermissionService.WithRawResponse = + hostedToolPermissions + override fun groups(): GroupService.WithRawResponse = groups override fun roles(): RoleService.WithRawResponse = roles diff --git a/openai-java-core/src/main/kotlin/com/openai/services/blocking/admin/organization/UsageService.kt b/openai-java-core/src/main/kotlin/com/openai/services/blocking/admin/organization/UsageService.kt index eab8ed311..6bde4d519 100644 --- a/openai-java-core/src/main/kotlin/com/openai/services/blocking/admin/organization/UsageService.kt +++ b/openai-java-core/src/main/kotlin/com/openai/services/blocking/admin/organization/UsageService.kt @@ -18,12 +18,16 @@ import com.openai.models.admin.organization.usage.UsageCostsParams import com.openai.models.admin.organization.usage.UsageCostsResponse import com.openai.models.admin.organization.usage.UsageEmbeddingsParams import com.openai.models.admin.organization.usage.UsageEmbeddingsResponse +import com.openai.models.admin.organization.usage.UsageFileSearchCallsParams +import com.openai.models.admin.organization.usage.UsageFileSearchCallsResponse import com.openai.models.admin.organization.usage.UsageImagesParams import com.openai.models.admin.organization.usage.UsageImagesResponse import com.openai.models.admin.organization.usage.UsageModerationsParams import com.openai.models.admin.organization.usage.UsageModerationsResponse import com.openai.models.admin.organization.usage.UsageVectorStoresParams import com.openai.models.admin.organization.usage.UsageVectorStoresResponse +import com.openai.models.admin.organization.usage.UsageWebSearchCallsParams +import com.openai.models.admin.organization.usage.UsageWebSearchCallsResponse import java.util.function.Consumer interface UsageService { @@ -101,6 +105,16 @@ interface UsageService { requestOptions: RequestOptions = RequestOptions.none(), ): UsageEmbeddingsResponse + /** Get file search calls usage details for the organization. */ + fun fileSearchCalls(params: UsageFileSearchCallsParams): UsageFileSearchCallsResponse = + fileSearchCalls(params, RequestOptions.none()) + + /** @see fileSearchCalls */ + fun fileSearchCalls( + params: UsageFileSearchCallsParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): UsageFileSearchCallsResponse + /** Get images usage details for the organization. */ fun images(params: UsageImagesParams): UsageImagesResponse = images(params, RequestOptions.none()) @@ -131,6 +145,16 @@ interface UsageService { requestOptions: RequestOptions = RequestOptions.none(), ): UsageVectorStoresResponse + /** Get web search calls usage details for the organization. */ + fun webSearchCalls(params: UsageWebSearchCallsParams): UsageWebSearchCallsResponse = + webSearchCalls(params, RequestOptions.none()) + + /** @see webSearchCalls */ + fun webSearchCalls( + params: UsageWebSearchCallsParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): UsageWebSearchCallsResponse + /** A view of [UsageService] that provides access to raw HTTP responses for each method. */ interface WithRawResponse { @@ -237,6 +261,23 @@ interface UsageService { requestOptions: RequestOptions = RequestOptions.none(), ): HttpResponseFor + /** + * Returns a raw HTTP response for `get /organization/usage/file_search_calls`, but is + * otherwise the same as [UsageService.fileSearchCalls]. + */ + @MustBeClosed + fun fileSearchCalls( + params: UsageFileSearchCallsParams + ): HttpResponseFor = + fileSearchCalls(params, RequestOptions.none()) + + /** @see fileSearchCalls */ + @MustBeClosed + fun fileSearchCalls( + params: UsageFileSearchCallsParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): HttpResponseFor + /** * Returns a raw HTTP response for `get /organization/usage/images`, but is otherwise the * same as [UsageService.images]. @@ -282,5 +323,22 @@ interface UsageService { params: UsageVectorStoresParams, requestOptions: RequestOptions = RequestOptions.none(), ): HttpResponseFor + + /** + * Returns a raw HTTP response for `get /organization/usage/web_search_calls`, but is + * otherwise the same as [UsageService.webSearchCalls]. + */ + @MustBeClosed + fun webSearchCalls( + params: UsageWebSearchCallsParams + ): HttpResponseFor = + webSearchCalls(params, RequestOptions.none()) + + /** @see webSearchCalls */ + @MustBeClosed + fun webSearchCalls( + params: UsageWebSearchCallsParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): HttpResponseFor } } diff --git a/openai-java-core/src/main/kotlin/com/openai/services/blocking/admin/organization/UsageServiceImpl.kt b/openai-java-core/src/main/kotlin/com/openai/services/blocking/admin/organization/UsageServiceImpl.kt index e23075405..a3f3f8f4e 100644 --- a/openai-java-core/src/main/kotlin/com/openai/services/blocking/admin/organization/UsageServiceImpl.kt +++ b/openai-java-core/src/main/kotlin/com/openai/services/blocking/admin/organization/UsageServiceImpl.kt @@ -27,12 +27,16 @@ import com.openai.models.admin.organization.usage.UsageCostsParams import com.openai.models.admin.organization.usage.UsageCostsResponse import com.openai.models.admin.organization.usage.UsageEmbeddingsParams import com.openai.models.admin.organization.usage.UsageEmbeddingsResponse +import com.openai.models.admin.organization.usage.UsageFileSearchCallsParams +import com.openai.models.admin.organization.usage.UsageFileSearchCallsResponse import com.openai.models.admin.organization.usage.UsageImagesParams import com.openai.models.admin.organization.usage.UsageImagesResponse import com.openai.models.admin.organization.usage.UsageModerationsParams import com.openai.models.admin.organization.usage.UsageModerationsResponse import com.openai.models.admin.organization.usage.UsageVectorStoresParams import com.openai.models.admin.organization.usage.UsageVectorStoresResponse +import com.openai.models.admin.organization.usage.UsageWebSearchCallsParams +import com.openai.models.admin.organization.usage.UsageWebSearchCallsResponse import java.util.function.Consumer class UsageServiceImpl internal constructor(private val clientOptions: ClientOptions) : @@ -89,6 +93,13 @@ class UsageServiceImpl internal constructor(private val clientOptions: ClientOpt // get /organization/usage/embeddings withRawResponse().embeddings(params, requestOptions).parse() + override fun fileSearchCalls( + params: UsageFileSearchCallsParams, + requestOptions: RequestOptions, + ): UsageFileSearchCallsResponse = + // get /organization/usage/file_search_calls + withRawResponse().fileSearchCalls(params, requestOptions).parse() + override fun images( params: UsageImagesParams, requestOptions: RequestOptions, @@ -110,6 +121,13 @@ class UsageServiceImpl internal constructor(private val clientOptions: ClientOpt // get /organization/usage/vector_stores withRawResponse().vectorStores(params, requestOptions).parse() + override fun webSearchCalls( + params: UsageWebSearchCallsParams, + requestOptions: RequestOptions, + ): UsageWebSearchCallsResponse = + // get /organization/usage/web_search_calls + withRawResponse().webSearchCalls(params, requestOptions).parse() + class WithRawResponseImpl internal constructor(private val clientOptions: ClientOptions) : UsageService.WithRawResponse { @@ -309,6 +327,37 @@ class UsageServiceImpl internal constructor(private val clientOptions: ClientOpt } } + private val fileSearchCallsHandler: Handler = + jsonHandler(clientOptions.jsonMapper) + + override fun fileSearchCalls( + params: UsageFileSearchCallsParams, + requestOptions: RequestOptions, + ): HttpResponseFor { + val request = + HttpRequest.builder() + .method(HttpMethod.GET) + .baseUrl(clientOptions.baseUrl()) + .addPathSegments("organization", "usage", "file_search_calls") + .build() + .prepare( + clientOptions, + params, + SecurityOptions.builder().adminApiKeyAuth(true).build(), + ) + val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) + val response = clientOptions.httpClient.execute(request, requestOptions) + return errorHandler.handle(response).parseable { + response + .use { fileSearchCallsHandler.handle(it) } + .also { + if (requestOptions.responseValidation!!) { + it.validate() + } + } + } + } + private val imagesHandler: Handler = jsonHandler(clientOptions.jsonMapper) @@ -401,5 +450,36 @@ class UsageServiceImpl internal constructor(private val clientOptions: ClientOpt } } } + + private val webSearchCallsHandler: Handler = + jsonHandler(clientOptions.jsonMapper) + + override fun webSearchCalls( + params: UsageWebSearchCallsParams, + requestOptions: RequestOptions, + ): HttpResponseFor { + val request = + HttpRequest.builder() + .method(HttpMethod.GET) + .baseUrl(clientOptions.baseUrl()) + .addPathSegments("organization", "usage", "web_search_calls") + .build() + .prepare( + clientOptions, + params, + SecurityOptions.builder().adminApiKeyAuth(true).build(), + ) + val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) + val response = clientOptions.httpClient.execute(request, requestOptions) + return errorHandler.handle(response).parseable { + response + .use { webSearchCallsHandler.handle(it) } + .also { + if (requestOptions.responseValidation!!) { + it.validate() + } + } + } + } } } diff --git a/openai-java-core/src/main/kotlin/com/openai/services/blocking/admin/organization/projects/HostedToolPermissionService.kt b/openai-java-core/src/main/kotlin/com/openai/services/blocking/admin/organization/projects/HostedToolPermissionService.kt new file mode 100644 index 000000000..5e6db074c --- /dev/null +++ b/openai-java-core/src/main/kotlin/com/openai/services/blocking/admin/organization/projects/HostedToolPermissionService.kt @@ -0,0 +1,201 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.services.blocking.admin.organization.projects + +import com.google.errorprone.annotations.MustBeClosed +import com.openai.core.ClientOptions +import com.openai.core.RequestOptions +import com.openai.core.http.HttpResponseFor +import com.openai.models.admin.organization.projects.hostedtoolpermissions.HostedToolPermissionRetrieveParams +import com.openai.models.admin.organization.projects.hostedtoolpermissions.HostedToolPermissionUpdateParams +import com.openai.models.admin.organization.projects.hostedtoolpermissions.ProjectHostedToolPermissions +import java.util.function.Consumer + +interface HostedToolPermissionService { + + /** + * Returns a view of this service that provides access to raw HTTP responses for each method. + */ + fun withRawResponse(): WithRawResponse + + /** + * Returns a view of this service with the given option modifications applied. + * + * The original service is not modified. + */ + fun withOptions(modifier: Consumer): HostedToolPermissionService + + /** Returns hosted tool permissions for a project. */ + fun retrieve(projectId: String): ProjectHostedToolPermissions = + retrieve(projectId, HostedToolPermissionRetrieveParams.none()) + + /** @see retrieve */ + fun retrieve( + projectId: String, + params: HostedToolPermissionRetrieveParams = HostedToolPermissionRetrieveParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): ProjectHostedToolPermissions = + retrieve(params.toBuilder().projectId(projectId).build(), requestOptions) + + /** @see retrieve */ + fun retrieve( + projectId: String, + params: HostedToolPermissionRetrieveParams = HostedToolPermissionRetrieveParams.none(), + ): ProjectHostedToolPermissions = retrieve(projectId, params, RequestOptions.none()) + + /** @see retrieve */ + fun retrieve( + params: HostedToolPermissionRetrieveParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): ProjectHostedToolPermissions + + /** @see retrieve */ + fun retrieve(params: HostedToolPermissionRetrieveParams): ProjectHostedToolPermissions = + retrieve(params, RequestOptions.none()) + + /** @see retrieve */ + fun retrieve(projectId: String, requestOptions: RequestOptions): ProjectHostedToolPermissions = + retrieve(projectId, HostedToolPermissionRetrieveParams.none(), requestOptions) + + /** Updates hosted tool permissions for a project. */ + fun update(projectId: String): ProjectHostedToolPermissions = + update(projectId, HostedToolPermissionUpdateParams.none()) + + /** @see update */ + fun update( + projectId: String, + params: HostedToolPermissionUpdateParams = HostedToolPermissionUpdateParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): ProjectHostedToolPermissions = + update(params.toBuilder().projectId(projectId).build(), requestOptions) + + /** @see update */ + fun update( + projectId: String, + params: HostedToolPermissionUpdateParams = HostedToolPermissionUpdateParams.none(), + ): ProjectHostedToolPermissions = update(projectId, params, RequestOptions.none()) + + /** @see update */ + fun update( + params: HostedToolPermissionUpdateParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): ProjectHostedToolPermissions + + /** @see update */ + fun update(params: HostedToolPermissionUpdateParams): ProjectHostedToolPermissions = + update(params, RequestOptions.none()) + + /** @see update */ + fun update(projectId: String, requestOptions: RequestOptions): ProjectHostedToolPermissions = + update(projectId, HostedToolPermissionUpdateParams.none(), requestOptions) + + /** + * A view of [HostedToolPermissionService] that provides access to raw HTTP responses for each + * method. + */ + interface WithRawResponse { + + /** + * Returns a view of this service with the given option modifications applied. + * + * The original service is not modified. + */ + fun withOptions( + modifier: Consumer + ): HostedToolPermissionService.WithRawResponse + + /** + * Returns a raw HTTP response for `get + * /organization/projects/{project_id}/hosted_tool_permissions`, but is otherwise the same + * as [HostedToolPermissionService.retrieve]. + */ + @MustBeClosed + fun retrieve(projectId: String): HttpResponseFor = + retrieve(projectId, HostedToolPermissionRetrieveParams.none()) + + /** @see retrieve */ + @MustBeClosed + fun retrieve( + projectId: String, + params: HostedToolPermissionRetrieveParams = HostedToolPermissionRetrieveParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): HttpResponseFor = + retrieve(params.toBuilder().projectId(projectId).build(), requestOptions) + + /** @see retrieve */ + @MustBeClosed + fun retrieve( + projectId: String, + params: HostedToolPermissionRetrieveParams = HostedToolPermissionRetrieveParams.none(), + ): HttpResponseFor = + retrieve(projectId, params, RequestOptions.none()) + + /** @see retrieve */ + @MustBeClosed + fun retrieve( + params: HostedToolPermissionRetrieveParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): HttpResponseFor + + /** @see retrieve */ + @MustBeClosed + fun retrieve( + params: HostedToolPermissionRetrieveParams + ): HttpResponseFor = retrieve(params, RequestOptions.none()) + + /** @see retrieve */ + @MustBeClosed + fun retrieve( + projectId: String, + requestOptions: RequestOptions, + ): HttpResponseFor = + retrieve(projectId, HostedToolPermissionRetrieveParams.none(), requestOptions) + + /** + * Returns a raw HTTP response for `post + * /organization/projects/{project_id}/hosted_tool_permissions`, but is otherwise the same + * as [HostedToolPermissionService.update]. + */ + @MustBeClosed + fun update(projectId: String): HttpResponseFor = + update(projectId, HostedToolPermissionUpdateParams.none()) + + /** @see update */ + @MustBeClosed + fun update( + projectId: String, + params: HostedToolPermissionUpdateParams = HostedToolPermissionUpdateParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): HttpResponseFor = + update(params.toBuilder().projectId(projectId).build(), requestOptions) + + /** @see update */ + @MustBeClosed + fun update( + projectId: String, + params: HostedToolPermissionUpdateParams = HostedToolPermissionUpdateParams.none(), + ): HttpResponseFor = + update(projectId, params, RequestOptions.none()) + + /** @see update */ + @MustBeClosed + fun update( + params: HostedToolPermissionUpdateParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): HttpResponseFor + + /** @see update */ + @MustBeClosed + fun update( + params: HostedToolPermissionUpdateParams + ): HttpResponseFor = update(params, RequestOptions.none()) + + /** @see update */ + @MustBeClosed + fun update( + projectId: String, + requestOptions: RequestOptions, + ): HttpResponseFor = + update(projectId, HostedToolPermissionUpdateParams.none(), requestOptions) + } +} diff --git a/openai-java-core/src/main/kotlin/com/openai/services/blocking/admin/organization/projects/HostedToolPermissionServiceImpl.kt b/openai-java-core/src/main/kotlin/com/openai/services/blocking/admin/organization/projects/HostedToolPermissionServiceImpl.kt new file mode 100644 index 000000000..95408d56f --- /dev/null +++ b/openai-java-core/src/main/kotlin/com/openai/services/blocking/admin/organization/projects/HostedToolPermissionServiceImpl.kt @@ -0,0 +1,146 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.services.blocking.admin.organization.projects + +import com.openai.core.ClientOptions +import com.openai.core.RequestOptions +import com.openai.core.SecurityOptions +import com.openai.core.checkRequired +import com.openai.core.handlers.errorBodyHandler +import com.openai.core.handlers.errorHandler +import com.openai.core.handlers.jsonHandler +import com.openai.core.http.HttpMethod +import com.openai.core.http.HttpRequest +import com.openai.core.http.HttpResponse +import com.openai.core.http.HttpResponse.Handler +import com.openai.core.http.HttpResponseFor +import com.openai.core.http.json +import com.openai.core.http.parseable +import com.openai.core.prepare +import com.openai.models.admin.organization.projects.hostedtoolpermissions.HostedToolPermissionRetrieveParams +import com.openai.models.admin.organization.projects.hostedtoolpermissions.HostedToolPermissionUpdateParams +import com.openai.models.admin.organization.projects.hostedtoolpermissions.ProjectHostedToolPermissions +import java.util.function.Consumer +import kotlin.jvm.optionals.getOrNull + +class HostedToolPermissionServiceImpl +internal constructor(private val clientOptions: ClientOptions) : HostedToolPermissionService { + + private val withRawResponse: HostedToolPermissionService.WithRawResponse by lazy { + WithRawResponseImpl(clientOptions) + } + + override fun withRawResponse(): HostedToolPermissionService.WithRawResponse = withRawResponse + + override fun withOptions( + modifier: Consumer + ): HostedToolPermissionService = + HostedToolPermissionServiceImpl(clientOptions.toBuilder().apply(modifier::accept).build()) + + override fun retrieve( + params: HostedToolPermissionRetrieveParams, + requestOptions: RequestOptions, + ): ProjectHostedToolPermissions = + // get /organization/projects/{project_id}/hosted_tool_permissions + withRawResponse().retrieve(params, requestOptions).parse() + + override fun update( + params: HostedToolPermissionUpdateParams, + requestOptions: RequestOptions, + ): ProjectHostedToolPermissions = + // post /organization/projects/{project_id}/hosted_tool_permissions + withRawResponse().update(params, requestOptions).parse() + + class WithRawResponseImpl internal constructor(private val clientOptions: ClientOptions) : + HostedToolPermissionService.WithRawResponse { + + private val errorHandler: Handler = + errorHandler(errorBodyHandler(clientOptions.jsonMapper)) + + override fun withOptions( + modifier: Consumer + ): HostedToolPermissionService.WithRawResponse = + HostedToolPermissionServiceImpl.WithRawResponseImpl( + clientOptions.toBuilder().apply(modifier::accept).build() + ) + + private val retrieveHandler: Handler = + jsonHandler(clientOptions.jsonMapper) + + override fun retrieve( + params: HostedToolPermissionRetrieveParams, + requestOptions: RequestOptions, + ): HttpResponseFor { + // We check here instead of in the params builder because this can be specified + // positionally or in the params class. + checkRequired("projectId", params.projectId().getOrNull()) + val request = + HttpRequest.builder() + .method(HttpMethod.GET) + .baseUrl(clientOptions.baseUrl()) + .addPathSegments( + "organization", + "projects", + params._pathParam(0), + "hosted_tool_permissions", + ) + .build() + .prepare( + clientOptions, + params, + SecurityOptions.builder().adminApiKeyAuth(true).build(), + ) + val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) + val response = clientOptions.httpClient.execute(request, requestOptions) + return errorHandler.handle(response).parseable { + response + .use { retrieveHandler.handle(it) } + .also { + if (requestOptions.responseValidation!!) { + it.validate() + } + } + } + } + + private val updateHandler: Handler = + jsonHandler(clientOptions.jsonMapper) + + override fun update( + params: HostedToolPermissionUpdateParams, + requestOptions: RequestOptions, + ): HttpResponseFor { + // We check here instead of in the params builder because this can be specified + // positionally or in the params class. + checkRequired("projectId", params.projectId().getOrNull()) + val request = + HttpRequest.builder() + .method(HttpMethod.POST) + .baseUrl(clientOptions.baseUrl()) + .addPathSegments( + "organization", + "projects", + params._pathParam(0), + "hosted_tool_permissions", + ) + .body(json(clientOptions.jsonMapper, params._body())) + .build() + .prepare( + clientOptions, + params, + SecurityOptions.builder().adminApiKeyAuth(true).build(), + ) + val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) + val response = clientOptions.httpClient.execute(request, requestOptions) + return errorHandler.handle(response).parseable { + response + .use { updateHandler.handle(it) } + .also { + if (requestOptions.responseValidation!!) { + it.validate() + } + } + } + } + } +} diff --git a/openai-java-core/src/main/kotlin/com/openai/services/blocking/admin/organization/projects/ModelPermissionService.kt b/openai-java-core/src/main/kotlin/com/openai/services/blocking/admin/organization/projects/ModelPermissionService.kt new file mode 100644 index 000000000..1284d7093 --- /dev/null +++ b/openai-java-core/src/main/kotlin/com/openai/services/blocking/admin/organization/projects/ModelPermissionService.kt @@ -0,0 +1,258 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.services.blocking.admin.organization.projects + +import com.google.errorprone.annotations.MustBeClosed +import com.openai.core.ClientOptions +import com.openai.core.RequestOptions +import com.openai.core.http.HttpResponseFor +import com.openai.models.admin.organization.projects.modelpermissions.ModelPermissionDeleteParams +import com.openai.models.admin.organization.projects.modelpermissions.ModelPermissionRetrieveParams +import com.openai.models.admin.organization.projects.modelpermissions.ModelPermissionUpdateParams +import com.openai.models.admin.organization.projects.modelpermissions.ProjectModelPermissions +import com.openai.models.admin.organization.projects.modelpermissions.ProjectModelPermissionsDeleted +import java.util.function.Consumer + +interface ModelPermissionService { + + /** + * Returns a view of this service that provides access to raw HTTP responses for each method. + */ + fun withRawResponse(): WithRawResponse + + /** + * Returns a view of this service with the given option modifications applied. + * + * The original service is not modified. + */ + fun withOptions(modifier: Consumer): ModelPermissionService + + /** Returns model permissions for a project. */ + fun retrieve(projectId: String): ProjectModelPermissions = + retrieve(projectId, ModelPermissionRetrieveParams.none()) + + /** @see retrieve */ + fun retrieve( + projectId: String, + params: ModelPermissionRetrieveParams = ModelPermissionRetrieveParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): ProjectModelPermissions = + retrieve(params.toBuilder().projectId(projectId).build(), requestOptions) + + /** @see retrieve */ + fun retrieve( + projectId: String, + params: ModelPermissionRetrieveParams = ModelPermissionRetrieveParams.none(), + ): ProjectModelPermissions = retrieve(projectId, params, RequestOptions.none()) + + /** @see retrieve */ + fun retrieve( + params: ModelPermissionRetrieveParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): ProjectModelPermissions + + /** @see retrieve */ + fun retrieve(params: ModelPermissionRetrieveParams): ProjectModelPermissions = + retrieve(params, RequestOptions.none()) + + /** @see retrieve */ + fun retrieve(projectId: String, requestOptions: RequestOptions): ProjectModelPermissions = + retrieve(projectId, ModelPermissionRetrieveParams.none(), requestOptions) + + /** Updates model permissions for a project. */ + fun update(projectId: String, params: ModelPermissionUpdateParams): ProjectModelPermissions = + update(projectId, params, RequestOptions.none()) + + /** @see update */ + fun update( + projectId: String, + params: ModelPermissionUpdateParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): ProjectModelPermissions = + update(params.toBuilder().projectId(projectId).build(), requestOptions) + + /** @see update */ + fun update(params: ModelPermissionUpdateParams): ProjectModelPermissions = + update(params, RequestOptions.none()) + + /** @see update */ + fun update( + params: ModelPermissionUpdateParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): ProjectModelPermissions + + /** Deletes model permissions for a project. */ + fun delete(projectId: String): ProjectModelPermissionsDeleted = + delete(projectId, ModelPermissionDeleteParams.none()) + + /** @see delete */ + fun delete( + projectId: String, + params: ModelPermissionDeleteParams = ModelPermissionDeleteParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): ProjectModelPermissionsDeleted = + delete(params.toBuilder().projectId(projectId).build(), requestOptions) + + /** @see delete */ + fun delete( + projectId: String, + params: ModelPermissionDeleteParams = ModelPermissionDeleteParams.none(), + ): ProjectModelPermissionsDeleted = delete(projectId, params, RequestOptions.none()) + + /** @see delete */ + fun delete( + params: ModelPermissionDeleteParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): ProjectModelPermissionsDeleted + + /** @see delete */ + fun delete(params: ModelPermissionDeleteParams): ProjectModelPermissionsDeleted = + delete(params, RequestOptions.none()) + + /** @see delete */ + fun delete(projectId: String, requestOptions: RequestOptions): ProjectModelPermissionsDeleted = + delete(projectId, ModelPermissionDeleteParams.none(), requestOptions) + + /** + * A view of [ModelPermissionService] that provides access to raw HTTP responses for each + * method. + */ + interface WithRawResponse { + + /** + * Returns a view of this service with the given option modifications applied. + * + * The original service is not modified. + */ + fun withOptions( + modifier: Consumer + ): ModelPermissionService.WithRawResponse + + /** + * Returns a raw HTTP response for `get + * /organization/projects/{project_id}/model_permissions`, but is otherwise the same as + * [ModelPermissionService.retrieve]. + */ + @MustBeClosed + fun retrieve(projectId: String): HttpResponseFor = + retrieve(projectId, ModelPermissionRetrieveParams.none()) + + /** @see retrieve */ + @MustBeClosed + fun retrieve( + projectId: String, + params: ModelPermissionRetrieveParams = ModelPermissionRetrieveParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): HttpResponseFor = + retrieve(params.toBuilder().projectId(projectId).build(), requestOptions) + + /** @see retrieve */ + @MustBeClosed + fun retrieve( + projectId: String, + params: ModelPermissionRetrieveParams = ModelPermissionRetrieveParams.none(), + ): HttpResponseFor = + retrieve(projectId, params, RequestOptions.none()) + + /** @see retrieve */ + @MustBeClosed + fun retrieve( + params: ModelPermissionRetrieveParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): HttpResponseFor + + /** @see retrieve */ + @MustBeClosed + fun retrieve( + params: ModelPermissionRetrieveParams + ): HttpResponseFor = retrieve(params, RequestOptions.none()) + + /** @see retrieve */ + @MustBeClosed + fun retrieve( + projectId: String, + requestOptions: RequestOptions, + ): HttpResponseFor = + retrieve(projectId, ModelPermissionRetrieveParams.none(), requestOptions) + + /** + * Returns a raw HTTP response for `post + * /organization/projects/{project_id}/model_permissions`, but is otherwise the same as + * [ModelPermissionService.update]. + */ + @MustBeClosed + fun update( + projectId: String, + params: ModelPermissionUpdateParams, + ): HttpResponseFor = + update(projectId, params, RequestOptions.none()) + + /** @see update */ + @MustBeClosed + fun update( + projectId: String, + params: ModelPermissionUpdateParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): HttpResponseFor = + update(params.toBuilder().projectId(projectId).build(), requestOptions) + + /** @see update */ + @MustBeClosed + fun update(params: ModelPermissionUpdateParams): HttpResponseFor = + update(params, RequestOptions.none()) + + /** @see update */ + @MustBeClosed + fun update( + params: ModelPermissionUpdateParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): HttpResponseFor + + /** + * Returns a raw HTTP response for `delete + * /organization/projects/{project_id}/model_permissions`, but is otherwise the same as + * [ModelPermissionService.delete]. + */ + @MustBeClosed + fun delete(projectId: String): HttpResponseFor = + delete(projectId, ModelPermissionDeleteParams.none()) + + /** @see delete */ + @MustBeClosed + fun delete( + projectId: String, + params: ModelPermissionDeleteParams = ModelPermissionDeleteParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): HttpResponseFor = + delete(params.toBuilder().projectId(projectId).build(), requestOptions) + + /** @see delete */ + @MustBeClosed + fun delete( + projectId: String, + params: ModelPermissionDeleteParams = ModelPermissionDeleteParams.none(), + ): HttpResponseFor = + delete(projectId, params, RequestOptions.none()) + + /** @see delete */ + @MustBeClosed + fun delete( + params: ModelPermissionDeleteParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): HttpResponseFor + + /** @see delete */ + @MustBeClosed + fun delete( + params: ModelPermissionDeleteParams + ): HttpResponseFor = delete(params, RequestOptions.none()) + + /** @see delete */ + @MustBeClosed + fun delete( + projectId: String, + requestOptions: RequestOptions, + ): HttpResponseFor = + delete(projectId, ModelPermissionDeleteParams.none(), requestOptions) + } +} diff --git a/openai-java-core/src/main/kotlin/com/openai/services/blocking/admin/organization/projects/ModelPermissionServiceImpl.kt b/openai-java-core/src/main/kotlin/com/openai/services/blocking/admin/organization/projects/ModelPermissionServiceImpl.kt new file mode 100644 index 000000000..d4708751a --- /dev/null +++ b/openai-java-core/src/main/kotlin/com/openai/services/blocking/admin/organization/projects/ModelPermissionServiceImpl.kt @@ -0,0 +1,193 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.services.blocking.admin.organization.projects + +import com.openai.core.ClientOptions +import com.openai.core.RequestOptions +import com.openai.core.SecurityOptions +import com.openai.core.checkRequired +import com.openai.core.handlers.errorBodyHandler +import com.openai.core.handlers.errorHandler +import com.openai.core.handlers.jsonHandler +import com.openai.core.http.HttpMethod +import com.openai.core.http.HttpRequest +import com.openai.core.http.HttpResponse +import com.openai.core.http.HttpResponse.Handler +import com.openai.core.http.HttpResponseFor +import com.openai.core.http.json +import com.openai.core.http.parseable +import com.openai.core.prepare +import com.openai.models.admin.organization.projects.modelpermissions.ModelPermissionDeleteParams +import com.openai.models.admin.organization.projects.modelpermissions.ModelPermissionRetrieveParams +import com.openai.models.admin.organization.projects.modelpermissions.ModelPermissionUpdateParams +import com.openai.models.admin.organization.projects.modelpermissions.ProjectModelPermissions +import com.openai.models.admin.organization.projects.modelpermissions.ProjectModelPermissionsDeleted +import java.util.function.Consumer +import kotlin.jvm.optionals.getOrNull + +class ModelPermissionServiceImpl internal constructor(private val clientOptions: ClientOptions) : + ModelPermissionService { + + private val withRawResponse: ModelPermissionService.WithRawResponse by lazy { + WithRawResponseImpl(clientOptions) + } + + override fun withRawResponse(): ModelPermissionService.WithRawResponse = withRawResponse + + override fun withOptions(modifier: Consumer): ModelPermissionService = + ModelPermissionServiceImpl(clientOptions.toBuilder().apply(modifier::accept).build()) + + override fun retrieve( + params: ModelPermissionRetrieveParams, + requestOptions: RequestOptions, + ): ProjectModelPermissions = + // get /organization/projects/{project_id}/model_permissions + withRawResponse().retrieve(params, requestOptions).parse() + + override fun update( + params: ModelPermissionUpdateParams, + requestOptions: RequestOptions, + ): ProjectModelPermissions = + // post /organization/projects/{project_id}/model_permissions + withRawResponse().update(params, requestOptions).parse() + + override fun delete( + params: ModelPermissionDeleteParams, + requestOptions: RequestOptions, + ): ProjectModelPermissionsDeleted = + // delete /organization/projects/{project_id}/model_permissions + withRawResponse().delete(params, requestOptions).parse() + + class WithRawResponseImpl internal constructor(private val clientOptions: ClientOptions) : + ModelPermissionService.WithRawResponse { + + private val errorHandler: Handler = + errorHandler(errorBodyHandler(clientOptions.jsonMapper)) + + override fun withOptions( + modifier: Consumer + ): ModelPermissionService.WithRawResponse = + ModelPermissionServiceImpl.WithRawResponseImpl( + clientOptions.toBuilder().apply(modifier::accept).build() + ) + + private val retrieveHandler: Handler = + jsonHandler(clientOptions.jsonMapper) + + override fun retrieve( + params: ModelPermissionRetrieveParams, + requestOptions: RequestOptions, + ): HttpResponseFor { + // We check here instead of in the params builder because this can be specified + // positionally or in the params class. + checkRequired("projectId", params.projectId().getOrNull()) + val request = + HttpRequest.builder() + .method(HttpMethod.GET) + .baseUrl(clientOptions.baseUrl()) + .addPathSegments( + "organization", + "projects", + params._pathParam(0), + "model_permissions", + ) + .build() + .prepare( + clientOptions, + params, + SecurityOptions.builder().adminApiKeyAuth(true).build(), + ) + val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) + val response = clientOptions.httpClient.execute(request, requestOptions) + return errorHandler.handle(response).parseable { + response + .use { retrieveHandler.handle(it) } + .also { + if (requestOptions.responseValidation!!) { + it.validate() + } + } + } + } + + private val updateHandler: Handler = + jsonHandler(clientOptions.jsonMapper) + + override fun update( + params: ModelPermissionUpdateParams, + requestOptions: RequestOptions, + ): HttpResponseFor { + // We check here instead of in the params builder because this can be specified + // positionally or in the params class. + checkRequired("projectId", params.projectId().getOrNull()) + val request = + HttpRequest.builder() + .method(HttpMethod.POST) + .baseUrl(clientOptions.baseUrl()) + .addPathSegments( + "organization", + "projects", + params._pathParam(0), + "model_permissions", + ) + .body(json(clientOptions.jsonMapper, params._body())) + .build() + .prepare( + clientOptions, + params, + SecurityOptions.builder().adminApiKeyAuth(true).build(), + ) + val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) + val response = clientOptions.httpClient.execute(request, requestOptions) + return errorHandler.handle(response).parseable { + response + .use { updateHandler.handle(it) } + .also { + if (requestOptions.responseValidation!!) { + it.validate() + } + } + } + } + + private val deleteHandler: Handler = + jsonHandler(clientOptions.jsonMapper) + + override fun delete( + params: ModelPermissionDeleteParams, + requestOptions: RequestOptions, + ): HttpResponseFor { + // We check here instead of in the params builder because this can be specified + // positionally or in the params class. + checkRequired("projectId", params.projectId().getOrNull()) + val request = + HttpRequest.builder() + .method(HttpMethod.DELETE) + .baseUrl(clientOptions.baseUrl()) + .addPathSegments( + "organization", + "projects", + params._pathParam(0), + "model_permissions", + ) + .apply { params._body().ifPresent { body(json(clientOptions.jsonMapper, it)) } } + .build() + .prepare( + clientOptions, + params, + SecurityOptions.builder().adminApiKeyAuth(true).build(), + ) + val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) + val response = clientOptions.httpClient.execute(request, requestOptions) + return errorHandler.handle(response).parseable { + response + .use { deleteHandler.handle(it) } + .also { + if (requestOptions.responseValidation!!) { + it.validate() + } + } + } + } + } +} diff --git a/openai-java-core/src/test/kotlin/com/openai/models/admin/organization/projects/hostedtoolpermissions/HostedToolPermissionRetrieveParamsTest.kt b/openai-java-core/src/test/kotlin/com/openai/models/admin/organization/projects/hostedtoolpermissions/HostedToolPermissionRetrieveParamsTest.kt new file mode 100644 index 000000000..44ea903cd --- /dev/null +++ b/openai-java-core/src/test/kotlin/com/openai/models/admin/organization/projects/hostedtoolpermissions/HostedToolPermissionRetrieveParamsTest.kt @@ -0,0 +1,23 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.models.admin.organization.projects.hostedtoolpermissions + +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test + +internal class HostedToolPermissionRetrieveParamsTest { + + @Test + fun create() { + HostedToolPermissionRetrieveParams.builder().projectId("project_id").build() + } + + @Test + fun pathParams() { + val params = HostedToolPermissionRetrieveParams.builder().projectId("project_id").build() + + assertThat(params._pathParam(0)).isEqualTo("project_id") + // out-of-bound path param + assertThat(params._pathParam(1)).isEqualTo("") + } +} diff --git a/openai-java-core/src/test/kotlin/com/openai/models/admin/organization/projects/hostedtoolpermissions/HostedToolPermissionUpdateParamsTest.kt b/openai-java-core/src/test/kotlin/com/openai/models/admin/organization/projects/hostedtoolpermissions/HostedToolPermissionUpdateParamsTest.kt new file mode 100644 index 000000000..68b376399 --- /dev/null +++ b/openai-java-core/src/test/kotlin/com/openai/models/admin/organization/projects/hostedtoolpermissions/HostedToolPermissionUpdateParamsTest.kt @@ -0,0 +1,79 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.models.admin.organization.projects.hostedtoolpermissions + +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test + +internal class HostedToolPermissionUpdateParamsTest { + + @Test + fun create() { + HostedToolPermissionUpdateParams.builder() + .projectId("project_id") + .codeInterpreter( + HostedToolPermissionUpdateParams.CodeInterpreter.builder().enabled(true).build() + ) + .fileSearch(HostedToolPermissionUpdateParams.FileSearch.builder().enabled(true).build()) + .imageGeneration( + HostedToolPermissionUpdateParams.ImageGeneration.builder().enabled(true).build() + ) + .mcp(HostedToolPermissionUpdateParams.Mcp.builder().enabled(true).build()) + .webSearch(HostedToolPermissionUpdateParams.WebSearch.builder().enabled(true).build()) + .build() + } + + @Test + fun pathParams() { + val params = HostedToolPermissionUpdateParams.builder().projectId("project_id").build() + + assertThat(params._pathParam(0)).isEqualTo("project_id") + // out-of-bound path param + assertThat(params._pathParam(1)).isEqualTo("") + } + + @Test + fun body() { + val params = + HostedToolPermissionUpdateParams.builder() + .projectId("project_id") + .codeInterpreter( + HostedToolPermissionUpdateParams.CodeInterpreter.builder().enabled(true).build() + ) + .fileSearch( + HostedToolPermissionUpdateParams.FileSearch.builder().enabled(true).build() + ) + .imageGeneration( + HostedToolPermissionUpdateParams.ImageGeneration.builder().enabled(true).build() + ) + .mcp(HostedToolPermissionUpdateParams.Mcp.builder().enabled(true).build()) + .webSearch( + HostedToolPermissionUpdateParams.WebSearch.builder().enabled(true).build() + ) + .build() + + val body = params._body() + + assertThat(body.codeInterpreter()) + .contains( + HostedToolPermissionUpdateParams.CodeInterpreter.builder().enabled(true).build() + ) + assertThat(body.fileSearch()) + .contains(HostedToolPermissionUpdateParams.FileSearch.builder().enabled(true).build()) + assertThat(body.imageGeneration()) + .contains( + HostedToolPermissionUpdateParams.ImageGeneration.builder().enabled(true).build() + ) + assertThat(body.mcp()) + .contains(HostedToolPermissionUpdateParams.Mcp.builder().enabled(true).build()) + assertThat(body.webSearch()) + .contains(HostedToolPermissionUpdateParams.WebSearch.builder().enabled(true).build()) + } + + @Test + fun bodyWithoutOptionalFields() { + val params = HostedToolPermissionUpdateParams.builder().projectId("project_id").build() + + val body = params._body() + } +} diff --git a/openai-java-core/src/test/kotlin/com/openai/models/admin/organization/projects/hostedtoolpermissions/ProjectHostedToolPermissionsTest.kt b/openai-java-core/src/test/kotlin/com/openai/models/admin/organization/projects/hostedtoolpermissions/ProjectHostedToolPermissionsTest.kt new file mode 100644 index 000000000..8ad603e99 --- /dev/null +++ b/openai-java-core/src/test/kotlin/com/openai/models/admin/organization/projects/hostedtoolpermissions/ProjectHostedToolPermissionsTest.kt @@ -0,0 +1,63 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.models.admin.organization.projects.hostedtoolpermissions + +import com.fasterxml.jackson.module.kotlin.jacksonTypeRef +import com.openai.core.jsonMapper +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test + +internal class ProjectHostedToolPermissionsTest { + + @Test + fun create() { + val projectHostedToolPermissions = + ProjectHostedToolPermissions.builder() + .codeInterpreter( + ProjectHostedToolPermissions.CodeInterpreter.builder().enabled(true).build() + ) + .fileSearch(ProjectHostedToolPermissions.FileSearch.builder().enabled(true).build()) + .imageGeneration( + ProjectHostedToolPermissions.ImageGeneration.builder().enabled(true).build() + ) + .mcp(ProjectHostedToolPermissions.Mcp.builder().enabled(true).build()) + .webSearch(ProjectHostedToolPermissions.WebSearch.builder().enabled(true).build()) + .build() + + assertThat(projectHostedToolPermissions.codeInterpreter()) + .isEqualTo(ProjectHostedToolPermissions.CodeInterpreter.builder().enabled(true).build()) + assertThat(projectHostedToolPermissions.fileSearch()) + .isEqualTo(ProjectHostedToolPermissions.FileSearch.builder().enabled(true).build()) + assertThat(projectHostedToolPermissions.imageGeneration()) + .isEqualTo(ProjectHostedToolPermissions.ImageGeneration.builder().enabled(true).build()) + assertThat(projectHostedToolPermissions.mcp()) + .isEqualTo(ProjectHostedToolPermissions.Mcp.builder().enabled(true).build()) + assertThat(projectHostedToolPermissions.webSearch()) + .isEqualTo(ProjectHostedToolPermissions.WebSearch.builder().enabled(true).build()) + } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val projectHostedToolPermissions = + ProjectHostedToolPermissions.builder() + .codeInterpreter( + ProjectHostedToolPermissions.CodeInterpreter.builder().enabled(true).build() + ) + .fileSearch(ProjectHostedToolPermissions.FileSearch.builder().enabled(true).build()) + .imageGeneration( + ProjectHostedToolPermissions.ImageGeneration.builder().enabled(true).build() + ) + .mcp(ProjectHostedToolPermissions.Mcp.builder().enabled(true).build()) + .webSearch(ProjectHostedToolPermissions.WebSearch.builder().enabled(true).build()) + .build() + + val roundtrippedProjectHostedToolPermissions = + jsonMapper.readValue( + jsonMapper.writeValueAsString(projectHostedToolPermissions), + jacksonTypeRef(), + ) + + assertThat(roundtrippedProjectHostedToolPermissions).isEqualTo(projectHostedToolPermissions) + } +} diff --git a/openai-java-core/src/test/kotlin/com/openai/models/admin/organization/projects/modelpermissions/ModelPermissionDeleteParamsTest.kt b/openai-java-core/src/test/kotlin/com/openai/models/admin/organization/projects/modelpermissions/ModelPermissionDeleteParamsTest.kt new file mode 100644 index 000000000..bb2540446 --- /dev/null +++ b/openai-java-core/src/test/kotlin/com/openai/models/admin/organization/projects/modelpermissions/ModelPermissionDeleteParamsTest.kt @@ -0,0 +1,23 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.models.admin.organization.projects.modelpermissions + +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test + +internal class ModelPermissionDeleteParamsTest { + + @Test + fun create() { + ModelPermissionDeleteParams.builder().projectId("project_id").build() + } + + @Test + fun pathParams() { + val params = ModelPermissionDeleteParams.builder().projectId("project_id").build() + + assertThat(params._pathParam(0)).isEqualTo("project_id") + // out-of-bound path param + assertThat(params._pathParam(1)).isEqualTo("") + } +} diff --git a/openai-java-core/src/test/kotlin/com/openai/models/admin/organization/projects/modelpermissions/ModelPermissionRetrieveParamsTest.kt b/openai-java-core/src/test/kotlin/com/openai/models/admin/organization/projects/modelpermissions/ModelPermissionRetrieveParamsTest.kt new file mode 100644 index 000000000..aa6438efa --- /dev/null +++ b/openai-java-core/src/test/kotlin/com/openai/models/admin/organization/projects/modelpermissions/ModelPermissionRetrieveParamsTest.kt @@ -0,0 +1,23 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.models.admin.organization.projects.modelpermissions + +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test + +internal class ModelPermissionRetrieveParamsTest { + + @Test + fun create() { + ModelPermissionRetrieveParams.builder().projectId("project_id").build() + } + + @Test + fun pathParams() { + val params = ModelPermissionRetrieveParams.builder().projectId("project_id").build() + + assertThat(params._pathParam(0)).isEqualTo("project_id") + // out-of-bound path param + assertThat(params._pathParam(1)).isEqualTo("") + } +} diff --git a/openai-java-core/src/test/kotlin/com/openai/models/admin/organization/projects/modelpermissions/ModelPermissionUpdateParamsTest.kt b/openai-java-core/src/test/kotlin/com/openai/models/admin/organization/projects/modelpermissions/ModelPermissionUpdateParamsTest.kt new file mode 100644 index 000000000..f78c463c8 --- /dev/null +++ b/openai-java-core/src/test/kotlin/com/openai/models/admin/organization/projects/modelpermissions/ModelPermissionUpdateParamsTest.kt @@ -0,0 +1,47 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.models.admin.organization.projects.modelpermissions + +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test + +internal class ModelPermissionUpdateParamsTest { + + @Test + fun create() { + ModelPermissionUpdateParams.builder() + .projectId("project_id") + .mode(ModelPermissionUpdateParams.Mode.ALLOW_LIST) + .addModelId("string") + .build() + } + + @Test + fun pathParams() { + val params = + ModelPermissionUpdateParams.builder() + .projectId("project_id") + .mode(ModelPermissionUpdateParams.Mode.ALLOW_LIST) + .addModelId("string") + .build() + + assertThat(params._pathParam(0)).isEqualTo("project_id") + // out-of-bound path param + assertThat(params._pathParam(1)).isEqualTo("") + } + + @Test + fun body() { + val params = + ModelPermissionUpdateParams.builder() + .projectId("project_id") + .mode(ModelPermissionUpdateParams.Mode.ALLOW_LIST) + .addModelId("string") + .build() + + val body = params._body() + + assertThat(body.mode()).isEqualTo(ModelPermissionUpdateParams.Mode.ALLOW_LIST) + assertThat(body.modelIds()).containsExactly("string") + } +} diff --git a/openai-java-core/src/test/kotlin/com/openai/models/admin/organization/projects/modelpermissions/ProjectModelPermissionsDeletedTest.kt b/openai-java-core/src/test/kotlin/com/openai/models/admin/organization/projects/modelpermissions/ProjectModelPermissionsDeletedTest.kt new file mode 100644 index 000000000..c149fa09b --- /dev/null +++ b/openai-java-core/src/test/kotlin/com/openai/models/admin/organization/projects/modelpermissions/ProjectModelPermissionsDeletedTest.kt @@ -0,0 +1,35 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.models.admin.organization.projects.modelpermissions + +import com.fasterxml.jackson.module.kotlin.jacksonTypeRef +import com.openai.core.jsonMapper +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test + +internal class ProjectModelPermissionsDeletedTest { + + @Test + fun create() { + val projectModelPermissionsDeleted = + ProjectModelPermissionsDeleted.builder().deleted(true).build() + + assertThat(projectModelPermissionsDeleted.deleted()).isEqualTo(true) + } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val projectModelPermissionsDeleted = + ProjectModelPermissionsDeleted.builder().deleted(true).build() + + val roundtrippedProjectModelPermissionsDeleted = + jsonMapper.readValue( + jsonMapper.writeValueAsString(projectModelPermissionsDeleted), + jacksonTypeRef(), + ) + + assertThat(roundtrippedProjectModelPermissionsDeleted) + .isEqualTo(projectModelPermissionsDeleted) + } +} diff --git a/openai-java-core/src/test/kotlin/com/openai/models/admin/organization/projects/modelpermissions/ProjectModelPermissionsTest.kt b/openai-java-core/src/test/kotlin/com/openai/models/admin/organization/projects/modelpermissions/ProjectModelPermissionsTest.kt new file mode 100644 index 000000000..46f4ffc66 --- /dev/null +++ b/openai-java-core/src/test/kotlin/com/openai/models/admin/organization/projects/modelpermissions/ProjectModelPermissionsTest.kt @@ -0,0 +1,42 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.models.admin.organization.projects.modelpermissions + +import com.fasterxml.jackson.module.kotlin.jacksonTypeRef +import com.openai.core.jsonMapper +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test + +internal class ProjectModelPermissionsTest { + + @Test + fun create() { + val projectModelPermissions = + ProjectModelPermissions.builder() + .mode(ProjectModelPermissions.Mode.ALLOW_LIST) + .addModelId("string") + .build() + + assertThat(projectModelPermissions.mode()) + .isEqualTo(ProjectModelPermissions.Mode.ALLOW_LIST) + assertThat(projectModelPermissions.modelIds()).containsExactly("string") + } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val projectModelPermissions = + ProjectModelPermissions.builder() + .mode(ProjectModelPermissions.Mode.ALLOW_LIST) + .addModelId("string") + .build() + + val roundtrippedProjectModelPermissions = + jsonMapper.readValue( + jsonMapper.writeValueAsString(projectModelPermissions), + jacksonTypeRef(), + ) + + assertThat(roundtrippedProjectModelPermissions).isEqualTo(projectModelPermissions) + } +} diff --git a/openai-java-core/src/test/kotlin/com/openai/models/admin/organization/usage/UsageFileSearchCallsParamsTest.kt b/openai-java-core/src/test/kotlin/com/openai/models/admin/organization/usage/UsageFileSearchCallsParamsTest.kt new file mode 100644 index 000000000..c02b23724 --- /dev/null +++ b/openai-java-core/src/test/kotlin/com/openai/models/admin/organization/usage/UsageFileSearchCallsParamsTest.kt @@ -0,0 +1,70 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.models.admin.organization.usage + +import com.openai.core.http.QueryParams +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test + +internal class UsageFileSearchCallsParamsTest { + + @Test + fun create() { + UsageFileSearchCallsParams.builder() + .startTime(0L) + .addApiKeyId("string") + .bucketWidth(UsageFileSearchCallsParams.BucketWidth._1M) + .endTime(0L) + .addGroupBy(UsageFileSearchCallsParams.GroupBy.PROJECT_ID) + .limit(0L) + .page("page") + .addProjectId("string") + .addUserId("string") + .addVectorStoreId("string") + .build() + } + + @Test + fun queryParams() { + val params = + UsageFileSearchCallsParams.builder() + .startTime(0L) + .addApiKeyId("string") + .bucketWidth(UsageFileSearchCallsParams.BucketWidth._1M) + .endTime(0L) + .addGroupBy(UsageFileSearchCallsParams.GroupBy.PROJECT_ID) + .limit(0L) + .page("page") + .addProjectId("string") + .addUserId("string") + .addVectorStoreId("string") + .build() + + val queryParams = params._queryParams() + + assertThat(queryParams) + .isEqualTo( + QueryParams.builder() + .put("start_time", "0") + .put("api_key_ids[]", "string") + .put("bucket_width", "1m") + .put("end_time", "0") + .put("group_by[]", "project_id") + .put("limit", "0") + .put("page", "page") + .put("project_ids[]", "string") + .put("user_ids[]", "string") + .put("vector_store_ids[]", "string") + .build() + ) + } + + @Test + fun queryParamsWithoutOptionalFields() { + val params = UsageFileSearchCallsParams.builder().startTime(0L).build() + + val queryParams = params._queryParams() + + assertThat(queryParams).isEqualTo(QueryParams.builder().put("start_time", "0").build()) + } +} diff --git a/openai-java-core/src/test/kotlin/com/openai/models/admin/organization/usage/UsageFileSearchCallsResponseTest.kt b/openai-java-core/src/test/kotlin/com/openai/models/admin/organization/usage/UsageFileSearchCallsResponseTest.kt new file mode 100644 index 000000000..c7021a07c --- /dev/null +++ b/openai-java-core/src/test/kotlin/com/openai/models/admin/organization/usage/UsageFileSearchCallsResponseTest.kt @@ -0,0 +1,113 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.models.admin.organization.usage + +import com.fasterxml.jackson.module.kotlin.jacksonTypeRef +import com.openai.core.jsonMapper +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test + +internal class UsageFileSearchCallsResponseTest { + + @Test + fun create() { + val usageFileSearchCallsResponse = + UsageFileSearchCallsResponse.builder() + .addData( + UsageFileSearchCallsResponse.Data.builder() + .endTime(0L) + .addResult( + UsageFileSearchCallsResponse.Data.Result + .OrganizationUsageCompletionsResult + .builder() + .inputTokens(0L) + .numModelRequests(0L) + .outputTokens(0L) + .apiKeyId("api_key_id") + .batch(true) + .inputAudioTokens(0L) + .inputCachedTokens(0L) + .model("model") + .outputAudioTokens(0L) + .projectId("project_id") + .serviceTier("service_tier") + .userId("user_id") + .build() + ) + .startTime(0L) + .build() + ) + .hasMore(true) + .nextPage("next_page") + .build() + + assertThat(usageFileSearchCallsResponse.data()) + .containsExactly( + UsageFileSearchCallsResponse.Data.builder() + .endTime(0L) + .addResult( + UsageFileSearchCallsResponse.Data.Result.OrganizationUsageCompletionsResult + .builder() + .inputTokens(0L) + .numModelRequests(0L) + .outputTokens(0L) + .apiKeyId("api_key_id") + .batch(true) + .inputAudioTokens(0L) + .inputCachedTokens(0L) + .model("model") + .outputAudioTokens(0L) + .projectId("project_id") + .serviceTier("service_tier") + .userId("user_id") + .build() + ) + .startTime(0L) + .build() + ) + assertThat(usageFileSearchCallsResponse.hasMore()).isEqualTo(true) + assertThat(usageFileSearchCallsResponse.nextPage()).contains("next_page") + } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val usageFileSearchCallsResponse = + UsageFileSearchCallsResponse.builder() + .addData( + UsageFileSearchCallsResponse.Data.builder() + .endTime(0L) + .addResult( + UsageFileSearchCallsResponse.Data.Result + .OrganizationUsageCompletionsResult + .builder() + .inputTokens(0L) + .numModelRequests(0L) + .outputTokens(0L) + .apiKeyId("api_key_id") + .batch(true) + .inputAudioTokens(0L) + .inputCachedTokens(0L) + .model("model") + .outputAudioTokens(0L) + .projectId("project_id") + .serviceTier("service_tier") + .userId("user_id") + .build() + ) + .startTime(0L) + .build() + ) + .hasMore(true) + .nextPage("next_page") + .build() + + val roundtrippedUsageFileSearchCallsResponse = + jsonMapper.readValue( + jsonMapper.writeValueAsString(usageFileSearchCallsResponse), + jacksonTypeRef(), + ) + + assertThat(roundtrippedUsageFileSearchCallsResponse).isEqualTo(usageFileSearchCallsResponse) + } +} diff --git a/openai-java-core/src/test/kotlin/com/openai/models/admin/organization/usage/UsageWebSearchCallsParamsTest.kt b/openai-java-core/src/test/kotlin/com/openai/models/admin/organization/usage/UsageWebSearchCallsParamsTest.kt new file mode 100644 index 000000000..05763666d --- /dev/null +++ b/openai-java-core/src/test/kotlin/com/openai/models/admin/organization/usage/UsageWebSearchCallsParamsTest.kt @@ -0,0 +1,73 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.models.admin.organization.usage + +import com.openai.core.http.QueryParams +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test + +internal class UsageWebSearchCallsParamsTest { + + @Test + fun create() { + UsageWebSearchCallsParams.builder() + .startTime(0L) + .addApiKeyId("string") + .bucketWidth(UsageWebSearchCallsParams.BucketWidth._1M) + .addContextLevel(UsageWebSearchCallsParams.ContextLevel.LOW) + .endTime(0L) + .addGroupBy(UsageWebSearchCallsParams.GroupBy.PROJECT_ID) + .limit(0L) + .addModel("string") + .page("page") + .addProjectId("string") + .addUserId("string") + .build() + } + + @Test + fun queryParams() { + val params = + UsageWebSearchCallsParams.builder() + .startTime(0L) + .addApiKeyId("string") + .bucketWidth(UsageWebSearchCallsParams.BucketWidth._1M) + .addContextLevel(UsageWebSearchCallsParams.ContextLevel.LOW) + .endTime(0L) + .addGroupBy(UsageWebSearchCallsParams.GroupBy.PROJECT_ID) + .limit(0L) + .addModel("string") + .page("page") + .addProjectId("string") + .addUserId("string") + .build() + + val queryParams = params._queryParams() + + assertThat(queryParams) + .isEqualTo( + QueryParams.builder() + .put("start_time", "0") + .put("api_key_ids[]", "string") + .put("bucket_width", "1m") + .put("context_levels[]", "low") + .put("end_time", "0") + .put("group_by[]", "project_id") + .put("limit", "0") + .put("models[]", "string") + .put("page", "page") + .put("project_ids[]", "string") + .put("user_ids[]", "string") + .build() + ) + } + + @Test + fun queryParamsWithoutOptionalFields() { + val params = UsageWebSearchCallsParams.builder().startTime(0L).build() + + val queryParams = params._queryParams() + + assertThat(queryParams).isEqualTo(QueryParams.builder().put("start_time", "0").build()) + } +} diff --git a/openai-java-core/src/test/kotlin/com/openai/models/admin/organization/usage/UsageWebSearchCallsResponseTest.kt b/openai-java-core/src/test/kotlin/com/openai/models/admin/organization/usage/UsageWebSearchCallsResponseTest.kt new file mode 100644 index 000000000..bf6f0f40f --- /dev/null +++ b/openai-java-core/src/test/kotlin/com/openai/models/admin/organization/usage/UsageWebSearchCallsResponseTest.kt @@ -0,0 +1,113 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.models.admin.organization.usage + +import com.fasterxml.jackson.module.kotlin.jacksonTypeRef +import com.openai.core.jsonMapper +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test + +internal class UsageWebSearchCallsResponseTest { + + @Test + fun create() { + val usageWebSearchCallsResponse = + UsageWebSearchCallsResponse.builder() + .addData( + UsageWebSearchCallsResponse.Data.builder() + .endTime(0L) + .addResult( + UsageWebSearchCallsResponse.Data.Result + .OrganizationUsageCompletionsResult + .builder() + .inputTokens(0L) + .numModelRequests(0L) + .outputTokens(0L) + .apiKeyId("api_key_id") + .batch(true) + .inputAudioTokens(0L) + .inputCachedTokens(0L) + .model("model") + .outputAudioTokens(0L) + .projectId("project_id") + .serviceTier("service_tier") + .userId("user_id") + .build() + ) + .startTime(0L) + .build() + ) + .hasMore(true) + .nextPage("next_page") + .build() + + assertThat(usageWebSearchCallsResponse.data()) + .containsExactly( + UsageWebSearchCallsResponse.Data.builder() + .endTime(0L) + .addResult( + UsageWebSearchCallsResponse.Data.Result.OrganizationUsageCompletionsResult + .builder() + .inputTokens(0L) + .numModelRequests(0L) + .outputTokens(0L) + .apiKeyId("api_key_id") + .batch(true) + .inputAudioTokens(0L) + .inputCachedTokens(0L) + .model("model") + .outputAudioTokens(0L) + .projectId("project_id") + .serviceTier("service_tier") + .userId("user_id") + .build() + ) + .startTime(0L) + .build() + ) + assertThat(usageWebSearchCallsResponse.hasMore()).isEqualTo(true) + assertThat(usageWebSearchCallsResponse.nextPage()).contains("next_page") + } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val usageWebSearchCallsResponse = + UsageWebSearchCallsResponse.builder() + .addData( + UsageWebSearchCallsResponse.Data.builder() + .endTime(0L) + .addResult( + UsageWebSearchCallsResponse.Data.Result + .OrganizationUsageCompletionsResult + .builder() + .inputTokens(0L) + .numModelRequests(0L) + .outputTokens(0L) + .apiKeyId("api_key_id") + .batch(true) + .inputAudioTokens(0L) + .inputCachedTokens(0L) + .model("model") + .outputAudioTokens(0L) + .projectId("project_id") + .serviceTier("service_tier") + .userId("user_id") + .build() + ) + .startTime(0L) + .build() + ) + .hasMore(true) + .nextPage("next_page") + .build() + + val roundtrippedUsageWebSearchCallsResponse = + jsonMapper.readValue( + jsonMapper.writeValueAsString(usageWebSearchCallsResponse), + jacksonTypeRef(), + ) + + assertThat(roundtrippedUsageWebSearchCallsResponse).isEqualTo(usageWebSearchCallsResponse) + } +} diff --git a/openai-java-core/src/test/kotlin/com/openai/services/async/admin/organization/UsageServiceAsyncTest.kt b/openai-java-core/src/test/kotlin/com/openai/services/async/admin/organization/UsageServiceAsyncTest.kt index 9036abf33..8cd3394ad 100644 --- a/openai-java-core/src/test/kotlin/com/openai/services/async/admin/organization/UsageServiceAsyncTest.kt +++ b/openai-java-core/src/test/kotlin/com/openai/services/async/admin/organization/UsageServiceAsyncTest.kt @@ -10,9 +10,11 @@ import com.openai.models.admin.organization.usage.UsageCodeInterpreterSessionsPa import com.openai.models.admin.organization.usage.UsageCompletionsParams import com.openai.models.admin.organization.usage.UsageCostsParams import com.openai.models.admin.organization.usage.UsageEmbeddingsParams +import com.openai.models.admin.organization.usage.UsageFileSearchCallsParams import com.openai.models.admin.organization.usage.UsageImagesParams import com.openai.models.admin.organization.usage.UsageModerationsParams import com.openai.models.admin.organization.usage.UsageVectorStoresParams +import com.openai.models.admin.organization.usage.UsageWebSearchCallsParams import org.junit.jupiter.api.Test import org.junit.jupiter.api.extension.ExtendWith @@ -195,6 +197,36 @@ internal class UsageServiceAsyncTest { response.validate() } + @Test + fun fileSearchCalls() { + val client = + OpenAIOkHttpClientAsync.builder() + .baseUrl(TestServerExtension.BASE_URL) + .apiKey("My API Key") + .adminApiKey("My Admin API Key") + .build() + val usageServiceAsync = client.admin().organization().usage() + + val responseFuture = + usageServiceAsync.fileSearchCalls( + UsageFileSearchCallsParams.builder() + .startTime(0L) + .addApiKeyId("string") + .bucketWidth(UsageFileSearchCallsParams.BucketWidth._1M) + .endTime(0L) + .addGroupBy(UsageFileSearchCallsParams.GroupBy.PROJECT_ID) + .limit(0L) + .page("page") + .addProjectId("string") + .addUserId("string") + .addVectorStoreId("string") + .build() + ) + + val response = responseFuture.get() + response.validate() + } + @Test fun images() { val client = @@ -283,4 +315,35 @@ internal class UsageServiceAsyncTest { val response = responseFuture.get() response.validate() } + + @Test + fun webSearchCalls() { + val client = + OpenAIOkHttpClientAsync.builder() + .baseUrl(TestServerExtension.BASE_URL) + .apiKey("My API Key") + .adminApiKey("My Admin API Key") + .build() + val usageServiceAsync = client.admin().organization().usage() + + val responseFuture = + usageServiceAsync.webSearchCalls( + UsageWebSearchCallsParams.builder() + .startTime(0L) + .addApiKeyId("string") + .bucketWidth(UsageWebSearchCallsParams.BucketWidth._1M) + .addContextLevel(UsageWebSearchCallsParams.ContextLevel.LOW) + .endTime(0L) + .addGroupBy(UsageWebSearchCallsParams.GroupBy.PROJECT_ID) + .limit(0L) + .addModel("string") + .page("page") + .addProjectId("string") + .addUserId("string") + .build() + ) + + val response = responseFuture.get() + response.validate() + } } diff --git a/openai-java-core/src/test/kotlin/com/openai/services/async/admin/organization/projects/HostedToolPermissionServiceAsyncTest.kt b/openai-java-core/src/test/kotlin/com/openai/services/async/admin/organization/projects/HostedToolPermissionServiceAsyncTest.kt new file mode 100644 index 000000000..1a8fe1a6e --- /dev/null +++ b/openai-java-core/src/test/kotlin/com/openai/services/async/admin/organization/projects/HostedToolPermissionServiceAsyncTest.kt @@ -0,0 +1,70 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.services.async.admin.organization.projects + +import com.openai.TestServerExtension +import com.openai.client.okhttp.OpenAIOkHttpClientAsync +import com.openai.models.admin.organization.projects.hostedtoolpermissions.HostedToolPermissionUpdateParams +import org.junit.jupiter.api.Test +import org.junit.jupiter.api.extension.ExtendWith + +@ExtendWith(TestServerExtension::class) +internal class HostedToolPermissionServiceAsyncTest { + + @Test + fun retrieve() { + val client = + OpenAIOkHttpClientAsync.builder() + .baseUrl(TestServerExtension.BASE_URL) + .apiKey("My API Key") + .adminApiKey("My Admin API Key") + .build() + val hostedToolPermissionServiceAsync = + client.admin().organization().projects().hostedToolPermissions() + + val projectHostedToolPermissionsFuture = + hostedToolPermissionServiceAsync.retrieve("project_id") + + val projectHostedToolPermissions = projectHostedToolPermissionsFuture.get() + projectHostedToolPermissions.validate() + } + + @Test + fun update() { + val client = + OpenAIOkHttpClientAsync.builder() + .baseUrl(TestServerExtension.BASE_URL) + .apiKey("My API Key") + .adminApiKey("My Admin API Key") + .build() + val hostedToolPermissionServiceAsync = + client.admin().organization().projects().hostedToolPermissions() + + val projectHostedToolPermissionsFuture = + hostedToolPermissionServiceAsync.update( + HostedToolPermissionUpdateParams.builder() + .projectId("project_id") + .codeInterpreter( + HostedToolPermissionUpdateParams.CodeInterpreter.builder() + .enabled(true) + .build() + ) + .fileSearch( + HostedToolPermissionUpdateParams.FileSearch.builder().enabled(true).build() + ) + .imageGeneration( + HostedToolPermissionUpdateParams.ImageGeneration.builder() + .enabled(true) + .build() + ) + .mcp(HostedToolPermissionUpdateParams.Mcp.builder().enabled(true).build()) + .webSearch( + HostedToolPermissionUpdateParams.WebSearch.builder().enabled(true).build() + ) + .build() + ) + + val projectHostedToolPermissions = projectHostedToolPermissionsFuture.get() + projectHostedToolPermissions.validate() + } +} diff --git a/openai-java-core/src/test/kotlin/com/openai/services/async/admin/organization/projects/ModelPermissionServiceAsyncTest.kt b/openai-java-core/src/test/kotlin/com/openai/services/async/admin/organization/projects/ModelPermissionServiceAsyncTest.kt new file mode 100644 index 000000000..4c3915653 --- /dev/null +++ b/openai-java-core/src/test/kotlin/com/openai/services/async/admin/organization/projects/ModelPermissionServiceAsyncTest.kt @@ -0,0 +1,71 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.services.async.admin.organization.projects + +import com.openai.TestServerExtension +import com.openai.client.okhttp.OpenAIOkHttpClientAsync +import com.openai.models.admin.organization.projects.modelpermissions.ModelPermissionUpdateParams +import org.junit.jupiter.api.Test +import org.junit.jupiter.api.extension.ExtendWith + +@ExtendWith(TestServerExtension::class) +internal class ModelPermissionServiceAsyncTest { + + @Test + fun retrieve() { + val client = + OpenAIOkHttpClientAsync.builder() + .baseUrl(TestServerExtension.BASE_URL) + .apiKey("My API Key") + .adminApiKey("My Admin API Key") + .build() + val modelPermissionServiceAsync = + client.admin().organization().projects().modelPermissions() + + val projectModelPermissionsFuture = modelPermissionServiceAsync.retrieve("project_id") + + val projectModelPermissions = projectModelPermissionsFuture.get() + projectModelPermissions.validate() + } + + @Test + fun update() { + val client = + OpenAIOkHttpClientAsync.builder() + .baseUrl(TestServerExtension.BASE_URL) + .apiKey("My API Key") + .adminApiKey("My Admin API Key") + .build() + val modelPermissionServiceAsync = + client.admin().organization().projects().modelPermissions() + + val projectModelPermissionsFuture = + modelPermissionServiceAsync.update( + ModelPermissionUpdateParams.builder() + .projectId("project_id") + .mode(ModelPermissionUpdateParams.Mode.ALLOW_LIST) + .addModelId("string") + .build() + ) + + val projectModelPermissions = projectModelPermissionsFuture.get() + projectModelPermissions.validate() + } + + @Test + fun delete() { + val client = + OpenAIOkHttpClientAsync.builder() + .baseUrl(TestServerExtension.BASE_URL) + .apiKey("My API Key") + .adminApiKey("My Admin API Key") + .build() + val modelPermissionServiceAsync = + client.admin().organization().projects().modelPermissions() + + val projectModelPermissionsDeletedFuture = modelPermissionServiceAsync.delete("project_id") + + val projectModelPermissionsDeleted = projectModelPermissionsDeletedFuture.get() + projectModelPermissionsDeleted.validate() + } +} diff --git a/openai-java-core/src/test/kotlin/com/openai/services/blocking/admin/organization/UsageServiceTest.kt b/openai-java-core/src/test/kotlin/com/openai/services/blocking/admin/organization/UsageServiceTest.kt index 91e552e5a..b598e44c1 100644 --- a/openai-java-core/src/test/kotlin/com/openai/services/blocking/admin/organization/UsageServiceTest.kt +++ b/openai-java-core/src/test/kotlin/com/openai/services/blocking/admin/organization/UsageServiceTest.kt @@ -10,9 +10,11 @@ import com.openai.models.admin.organization.usage.UsageCodeInterpreterSessionsPa import com.openai.models.admin.organization.usage.UsageCompletionsParams import com.openai.models.admin.organization.usage.UsageCostsParams import com.openai.models.admin.organization.usage.UsageEmbeddingsParams +import com.openai.models.admin.organization.usage.UsageFileSearchCallsParams import com.openai.models.admin.organization.usage.UsageImagesParams import com.openai.models.admin.organization.usage.UsageModerationsParams import com.openai.models.admin.organization.usage.UsageVectorStoresParams +import com.openai.models.admin.organization.usage.UsageWebSearchCallsParams import org.junit.jupiter.api.Test import org.junit.jupiter.api.extension.ExtendWith @@ -189,6 +191,35 @@ internal class UsageServiceTest { response.validate() } + @Test + fun fileSearchCalls() { + val client = + OpenAIOkHttpClient.builder() + .baseUrl(TestServerExtension.BASE_URL) + .apiKey("My API Key") + .adminApiKey("My Admin API Key") + .build() + val usageService = client.admin().organization().usage() + + val response = + usageService.fileSearchCalls( + UsageFileSearchCallsParams.builder() + .startTime(0L) + .addApiKeyId("string") + .bucketWidth(UsageFileSearchCallsParams.BucketWidth._1M) + .endTime(0L) + .addGroupBy(UsageFileSearchCallsParams.GroupBy.PROJECT_ID) + .limit(0L) + .page("page") + .addProjectId("string") + .addUserId("string") + .addVectorStoreId("string") + .build() + ) + + response.validate() + } + @Test fun images() { val client = @@ -274,4 +305,34 @@ internal class UsageServiceTest { response.validate() } + + @Test + fun webSearchCalls() { + val client = + OpenAIOkHttpClient.builder() + .baseUrl(TestServerExtension.BASE_URL) + .apiKey("My API Key") + .adminApiKey("My Admin API Key") + .build() + val usageService = client.admin().organization().usage() + + val response = + usageService.webSearchCalls( + UsageWebSearchCallsParams.builder() + .startTime(0L) + .addApiKeyId("string") + .bucketWidth(UsageWebSearchCallsParams.BucketWidth._1M) + .addContextLevel(UsageWebSearchCallsParams.ContextLevel.LOW) + .endTime(0L) + .addGroupBy(UsageWebSearchCallsParams.GroupBy.PROJECT_ID) + .limit(0L) + .addModel("string") + .page("page") + .addProjectId("string") + .addUserId("string") + .build() + ) + + response.validate() + } } diff --git a/openai-java-core/src/test/kotlin/com/openai/services/blocking/admin/organization/projects/HostedToolPermissionServiceTest.kt b/openai-java-core/src/test/kotlin/com/openai/services/blocking/admin/organization/projects/HostedToolPermissionServiceTest.kt new file mode 100644 index 000000000..41f486e8a --- /dev/null +++ b/openai-java-core/src/test/kotlin/com/openai/services/blocking/admin/organization/projects/HostedToolPermissionServiceTest.kt @@ -0,0 +1,67 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.services.blocking.admin.organization.projects + +import com.openai.TestServerExtension +import com.openai.client.okhttp.OpenAIOkHttpClient +import com.openai.models.admin.organization.projects.hostedtoolpermissions.HostedToolPermissionUpdateParams +import org.junit.jupiter.api.Test +import org.junit.jupiter.api.extension.ExtendWith + +@ExtendWith(TestServerExtension::class) +internal class HostedToolPermissionServiceTest { + + @Test + fun retrieve() { + val client = + OpenAIOkHttpClient.builder() + .baseUrl(TestServerExtension.BASE_URL) + .apiKey("My API Key") + .adminApiKey("My Admin API Key") + .build() + val hostedToolPermissionService = + client.admin().organization().projects().hostedToolPermissions() + + val projectHostedToolPermissions = hostedToolPermissionService.retrieve("project_id") + + projectHostedToolPermissions.validate() + } + + @Test + fun update() { + val client = + OpenAIOkHttpClient.builder() + .baseUrl(TestServerExtension.BASE_URL) + .apiKey("My API Key") + .adminApiKey("My Admin API Key") + .build() + val hostedToolPermissionService = + client.admin().organization().projects().hostedToolPermissions() + + val projectHostedToolPermissions = + hostedToolPermissionService.update( + HostedToolPermissionUpdateParams.builder() + .projectId("project_id") + .codeInterpreter( + HostedToolPermissionUpdateParams.CodeInterpreter.builder() + .enabled(true) + .build() + ) + .fileSearch( + HostedToolPermissionUpdateParams.FileSearch.builder().enabled(true).build() + ) + .imageGeneration( + HostedToolPermissionUpdateParams.ImageGeneration.builder() + .enabled(true) + .build() + ) + .mcp(HostedToolPermissionUpdateParams.Mcp.builder().enabled(true).build()) + .webSearch( + HostedToolPermissionUpdateParams.WebSearch.builder().enabled(true).build() + ) + .build() + ) + + projectHostedToolPermissions.validate() + } +} diff --git a/openai-java-core/src/test/kotlin/com/openai/services/blocking/admin/organization/projects/ModelPermissionServiceTest.kt b/openai-java-core/src/test/kotlin/com/openai/services/blocking/admin/organization/projects/ModelPermissionServiceTest.kt new file mode 100644 index 000000000..5b02f6743 --- /dev/null +++ b/openai-java-core/src/test/kotlin/com/openai/services/blocking/admin/organization/projects/ModelPermissionServiceTest.kt @@ -0,0 +1,65 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.services.blocking.admin.organization.projects + +import com.openai.TestServerExtension +import com.openai.client.okhttp.OpenAIOkHttpClient +import com.openai.models.admin.organization.projects.modelpermissions.ModelPermissionUpdateParams +import org.junit.jupiter.api.Test +import org.junit.jupiter.api.extension.ExtendWith + +@ExtendWith(TestServerExtension::class) +internal class ModelPermissionServiceTest { + + @Test + fun retrieve() { + val client = + OpenAIOkHttpClient.builder() + .baseUrl(TestServerExtension.BASE_URL) + .apiKey("My API Key") + .adminApiKey("My Admin API Key") + .build() + val modelPermissionService = client.admin().organization().projects().modelPermissions() + + val projectModelPermissions = modelPermissionService.retrieve("project_id") + + projectModelPermissions.validate() + } + + @Test + fun update() { + val client = + OpenAIOkHttpClient.builder() + .baseUrl(TestServerExtension.BASE_URL) + .apiKey("My API Key") + .adminApiKey("My Admin API Key") + .build() + val modelPermissionService = client.admin().organization().projects().modelPermissions() + + val projectModelPermissions = + modelPermissionService.update( + ModelPermissionUpdateParams.builder() + .projectId("project_id") + .mode(ModelPermissionUpdateParams.Mode.ALLOW_LIST) + .addModelId("string") + .build() + ) + + projectModelPermissions.validate() + } + + @Test + fun delete() { + val client = + OpenAIOkHttpClient.builder() + .baseUrl(TestServerExtension.BASE_URL) + .apiKey("My API Key") + .adminApiKey("My Admin API Key") + .build() + val modelPermissionService = client.admin().organization().projects().modelPermissions() + + val projectModelPermissionsDeleted = modelPermissionService.delete("project_id") + + projectModelPermissionsDeleted.validate() + } +} From 704032ebbb3244054e5e8425c82dfe45562378e9 Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Tue, 19 May 2026 19:53:08 +0000 Subject: [PATCH 6/8] chore(api): docs updates --- .stats.yml | 6 +++--- .../openai/models/responses/ResponseFunctionWebSearch.kt | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.stats.yml b/.stats.yml index 787895e02..efb841c22 100644 --- a/.stats.yml +++ b/.stats.yml @@ -1,4 +1,4 @@ configured_endpoints: 239 -openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/openai/openai-d7d5adb20c516e7aca6e35ed9f58aba0bc14dd5aa0096fd980061c4a5ab406e3.yml -openapi_spec_hash: 72ee7d4fe582e75d16e67b6c97881fed -config_hash: af72288617facaeed4d014024a9c946d +openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/openai/openai-66f110677cd924205b0a4e2a1f567c8b56349ee9658bd0ce86561a413a2aabfe.yml +openapi_spec_hash: ab8f320a7a6b2d30d5f1665b8a8bf84e +config_hash: 425042cc0e99cf31866f6c98fef2be27 diff --git a/openai-java-core/src/main/kotlin/com/openai/models/responses/ResponseFunctionWebSearch.kt b/openai-java-core/src/main/kotlin/com/openai/models/responses/ResponseFunctionWebSearch.kt index edf29d553..ecbe1232c 100644 --- a/openai-java-core/src/main/kotlin/com/openai/models/responses/ResponseFunctionWebSearch.kt +++ b/openai-java-core/src/main/kotlin/com/openai/models/responses/ResponseFunctionWebSearch.kt @@ -1110,7 +1110,7 @@ private constructor( ) : this(type, url, mutableMapOf()) /** - * The action type. + * The action type. Always `open_page`. * * Expected to always return the following: * ```java From 751f476ae83e88dcf122aa2d34bdc16983e800b4 Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Thu, 21 May 2026 18:02:42 +0000 Subject: [PATCH 7/8] feat(api): manual updates add spend alert, data retention and admin api --- .stats.yml | 8 +- .../DataRetentionRetrieveParams.kt | 172 +++ .../DataRetentionUpdateParams.kt | 596 ++++++++ .../OrganizationDataRetention.kt | 373 +++++ .../models/admin/organization/groups/Group.kt | 161 ++- .../groups/GroupRetrieveParams.kt | 189 +++ .../groups/roles/RoleListResponse.kt | 282 +++- .../groups/roles/RoleRetrieveParams.kt | 217 +++ .../groups/roles/RoleRetrieveResponse.kt | 1155 +++++++++++++++ .../groups/users/UserRetrieveParams.kt | 217 +++ .../groups/users/UserRetrieveResponse.kt | 532 +++++++ .../DataRetentionRetrieveParams.kt | 195 +++ .../DataRetentionUpdateParams.kt | 628 +++++++++ .../dataretention/ProjectDataRetention.kt | 385 +++++ .../projects/groups/GroupRetrieveParams.kt | 378 +++++ .../projects/groups/ProjectGroup.kt | 161 ++- .../projects/groups/roles/RoleListResponse.kt | 282 +++- .../groups/roles/RoleRetrieveParams.kt | 229 +++ .../groups/roles/RoleRetrieveResponse.kt | 1155 +++++++++++++++ .../projects/roles/RoleRetrieveParams.kt | 217 +++ .../ServiceAccountUpdateParams.kt | 642 +++++++++ .../projects/spendalerts/ProjectSpendAlert.kt | 936 +++++++++++++ .../spendalerts/ProjectSpendAlertDeleted.kt | 259 ++++ .../spendalerts/SpendAlertCreateParams.kt | 1227 ++++++++++++++++ .../spendalerts/SpendAlertDeleteParams.kt | 259 ++++ .../spendalerts/SpendAlertListPage.kt | 139 ++ .../spendalerts/SpendAlertListPageAsync.kt | 154 ++ .../spendalerts/SpendAlertListPageResponse.kt | 360 +++++ .../spendalerts/SpendAlertListParams.kt | 425 ++++++ .../spendalerts/SpendAlertUpdateParams.kt | 1239 +++++++++++++++++ .../projects/users/roles/RoleListResponse.kt | 282 +++- .../users/roles/RoleRetrieveParams.kt | 229 +++ .../users/roles/RoleRetrieveResponse.kt | 1155 +++++++++++++++ .../organization/roles/RoleRetrieveParams.kt | 189 +++ .../spendalerts/OrganizationSpendAlert.kt | 936 +++++++++++++ .../OrganizationSpendAlertDeleted.kt | 260 ++++ .../spendalerts/SpendAlertCreateParams.kt | 1208 ++++++++++++++++ .../spendalerts/SpendAlertDeleteParams.kt | 230 +++ .../spendalerts/SpendAlertListPage.kt | 139 ++ .../spendalerts/SpendAlertListPageAsync.kt | 154 ++ .../spendalerts/SpendAlertListPageResponse.kt | 362 +++++ .../spendalerts/SpendAlertListParams.kt | 399 ++++++ .../spendalerts/SpendAlertUpdateParams.kt | 1227 ++++++++++++++++ .../users/roles/RoleListResponse.kt | 282 +++- .../users/roles/RoleRetrieveParams.kt | 217 +++ .../users/roles/RoleRetrieveResponse.kt | 1155 +++++++++++++++ .../responses/ResponseFunctionWebSearch.kt | 2 +- .../async/admin/OrganizationServiceAsync.kt | 10 + .../admin/OrganizationServiceAsyncImpl.kt | 28 + .../organization/DataRetentionServiceAsync.kt | 112 ++ .../DataRetentionServiceAsyncImpl.kt | 133 ++ .../admin/organization/GroupServiceAsync.kt | 72 + .../organization/GroupServiceAsyncImpl.kt | 44 + .../admin/organization/ProjectServiceAsync.kt | 10 + .../organization/ProjectServiceAsyncImpl.kt | 28 + .../admin/organization/RoleServiceAsync.kt | 71 + .../organization/RoleServiceAsyncImpl.kt | 44 + .../organization/SpendAlertServiceAsync.kt | 248 ++++ .../SpendAlertServiceAsyncImpl.kt | 238 ++++ .../organization/groups/RoleServiceAsync.kt | 56 + .../groups/RoleServiceAsyncImpl.kt | 52 + .../organization/groups/UserServiceAsync.kt | 56 + .../groups/UserServiceAsyncImpl.kt | 52 + .../projects/DataRetentionServiceAsync.kt | 174 +++ .../projects/DataRetentionServiceAsyncImpl.kt | 151 ++ .../projects/GroupServiceAsync.kt | 54 + .../projects/GroupServiceAsyncImpl.kt | 51 + .../organization/projects/RoleServiceAsync.kt | 50 + .../projects/RoleServiceAsyncImpl.kt | 49 + .../projects/ServiceAccountServiceAsync.kt | 57 + .../ServiceAccountServiceAsyncImpl.kt | 52 + .../projects/SpendAlertServiceAsync.kt | 287 ++++ .../projects/SpendAlertServiceAsyncImpl.kt | 266 ++++ .../projects/groups/RoleServiceAsync.kt | 57 + .../projects/groups/RoleServiceAsyncImpl.kt | 53 + .../projects/users/RoleServiceAsync.kt | 57 + .../projects/users/RoleServiceAsyncImpl.kt | 53 + .../organization/users/RoleServiceAsync.kt | 56 + .../users/RoleServiceAsyncImpl.kt | 52 + .../blocking/admin/OrganizationService.kt | 10 + .../blocking/admin/OrganizationServiceImpl.kt | 26 + .../organization/DataRetentionService.kt | 111 ++ .../organization/DataRetentionServiceImpl.kt | 126 ++ .../admin/organization/GroupService.kt | 69 + .../admin/organization/GroupServiceImpl.kt | 38 + .../admin/organization/ProjectService.kt | 10 + .../admin/organization/ProjectServiceImpl.kt | 26 + .../admin/organization/RoleService.kt | 69 + .../admin/organization/RoleServiceImpl.kt | 38 + .../admin/organization/SpendAlertService.kt | 240 ++++ .../organization/SpendAlertServiceImpl.kt | 224 +++ .../admin/organization/groups/RoleService.kt | 54 + .../organization/groups/RoleServiceImpl.kt | 49 + .../admin/organization/groups/UserService.kt | 54 + .../organization/groups/UserServiceImpl.kt | 49 + .../projects/DataRetentionService.kt | 173 +++ .../projects/DataRetentionServiceImpl.kt | 144 ++ .../organization/projects/GroupService.kt | 52 + .../organization/projects/GroupServiceImpl.kt | 48 + .../organization/projects/RoleService.kt | 50 + .../organization/projects/RoleServiceImpl.kt | 43 + .../projects/ServiceAccountService.kt | 58 + .../projects/ServiceAccountServiceImpl.kt | 49 + .../projects/SpendAlertService.kt | 277 ++++ .../projects/SpendAlertServiceImpl.kt | 252 ++++ .../projects/groups/RoleService.kt | 55 + .../projects/groups/RoleServiceImpl.kt | 50 + .../projects/users/RoleService.kt | 55 + .../projects/users/RoleServiceImpl.kt | 50 + .../admin/organization/users/RoleService.kt | 54 + .../organization/users/RoleServiceImpl.kt | 49 + .../DataRetentionRetrieveParamsTest.kt | 13 + .../DataRetentionUpdateParamsTest.kt | 29 + .../OrganizationDataRetentionTest.kt | 39 + .../groups/GroupListPageResponseTest.kt | 6 +- .../groups/GroupRetrieveParamsTest.kt | 23 + .../admin/organization/groups/GroupTest.kt | 6 +- .../groups/roles/RoleListPageResponseTest.kt | 18 + .../groups/roles/RoleListResponseTest.kt | 20 + .../groups/roles/RoleRetrieveParamsTest.kt | 24 + .../groups/roles/RoleRetrieveResponseTest.kt | 115 ++ .../groups/users/UserRetrieveParamsTest.kt | 24 + .../groups/users/UserRetrieveResponseTest.kt | 53 + .../DataRetentionRetrieveParamsTest.kt | 23 + .../DataRetentionUpdateParamsTest.kt | 44 + .../dataretention/ProjectDataRetentionTest.kt | 39 + .../groups/GroupListPageResponseTest.kt | 6 +- .../groups/GroupRetrieveParamsTest.kt | 54 + .../projects/groups/ProjectGroupTest.kt | 6 +- .../groups/roles/RoleListPageResponseTest.kt | 18 + .../groups/roles/RoleListResponseTest.kt | 20 + .../groups/roles/RoleRetrieveParamsTest.kt | 34 + .../groups/roles/RoleRetrieveResponseTest.kt | 115 ++ .../projects/roles/RoleRetrieveParamsTest.kt | 24 + .../ServiceAccountUpdateParamsTest.kt | 60 + .../ProjectSpendAlertDeletedTest.kt | 35 + .../spendalerts/ProjectSpendAlertTest.kt | 66 + .../spendalerts/SpendAlertCreateParamsTest.kt | 101 ++ .../spendalerts/SpendAlertDeleteParamsTest.kt | 25 + .../SpendAlertListPageResponseTest.kt | 87 ++ .../spendalerts/SpendAlertListParamsTest.kt | 63 + .../spendalerts/SpendAlertUpdateParamsTest.kt | 106 ++ .../users/roles/RoleListPageResponseTest.kt | 18 + .../users/roles/RoleListResponseTest.kt | 20 + .../users/roles/RoleRetrieveParamsTest.kt | 34 + .../users/roles/RoleRetrieveResponseTest.kt | 115 ++ .../roles/RoleRetrieveParamsTest.kt | 23 + .../OrganizationSpendAlertDeletedTest.kt | 36 + .../spendalerts/OrganizationSpendAlertTest.kt | 67 + .../spendalerts/SpendAlertCreateParamsTest.kt | 78 ++ .../spendalerts/SpendAlertDeleteParamsTest.kt | 23 + .../SpendAlertListPageResponseTest.kt | 87 ++ .../spendalerts/SpendAlertListParamsTest.kt | 52 + .../spendalerts/SpendAlertUpdateParamsTest.kt | 101 ++ .../users/roles/RoleListPageResponseTest.kt | 18 + .../users/roles/RoleListResponseTest.kt | 20 + .../users/roles/RoleRetrieveParamsTest.kt | 24 + .../users/roles/RoleRetrieveResponseTest.kt | 115 ++ .../DataRetentionServiceAsyncTest.kt | 50 + .../organization/GroupServiceAsyncTest.kt | 16 + .../organization/RoleServiceAsyncTest.kt | 16 + .../SpendAlertServiceAsyncTest.kt | 105 ++ .../groups/RoleServiceAsyncTest.kt | 20 + .../groups/UserServiceAsyncTest.kt | 20 + .../projects/DataRetentionServiceAsyncTest.kt | 51 + .../projects/GroupServiceAsyncTest.kt | 24 + .../projects/RoleServiceAsyncTest.kt | 20 + .../ServiceAccountServiceAsyncTest.kt | 25 + .../projects/SpendAlertServiceAsyncTest.kt | 111 ++ .../projects/groups/RoleServiceAsyncTest.kt | 24 + .../projects/users/RoleServiceAsyncTest.kt | 24 + .../users/RoleServiceAsyncTest.kt | 20 + .../organization/DataRetentionServiceTest.kt | 48 + .../admin/organization/GroupServiceTest.kt | 15 + .../admin/organization/RoleServiceTest.kt | 15 + .../organization/SpendAlertServiceTest.kt | 101 ++ .../organization/groups/RoleServiceTest.kt | 19 + .../organization/groups/UserServiceTest.kt | 19 + .../projects/DataRetentionServiceTest.kt | 49 + .../organization/projects/GroupServiceTest.kt | 23 + .../organization/projects/RoleServiceTest.kt | 19 + .../projects/ServiceAccountServiceTest.kt | 24 + .../projects/SpendAlertServiceTest.kt | 107 ++ .../projects/groups/RoleServiceTest.kt | 23 + .../projects/users/RoleServiceTest.kt | 23 + .../organization/users/RoleServiceTest.kt | 19 + 186 files changed, 30139 insertions(+), 41 deletions(-) create mode 100644 openai-java-core/src/main/kotlin/com/openai/models/admin/organization/dataretention/DataRetentionRetrieveParams.kt create mode 100644 openai-java-core/src/main/kotlin/com/openai/models/admin/organization/dataretention/DataRetentionUpdateParams.kt create mode 100644 openai-java-core/src/main/kotlin/com/openai/models/admin/organization/dataretention/OrganizationDataRetention.kt create mode 100644 openai-java-core/src/main/kotlin/com/openai/models/admin/organization/groups/GroupRetrieveParams.kt create mode 100644 openai-java-core/src/main/kotlin/com/openai/models/admin/organization/groups/roles/RoleRetrieveParams.kt create mode 100644 openai-java-core/src/main/kotlin/com/openai/models/admin/organization/groups/roles/RoleRetrieveResponse.kt create mode 100644 openai-java-core/src/main/kotlin/com/openai/models/admin/organization/groups/users/UserRetrieveParams.kt create mode 100644 openai-java-core/src/main/kotlin/com/openai/models/admin/organization/groups/users/UserRetrieveResponse.kt create mode 100644 openai-java-core/src/main/kotlin/com/openai/models/admin/organization/projects/dataretention/DataRetentionRetrieveParams.kt create mode 100644 openai-java-core/src/main/kotlin/com/openai/models/admin/organization/projects/dataretention/DataRetentionUpdateParams.kt create mode 100644 openai-java-core/src/main/kotlin/com/openai/models/admin/organization/projects/dataretention/ProjectDataRetention.kt create mode 100644 openai-java-core/src/main/kotlin/com/openai/models/admin/organization/projects/groups/GroupRetrieveParams.kt create mode 100644 openai-java-core/src/main/kotlin/com/openai/models/admin/organization/projects/groups/roles/RoleRetrieveParams.kt create mode 100644 openai-java-core/src/main/kotlin/com/openai/models/admin/organization/projects/groups/roles/RoleRetrieveResponse.kt create mode 100644 openai-java-core/src/main/kotlin/com/openai/models/admin/organization/projects/roles/RoleRetrieveParams.kt create mode 100644 openai-java-core/src/main/kotlin/com/openai/models/admin/organization/projects/serviceaccounts/ServiceAccountUpdateParams.kt create mode 100644 openai-java-core/src/main/kotlin/com/openai/models/admin/organization/projects/spendalerts/ProjectSpendAlert.kt create mode 100644 openai-java-core/src/main/kotlin/com/openai/models/admin/organization/projects/spendalerts/ProjectSpendAlertDeleted.kt create mode 100644 openai-java-core/src/main/kotlin/com/openai/models/admin/organization/projects/spendalerts/SpendAlertCreateParams.kt create mode 100644 openai-java-core/src/main/kotlin/com/openai/models/admin/organization/projects/spendalerts/SpendAlertDeleteParams.kt create mode 100644 openai-java-core/src/main/kotlin/com/openai/models/admin/organization/projects/spendalerts/SpendAlertListPage.kt create mode 100644 openai-java-core/src/main/kotlin/com/openai/models/admin/organization/projects/spendalerts/SpendAlertListPageAsync.kt create mode 100644 openai-java-core/src/main/kotlin/com/openai/models/admin/organization/projects/spendalerts/SpendAlertListPageResponse.kt create mode 100644 openai-java-core/src/main/kotlin/com/openai/models/admin/organization/projects/spendalerts/SpendAlertListParams.kt create mode 100644 openai-java-core/src/main/kotlin/com/openai/models/admin/organization/projects/spendalerts/SpendAlertUpdateParams.kt create mode 100644 openai-java-core/src/main/kotlin/com/openai/models/admin/organization/projects/users/roles/RoleRetrieveParams.kt create mode 100644 openai-java-core/src/main/kotlin/com/openai/models/admin/organization/projects/users/roles/RoleRetrieveResponse.kt create mode 100644 openai-java-core/src/main/kotlin/com/openai/models/admin/organization/roles/RoleRetrieveParams.kt create mode 100644 openai-java-core/src/main/kotlin/com/openai/models/admin/organization/spendalerts/OrganizationSpendAlert.kt create mode 100644 openai-java-core/src/main/kotlin/com/openai/models/admin/organization/spendalerts/OrganizationSpendAlertDeleted.kt create mode 100644 openai-java-core/src/main/kotlin/com/openai/models/admin/organization/spendalerts/SpendAlertCreateParams.kt create mode 100644 openai-java-core/src/main/kotlin/com/openai/models/admin/organization/spendalerts/SpendAlertDeleteParams.kt create mode 100644 openai-java-core/src/main/kotlin/com/openai/models/admin/organization/spendalerts/SpendAlertListPage.kt create mode 100644 openai-java-core/src/main/kotlin/com/openai/models/admin/organization/spendalerts/SpendAlertListPageAsync.kt create mode 100644 openai-java-core/src/main/kotlin/com/openai/models/admin/organization/spendalerts/SpendAlertListPageResponse.kt create mode 100644 openai-java-core/src/main/kotlin/com/openai/models/admin/organization/spendalerts/SpendAlertListParams.kt create mode 100644 openai-java-core/src/main/kotlin/com/openai/models/admin/organization/spendalerts/SpendAlertUpdateParams.kt create mode 100644 openai-java-core/src/main/kotlin/com/openai/models/admin/organization/users/roles/RoleRetrieveParams.kt create mode 100644 openai-java-core/src/main/kotlin/com/openai/models/admin/organization/users/roles/RoleRetrieveResponse.kt create mode 100644 openai-java-core/src/main/kotlin/com/openai/services/async/admin/organization/DataRetentionServiceAsync.kt create mode 100644 openai-java-core/src/main/kotlin/com/openai/services/async/admin/organization/DataRetentionServiceAsyncImpl.kt create mode 100644 openai-java-core/src/main/kotlin/com/openai/services/async/admin/organization/SpendAlertServiceAsync.kt create mode 100644 openai-java-core/src/main/kotlin/com/openai/services/async/admin/organization/SpendAlertServiceAsyncImpl.kt create mode 100644 openai-java-core/src/main/kotlin/com/openai/services/async/admin/organization/projects/DataRetentionServiceAsync.kt create mode 100644 openai-java-core/src/main/kotlin/com/openai/services/async/admin/organization/projects/DataRetentionServiceAsyncImpl.kt create mode 100644 openai-java-core/src/main/kotlin/com/openai/services/async/admin/organization/projects/SpendAlertServiceAsync.kt create mode 100644 openai-java-core/src/main/kotlin/com/openai/services/async/admin/organization/projects/SpendAlertServiceAsyncImpl.kt create mode 100644 openai-java-core/src/main/kotlin/com/openai/services/blocking/admin/organization/DataRetentionService.kt create mode 100644 openai-java-core/src/main/kotlin/com/openai/services/blocking/admin/organization/DataRetentionServiceImpl.kt create mode 100644 openai-java-core/src/main/kotlin/com/openai/services/blocking/admin/organization/SpendAlertService.kt create mode 100644 openai-java-core/src/main/kotlin/com/openai/services/blocking/admin/organization/SpendAlertServiceImpl.kt create mode 100644 openai-java-core/src/main/kotlin/com/openai/services/blocking/admin/organization/projects/DataRetentionService.kt create mode 100644 openai-java-core/src/main/kotlin/com/openai/services/blocking/admin/organization/projects/DataRetentionServiceImpl.kt create mode 100644 openai-java-core/src/main/kotlin/com/openai/services/blocking/admin/organization/projects/SpendAlertService.kt create mode 100644 openai-java-core/src/main/kotlin/com/openai/services/blocking/admin/organization/projects/SpendAlertServiceImpl.kt create mode 100644 openai-java-core/src/test/kotlin/com/openai/models/admin/organization/dataretention/DataRetentionRetrieveParamsTest.kt create mode 100644 openai-java-core/src/test/kotlin/com/openai/models/admin/organization/dataretention/DataRetentionUpdateParamsTest.kt create mode 100644 openai-java-core/src/test/kotlin/com/openai/models/admin/organization/dataretention/OrganizationDataRetentionTest.kt create mode 100644 openai-java-core/src/test/kotlin/com/openai/models/admin/organization/groups/GroupRetrieveParamsTest.kt create mode 100644 openai-java-core/src/test/kotlin/com/openai/models/admin/organization/groups/roles/RoleRetrieveParamsTest.kt create mode 100644 openai-java-core/src/test/kotlin/com/openai/models/admin/organization/groups/roles/RoleRetrieveResponseTest.kt create mode 100644 openai-java-core/src/test/kotlin/com/openai/models/admin/organization/groups/users/UserRetrieveParamsTest.kt create mode 100644 openai-java-core/src/test/kotlin/com/openai/models/admin/organization/groups/users/UserRetrieveResponseTest.kt create mode 100644 openai-java-core/src/test/kotlin/com/openai/models/admin/organization/projects/dataretention/DataRetentionRetrieveParamsTest.kt create mode 100644 openai-java-core/src/test/kotlin/com/openai/models/admin/organization/projects/dataretention/DataRetentionUpdateParamsTest.kt create mode 100644 openai-java-core/src/test/kotlin/com/openai/models/admin/organization/projects/dataretention/ProjectDataRetentionTest.kt create mode 100644 openai-java-core/src/test/kotlin/com/openai/models/admin/organization/projects/groups/GroupRetrieveParamsTest.kt create mode 100644 openai-java-core/src/test/kotlin/com/openai/models/admin/organization/projects/groups/roles/RoleRetrieveParamsTest.kt create mode 100644 openai-java-core/src/test/kotlin/com/openai/models/admin/organization/projects/groups/roles/RoleRetrieveResponseTest.kt create mode 100644 openai-java-core/src/test/kotlin/com/openai/models/admin/organization/projects/roles/RoleRetrieveParamsTest.kt create mode 100644 openai-java-core/src/test/kotlin/com/openai/models/admin/organization/projects/serviceaccounts/ServiceAccountUpdateParamsTest.kt create mode 100644 openai-java-core/src/test/kotlin/com/openai/models/admin/organization/projects/spendalerts/ProjectSpendAlertDeletedTest.kt create mode 100644 openai-java-core/src/test/kotlin/com/openai/models/admin/organization/projects/spendalerts/ProjectSpendAlertTest.kt create mode 100644 openai-java-core/src/test/kotlin/com/openai/models/admin/organization/projects/spendalerts/SpendAlertCreateParamsTest.kt create mode 100644 openai-java-core/src/test/kotlin/com/openai/models/admin/organization/projects/spendalerts/SpendAlertDeleteParamsTest.kt create mode 100644 openai-java-core/src/test/kotlin/com/openai/models/admin/organization/projects/spendalerts/SpendAlertListPageResponseTest.kt create mode 100644 openai-java-core/src/test/kotlin/com/openai/models/admin/organization/projects/spendalerts/SpendAlertListParamsTest.kt create mode 100644 openai-java-core/src/test/kotlin/com/openai/models/admin/organization/projects/spendalerts/SpendAlertUpdateParamsTest.kt create mode 100644 openai-java-core/src/test/kotlin/com/openai/models/admin/organization/projects/users/roles/RoleRetrieveParamsTest.kt create mode 100644 openai-java-core/src/test/kotlin/com/openai/models/admin/organization/projects/users/roles/RoleRetrieveResponseTest.kt create mode 100644 openai-java-core/src/test/kotlin/com/openai/models/admin/organization/roles/RoleRetrieveParamsTest.kt create mode 100644 openai-java-core/src/test/kotlin/com/openai/models/admin/organization/spendalerts/OrganizationSpendAlertDeletedTest.kt create mode 100644 openai-java-core/src/test/kotlin/com/openai/models/admin/organization/spendalerts/OrganizationSpendAlertTest.kt create mode 100644 openai-java-core/src/test/kotlin/com/openai/models/admin/organization/spendalerts/SpendAlertCreateParamsTest.kt create mode 100644 openai-java-core/src/test/kotlin/com/openai/models/admin/organization/spendalerts/SpendAlertDeleteParamsTest.kt create mode 100644 openai-java-core/src/test/kotlin/com/openai/models/admin/organization/spendalerts/SpendAlertListPageResponseTest.kt create mode 100644 openai-java-core/src/test/kotlin/com/openai/models/admin/organization/spendalerts/SpendAlertListParamsTest.kt create mode 100644 openai-java-core/src/test/kotlin/com/openai/models/admin/organization/spendalerts/SpendAlertUpdateParamsTest.kt create mode 100644 openai-java-core/src/test/kotlin/com/openai/models/admin/organization/users/roles/RoleRetrieveParamsTest.kt create mode 100644 openai-java-core/src/test/kotlin/com/openai/models/admin/organization/users/roles/RoleRetrieveResponseTest.kt create mode 100644 openai-java-core/src/test/kotlin/com/openai/services/async/admin/organization/DataRetentionServiceAsyncTest.kt create mode 100644 openai-java-core/src/test/kotlin/com/openai/services/async/admin/organization/SpendAlertServiceAsyncTest.kt create mode 100644 openai-java-core/src/test/kotlin/com/openai/services/async/admin/organization/projects/DataRetentionServiceAsyncTest.kt create mode 100644 openai-java-core/src/test/kotlin/com/openai/services/async/admin/organization/projects/SpendAlertServiceAsyncTest.kt create mode 100644 openai-java-core/src/test/kotlin/com/openai/services/blocking/admin/organization/DataRetentionServiceTest.kt create mode 100644 openai-java-core/src/test/kotlin/com/openai/services/blocking/admin/organization/SpendAlertServiceTest.kt create mode 100644 openai-java-core/src/test/kotlin/com/openai/services/blocking/admin/organization/projects/DataRetentionServiceTest.kt create mode 100644 openai-java-core/src/test/kotlin/com/openai/services/blocking/admin/organization/projects/SpendAlertServiceTest.kt diff --git a/.stats.yml b/.stats.yml index efb841c22..e5ac7b3ad 100644 --- a/.stats.yml +++ b/.stats.yml @@ -1,4 +1,4 @@ -configured_endpoints: 239 -openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/openai/openai-66f110677cd924205b0a4e2a1f567c8b56349ee9658bd0ce86561a413a2aabfe.yml -openapi_spec_hash: ab8f320a7a6b2d30d5f1665b8a8bf84e -config_hash: 425042cc0e99cf31866f6c98fef2be27 +configured_endpoints: 261 +openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/openai/openai-afacc4343d0efc074c8c5667eb83570642c8b9acaa7792ca8e075c6d18ef9f3a.yml +openapi_spec_hash: a62a557c61532681963fd21e748b0eb4 +config_hash: bb69d8d0771dbac4a84fc6dca11e3ceb diff --git a/openai-java-core/src/main/kotlin/com/openai/models/admin/organization/dataretention/DataRetentionRetrieveParams.kt b/openai-java-core/src/main/kotlin/com/openai/models/admin/organization/dataretention/DataRetentionRetrieveParams.kt new file mode 100644 index 000000000..2633a9d80 --- /dev/null +++ b/openai-java-core/src/main/kotlin/com/openai/models/admin/organization/dataretention/DataRetentionRetrieveParams.kt @@ -0,0 +1,172 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.models.admin.organization.dataretention + +import com.openai.core.Params +import com.openai.core.http.Headers +import com.openai.core.http.QueryParams +import java.util.Objects + +/** Retrieves organization data retention controls. */ +class DataRetentionRetrieveParams +private constructor( + private val additionalHeaders: Headers, + private val additionalQueryParams: QueryParams, +) : Params { + + /** Additional headers to send with the request. */ + fun _additionalHeaders(): Headers = additionalHeaders + + /** Additional query param to send with the request. */ + fun _additionalQueryParams(): QueryParams = additionalQueryParams + + fun toBuilder() = Builder().from(this) + + companion object { + + @JvmStatic fun none(): DataRetentionRetrieveParams = builder().build() + + /** + * Returns a mutable builder for constructing an instance of [DataRetentionRetrieveParams]. + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [DataRetentionRetrieveParams]. */ + class Builder internal constructor() { + + private var additionalHeaders: Headers.Builder = Headers.builder() + private var additionalQueryParams: QueryParams.Builder = QueryParams.builder() + + @JvmSynthetic + internal fun from(dataRetentionRetrieveParams: DataRetentionRetrieveParams) = apply { + additionalHeaders = dataRetentionRetrieveParams.additionalHeaders.toBuilder() + additionalQueryParams = dataRetentionRetrieveParams.additionalQueryParams.toBuilder() + } + + 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 [DataRetentionRetrieveParams]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): DataRetentionRetrieveParams = + DataRetentionRetrieveParams(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 + } + + return other is DataRetentionRetrieveParams && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams + } + + override fun hashCode(): Int = Objects.hash(additionalHeaders, additionalQueryParams) + + override fun toString() = + "DataRetentionRetrieveParams{additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" +} diff --git a/openai-java-core/src/main/kotlin/com/openai/models/admin/organization/dataretention/DataRetentionUpdateParams.kt b/openai-java-core/src/main/kotlin/com/openai/models/admin/organization/dataretention/DataRetentionUpdateParams.kt new file mode 100644 index 000000000..6da48966f --- /dev/null +++ b/openai-java-core/src/main/kotlin/com/openai/models/admin/organization/dataretention/DataRetentionUpdateParams.kt @@ -0,0 +1,596 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.models.admin.organization.dataretention + +import com.fasterxml.jackson.annotation.JsonAnyGetter +import com.fasterxml.jackson.annotation.JsonAnySetter +import com.fasterxml.jackson.annotation.JsonCreator +import com.fasterxml.jackson.annotation.JsonProperty +import com.openai.core.Enum +import com.openai.core.ExcludeMissing +import com.openai.core.JsonField +import com.openai.core.JsonMissing +import com.openai.core.JsonValue +import com.openai.core.Params +import com.openai.core.checkRequired +import com.openai.core.http.Headers +import com.openai.core.http.QueryParams +import com.openai.errors.OpenAIInvalidDataException +import java.util.Collections +import java.util.Objects +import kotlin.jvm.optionals.getOrNull + +/** Updates organization data retention controls. */ +class DataRetentionUpdateParams +private constructor( + private val body: Body, + private val additionalHeaders: Headers, + private val additionalQueryParams: QueryParams, +) : Params { + + /** + * The desired organization data retention type. + * + * @throws OpenAIInvalidDataException 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 retentionType(): RetentionType = body.retentionType() + + /** + * Returns the raw JSON value of [retentionType]. + * + * Unlike [retentionType], this method doesn't throw if the JSON field has an unexpected type. + */ + fun _retentionType(): JsonField = body._retentionType() + + fun _additionalBodyProperties(): Map = body._additionalProperties() + + /** Additional headers to send with the request. */ + fun _additionalHeaders(): Headers = additionalHeaders + + /** Additional query param to send with the request. */ + fun _additionalQueryParams(): QueryParams = additionalQueryParams + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of [DataRetentionUpdateParams]. + * + * The following fields are required: + * ```java + * .retentionType() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [DataRetentionUpdateParams]. */ + 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(dataRetentionUpdateParams: DataRetentionUpdateParams) = apply { + body = dataRetentionUpdateParams.body.toBuilder() + additionalHeaders = dataRetentionUpdateParams.additionalHeaders.toBuilder() + additionalQueryParams = dataRetentionUpdateParams.additionalQueryParams.toBuilder() + } + + /** + * Sets the entire request body. + * + * This is generally only useful if you are already constructing the body separately. + * Otherwise, it's more convenient to use the top-level setters instead: + * - [retentionType] + */ + fun body(body: Body) = apply { this.body = body.toBuilder() } + + /** The desired organization data retention type. */ + fun retentionType(retentionType: RetentionType) = apply { + body.retentionType(retentionType) + } + + /** + * Sets [Builder.retentionType] to an arbitrary JSON value. + * + * You should usually call [Builder.retentionType] with a well-typed [RetentionType] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun retentionType(retentionType: JsonField) = apply { + body.retentionType(retentionType) + } + + 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 [DataRetentionUpdateParams]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .retentionType() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): DataRetentionUpdateParams = + DataRetentionUpdateParams( + body.build(), + additionalHeaders.build(), + additionalQueryParams.build(), + ) + } + + fun _body(): Body = body + + override fun _headers(): Headers = additionalHeaders + + override fun _queryParams(): QueryParams = additionalQueryParams + + /** Parameters for updating organization data retention controls. */ + class Body + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val retentionType: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("retention_type") + @ExcludeMissing + retentionType: JsonField = JsonMissing.of() + ) : this(retentionType, mutableMapOf()) + + /** + * The desired organization data retention type. + * + * @throws OpenAIInvalidDataException 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 retentionType(): RetentionType = retentionType.getRequired("retention_type") + + /** + * Returns the raw JSON value of [retentionType]. + * + * Unlike [retentionType], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("retention_type") + @ExcludeMissing + fun _retentionType(): JsonField = retentionType + + @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 + * .retentionType() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [Body]. */ + class Builder internal constructor() { + + private var retentionType: JsonField? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(body: Body) = apply { + retentionType = body.retentionType + additionalProperties = body.additionalProperties.toMutableMap() + } + + /** The desired organization data retention type. */ + fun retentionType(retentionType: RetentionType) = + retentionType(JsonField.of(retentionType)) + + /** + * Sets [Builder.retentionType] to an arbitrary JSON value. + * + * You should usually call [Builder.retentionType] with a well-typed [RetentionType] + * value instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun retentionType(retentionType: JsonField) = apply { + this.retentionType = retentionType + } + + 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 + * .retentionType() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): Body = + Body( + checkRequired("retentionType", retentionType), + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing fields. + * + * @throws OpenAIInvalidDataException if any value type in this object doesn't match its + * expected type. + */ + fun validate(): Body = apply { + if (validated) { + return@apply + } + + retentionType().validate() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OpenAIInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = (retentionType.asKnown().getOrNull()?.validity() ?: 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Body && + retentionType == other.retentionType && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(retentionType, additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Body{retentionType=$retentionType, additionalProperties=$additionalProperties}" + } + + /** The desired organization data retention type. */ + class RetentionType @JsonCreator private constructor(private val value: JsonField) : + Enum { + + /** + * Returns this class instance's raw value. + * + * This is usually only useful if this instance was deserialized from data that doesn't + * match any known member, and you want to know that value. For example, if the SDK is on an + * older version than the API, then the API may respond with new members that the SDK is + * unaware of. + */ + @com.fasterxml.jackson.annotation.JsonValue fun _value(): JsonField = value + + companion object { + + @JvmField val ZERO_DATA_RETENTION = of("zero_data_retention") + + @JvmField val MODIFIED_ABUSE_MONITORING = of("modified_abuse_monitoring") + + @JvmField val ENHANCED_ZERO_DATA_RETENTION = of("enhanced_zero_data_retention") + + @JvmField + val ENHANCED_MODIFIED_ABUSE_MONITORING = of("enhanced_modified_abuse_monitoring") + + @JvmStatic fun of(value: String) = RetentionType(JsonField.of(value)) + } + + /** An enum containing [RetentionType]'s known values. */ + enum class Known { + ZERO_DATA_RETENTION, + MODIFIED_ABUSE_MONITORING, + ENHANCED_ZERO_DATA_RETENTION, + ENHANCED_MODIFIED_ABUSE_MONITORING, + } + + /** + * An enum containing [RetentionType]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [RetentionType] can contain an unknown value in a couple of cases: + * - It was deserialized from data that doesn't match any known member. For example, if the + * SDK is on an older version than the API, then the API may respond with new members that + * the SDK is unaware of. + * - It was constructed with an arbitrary value using the [of] method. + */ + enum class Value { + ZERO_DATA_RETENTION, + MODIFIED_ABUSE_MONITORING, + ENHANCED_ZERO_DATA_RETENTION, + ENHANCED_MODIFIED_ABUSE_MONITORING, + /** + * An enum member indicating that [RetentionType] was instantiated with an unknown + * value. + */ + _UNKNOWN, + } + + /** + * Returns an enum member corresponding to this class instance's value, or [Value._UNKNOWN] + * if the class was instantiated with an unknown value. + * + * Use the [known] method instead if you're certain the value is always known or if you want + * to throw for the unknown case. + */ + fun value(): Value = + when (this) { + ZERO_DATA_RETENTION -> Value.ZERO_DATA_RETENTION + MODIFIED_ABUSE_MONITORING -> Value.MODIFIED_ABUSE_MONITORING + ENHANCED_ZERO_DATA_RETENTION -> Value.ENHANCED_ZERO_DATA_RETENTION + ENHANCED_MODIFIED_ABUSE_MONITORING -> Value.ENHANCED_MODIFIED_ABUSE_MONITORING + else -> Value._UNKNOWN + } + + /** + * Returns an enum member corresponding to this class instance's value. + * + * Use the [value] method instead if you're uncertain the value is always known and don't + * want to throw for the unknown case. + * + * @throws OpenAIInvalidDataException if this class instance's value is a not a known + * member. + */ + fun known(): Known = + when (this) { + ZERO_DATA_RETENTION -> Known.ZERO_DATA_RETENTION + MODIFIED_ABUSE_MONITORING -> Known.MODIFIED_ABUSE_MONITORING + ENHANCED_ZERO_DATA_RETENTION -> Known.ENHANCED_ZERO_DATA_RETENTION + ENHANCED_MODIFIED_ABUSE_MONITORING -> Known.ENHANCED_MODIFIED_ABUSE_MONITORING + else -> throw OpenAIInvalidDataException("Unknown RetentionType: $value") + } + + /** + * Returns this class instance's primitive wire representation. + * + * This differs from the [toString] method because that method is primarily for debugging + * and generally doesn't throw. + * + * @throws OpenAIInvalidDataException if this class instance's value does not have the + * expected primitive type. + */ + fun asString(): String = + _value().asString().orElseThrow { OpenAIInvalidDataException("Value is not a String") } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing fields. + * + * @throws OpenAIInvalidDataException if any value type in this object doesn't match its + * expected type. + */ + fun validate(): RetentionType = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OpenAIInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is RetentionType && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is DataRetentionUpdateParams && + body == other.body && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams + } + + override fun hashCode(): Int = Objects.hash(body, additionalHeaders, additionalQueryParams) + + override fun toString() = + "DataRetentionUpdateParams{body=$body, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" +} diff --git a/openai-java-core/src/main/kotlin/com/openai/models/admin/organization/dataretention/OrganizationDataRetention.kt b/openai-java-core/src/main/kotlin/com/openai/models/admin/organization/dataretention/OrganizationDataRetention.kt new file mode 100644 index 000000000..e9da1e45c --- /dev/null +++ b/openai-java-core/src/main/kotlin/com/openai/models/admin/organization/dataretention/OrganizationDataRetention.kt @@ -0,0 +1,373 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.models.admin.organization.dataretention + +import com.fasterxml.jackson.annotation.JsonAnyGetter +import com.fasterxml.jackson.annotation.JsonAnySetter +import com.fasterxml.jackson.annotation.JsonCreator +import com.fasterxml.jackson.annotation.JsonProperty +import com.openai.core.Enum +import com.openai.core.ExcludeMissing +import com.openai.core.JsonField +import com.openai.core.JsonMissing +import com.openai.core.JsonValue +import com.openai.core.checkRequired +import com.openai.errors.OpenAIInvalidDataException +import java.util.Collections +import java.util.Objects +import kotlin.jvm.optionals.getOrNull + +/** Represents the organization's data retention control setting. */ +class OrganizationDataRetention +@JsonCreator(mode = JsonCreator.Mode.DISABLED) +private constructor( + private val object_: JsonValue, + private val type: JsonField, + private val additionalProperties: MutableMap, +) { + + @JsonCreator + private constructor( + @JsonProperty("object") @ExcludeMissing object_: JsonValue = JsonMissing.of(), + @JsonProperty("type") @ExcludeMissing type: JsonField = JsonMissing.of(), + ) : this(object_, type, mutableMapOf()) + + /** + * The object type, which is always `organization.data_retention`. + * + * Expected to always return the following: + * ```java + * JsonValue.from("organization.data_retention") + * ``` + * + * However, this method can be useful for debugging and logging (e.g. if the server responded + * with an unexpected value). + */ + @JsonProperty("object") @ExcludeMissing fun _object_(): JsonValue = object_ + + /** + * The configured organization data retention type. + * + * @throws OpenAIInvalidDataException 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 type(): Type = type.getRequired("type") + + /** + * 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 = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of [OrganizationDataRetention]. + * + * The following fields are required: + * ```java + * .type() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [OrganizationDataRetention]. */ + class Builder internal constructor() { + + private var object_: JsonValue = JsonValue.from("organization.data_retention") + private var type: JsonField? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(organizationDataRetention: OrganizationDataRetention) = apply { + object_ = organizationDataRetention.object_ + type = organizationDataRetention.type + additionalProperties = organizationDataRetention.additionalProperties.toMutableMap() + } + + /** + * Sets the field to an arbitrary JSON value. + * + * It is usually unnecessary to call this method because the field defaults to the + * following: + * ```java + * JsonValue.from("organization.data_retention") + * ``` + * + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun object_(object_: JsonValue) = apply { this.object_ = object_ } + + /** The configured organization data retention type. */ + fun type(type: Type) = type(JsonField.of(type)) + + /** + * Sets [Builder.type] to an arbitrary JSON value. + * + * You should usually call [Builder.type] with a well-typed [Type] 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 [OrganizationDataRetention]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .type() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): OrganizationDataRetention = + OrganizationDataRetention( + object_, + checkRequired("type", type), + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected types recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing fields. + * + * @throws OpenAIInvalidDataException if any value type in this object doesn't match its + * expected type. + */ + fun validate(): OrganizationDataRetention = apply { + if (validated) { + return@apply + } + + _object_().let { + if (it != JsonValue.from("organization.data_retention")) { + throw OpenAIInvalidDataException("'object_' is invalid, received $it") + } + } + type().validate() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OpenAIInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + object_.let { if (it == JsonValue.from("organization.data_retention")) 1 else 0 } + + (type.asKnown().getOrNull()?.validity() ?: 0) + + /** The configured organization data retention type. */ + class Type @JsonCreator private constructor(private val value: JsonField) : Enum { + + /** + * Returns this class instance's raw value. + * + * This is usually only useful if this instance was deserialized from data that doesn't + * match any known member, and you want to know that value. For example, if the SDK is on an + * older version than the API, then the API may respond with new members that the SDK is + * unaware of. + */ + @com.fasterxml.jackson.annotation.JsonValue fun _value(): JsonField = value + + companion object { + + @JvmField val ZERO_DATA_RETENTION = of("zero_data_retention") + + @JvmField val MODIFIED_ABUSE_MONITORING = of("modified_abuse_monitoring") + + @JvmField val ENHANCED_ZERO_DATA_RETENTION = of("enhanced_zero_data_retention") + + @JvmField + val ENHANCED_MODIFIED_ABUSE_MONITORING = of("enhanced_modified_abuse_monitoring") + + @JvmStatic fun of(value: String) = Type(JsonField.of(value)) + } + + /** An enum containing [Type]'s known values. */ + enum class Known { + ZERO_DATA_RETENTION, + MODIFIED_ABUSE_MONITORING, + ENHANCED_ZERO_DATA_RETENTION, + ENHANCED_MODIFIED_ABUSE_MONITORING, + } + + /** + * An enum containing [Type]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [Type] can contain an unknown value in a couple of cases: + * - It was deserialized from data that doesn't match any known member. For example, if the + * SDK is on an older version than the API, then the API may respond with new members that + * the SDK is unaware of. + * - It was constructed with an arbitrary value using the [of] method. + */ + enum class Value { + ZERO_DATA_RETENTION, + MODIFIED_ABUSE_MONITORING, + ENHANCED_ZERO_DATA_RETENTION, + ENHANCED_MODIFIED_ABUSE_MONITORING, + /** An enum member indicating that [Type] was instantiated with an unknown value. */ + _UNKNOWN, + } + + /** + * Returns an enum member corresponding to this class instance's value, or [Value._UNKNOWN] + * if the class was instantiated with an unknown value. + * + * Use the [known] method instead if you're certain the value is always known or if you want + * to throw for the unknown case. + */ + fun value(): Value = + when (this) { + ZERO_DATA_RETENTION -> Value.ZERO_DATA_RETENTION + MODIFIED_ABUSE_MONITORING -> Value.MODIFIED_ABUSE_MONITORING + ENHANCED_ZERO_DATA_RETENTION -> Value.ENHANCED_ZERO_DATA_RETENTION + ENHANCED_MODIFIED_ABUSE_MONITORING -> Value.ENHANCED_MODIFIED_ABUSE_MONITORING + else -> Value._UNKNOWN + } + + /** + * Returns an enum member corresponding to this class instance's value. + * + * Use the [value] method instead if you're uncertain the value is always known and don't + * want to throw for the unknown case. + * + * @throws OpenAIInvalidDataException if this class instance's value is a not a known + * member. + */ + fun known(): Known = + when (this) { + ZERO_DATA_RETENTION -> Known.ZERO_DATA_RETENTION + MODIFIED_ABUSE_MONITORING -> Known.MODIFIED_ABUSE_MONITORING + ENHANCED_ZERO_DATA_RETENTION -> Known.ENHANCED_ZERO_DATA_RETENTION + ENHANCED_MODIFIED_ABUSE_MONITORING -> Known.ENHANCED_MODIFIED_ABUSE_MONITORING + else -> throw OpenAIInvalidDataException("Unknown Type: $value") + } + + /** + * Returns this class instance's primitive wire representation. + * + * This differs from the [toString] method because that method is primarily for debugging + * and generally doesn't throw. + * + * @throws OpenAIInvalidDataException if this class instance's value does not have the + * expected primitive type. + */ + fun asString(): String = + _value().asString().orElseThrow { OpenAIInvalidDataException("Value is not a String") } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing fields. + * + * @throws OpenAIInvalidDataException if any value type in this object doesn't match its + * expected type. + */ + fun validate(): Type = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OpenAIInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Type && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is OrganizationDataRetention && + object_ == other.object_ && + type == other.type && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(object_, type, additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "OrganizationDataRetention{object_=$object_, type=$type, additionalProperties=$additionalProperties}" +} diff --git a/openai-java-core/src/main/kotlin/com/openai/models/admin/organization/groups/Group.kt b/openai-java-core/src/main/kotlin/com/openai/models/admin/organization/groups/Group.kt index 5f5422d00..6104f67ca 100644 --- a/openai-java-core/src/main/kotlin/com/openai/models/admin/organization/groups/Group.kt +++ b/openai-java-core/src/main/kotlin/com/openai/models/admin/organization/groups/Group.kt @@ -6,6 +6,7 @@ import com.fasterxml.jackson.annotation.JsonAnyGetter import com.fasterxml.jackson.annotation.JsonAnySetter import com.fasterxml.jackson.annotation.JsonCreator import com.fasterxml.jackson.annotation.JsonProperty +import com.openai.core.Enum import com.openai.core.ExcludeMissing import com.openai.core.JsonField import com.openai.core.JsonMissing @@ -14,6 +15,7 @@ import com.openai.core.checkRequired import com.openai.errors.OpenAIInvalidDataException import java.util.Collections import java.util.Objects +import kotlin.jvm.optionals.getOrNull /** Details about an organization group. */ class Group @@ -21,7 +23,7 @@ class Group private constructor( private val id: JsonField, private val createdAt: JsonField, - private val groupType: JsonField, + private val groupType: JsonField, private val isScimManaged: JsonField, private val name: JsonField, private val additionalProperties: MutableMap, @@ -31,7 +33,9 @@ private constructor( private constructor( @JsonProperty("id") @ExcludeMissing id: JsonField = JsonMissing.of(), @JsonProperty("created_at") @ExcludeMissing createdAt: JsonField = JsonMissing.of(), - @JsonProperty("group_type") @ExcludeMissing groupType: JsonField = JsonMissing.of(), + @JsonProperty("group_type") + @ExcludeMissing + groupType: JsonField = JsonMissing.of(), @JsonProperty("is_scim_managed") @ExcludeMissing isScimManaged: JsonField = JsonMissing.of(), @@ -60,7 +64,7 @@ private constructor( * @throws OpenAIInvalidDataException 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 groupType(): String = groupType.getRequired("group_type") + fun groupType(): GroupType = groupType.getRequired("group_type") /** * Whether the group is managed through SCIM and controlled by your identity provider. @@ -97,7 +101,7 @@ private constructor( * * Unlike [groupType], this method doesn't throw if the JSON field has an unexpected type. */ - @JsonProperty("group_type") @ExcludeMissing fun _groupType(): JsonField = groupType + @JsonProperty("group_type") @ExcludeMissing fun _groupType(): JsonField = groupType /** * Returns the raw JSON value of [isScimManaged]. @@ -149,7 +153,7 @@ private constructor( private var id: JsonField? = null private var createdAt: JsonField? = null - private var groupType: JsonField? = null + private var groupType: JsonField? = null private var isScimManaged: JsonField? = null private var name: JsonField? = null private var additionalProperties: MutableMap = mutableMapOf() @@ -187,16 +191,16 @@ private constructor( fun createdAt(createdAt: JsonField) = apply { this.createdAt = createdAt } /** The type of the group. */ - fun groupType(groupType: String) = groupType(JsonField.of(groupType)) + fun groupType(groupType: GroupType) = groupType(JsonField.of(groupType)) /** * Sets [Builder.groupType] to an arbitrary JSON value. * - * You should usually call [Builder.groupType] with a well-typed [String] value instead. + * You should usually call [Builder.groupType] with a well-typed [GroupType] value instead. * This method is primarily for setting the field to an undocumented or not yet supported * value. */ - fun groupType(groupType: JsonField) = apply { this.groupType = groupType } + fun groupType(groupType: JsonField) = apply { this.groupType = groupType } /** Whether the group is managed through SCIM and controlled by your identity provider. */ fun isScimManaged(isScimManaged: Boolean) = isScimManaged(JsonField.of(isScimManaged)) @@ -286,7 +290,7 @@ private constructor( id() createdAt() - groupType() + groupType().validate() isScimManaged() name() validated = true @@ -309,10 +313,147 @@ private constructor( internal fun validity(): Int = (if (id.asKnown().isPresent) 1 else 0) + (if (createdAt.asKnown().isPresent) 1 else 0) + - (if (groupType.asKnown().isPresent) 1 else 0) + + (groupType.asKnown().getOrNull()?.validity() ?: 0) + (if (isScimManaged.asKnown().isPresent) 1 else 0) + (if (name.asKnown().isPresent) 1 else 0) + /** The type of the group. */ + class GroupType @JsonCreator private constructor(private val value: JsonField) : Enum { + + /** + * Returns this class instance's raw value. + * + * This is usually only useful if this instance was deserialized from data that doesn't + * match any known member, and you want to know that value. For example, if the SDK is on an + * older version than the API, then the API may respond with new members that the SDK is + * unaware of. + */ + @com.fasterxml.jackson.annotation.JsonValue fun _value(): JsonField = value + + companion object { + + @JvmField val GROUP = of("group") + + @JvmField val TENANT_GROUP = of("tenant_group") + + @JvmStatic fun of(value: String) = GroupType(JsonField.of(value)) + } + + /** An enum containing [GroupType]'s known values. */ + enum class Known { + GROUP, + TENANT_GROUP, + } + + /** + * An enum containing [GroupType]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [GroupType] can contain an unknown value in a couple of cases: + * - It was deserialized from data that doesn't match any known member. For example, if the + * SDK is on an older version than the API, then the API may respond with new members that + * the SDK is unaware of. + * - It was constructed with an arbitrary value using the [of] method. + */ + enum class Value { + GROUP, + TENANT_GROUP, + /** + * An enum member indicating that [GroupType] was instantiated with an unknown value. + */ + _UNKNOWN, + } + + /** + * Returns an enum member corresponding to this class instance's value, or [Value._UNKNOWN] + * if the class was instantiated with an unknown value. + * + * Use the [known] method instead if you're certain the value is always known or if you want + * to throw for the unknown case. + */ + fun value(): Value = + when (this) { + GROUP -> Value.GROUP + TENANT_GROUP -> Value.TENANT_GROUP + else -> Value._UNKNOWN + } + + /** + * Returns an enum member corresponding to this class instance's value. + * + * Use the [value] method instead if you're uncertain the value is always known and don't + * want to throw for the unknown case. + * + * @throws OpenAIInvalidDataException if this class instance's value is a not a known + * member. + */ + fun known(): Known = + when (this) { + GROUP -> Known.GROUP + TENANT_GROUP -> Known.TENANT_GROUP + else -> throw OpenAIInvalidDataException("Unknown GroupType: $value") + } + + /** + * Returns this class instance's primitive wire representation. + * + * This differs from the [toString] method because that method is primarily for debugging + * and generally doesn't throw. + * + * @throws OpenAIInvalidDataException if this class instance's value does not have the + * expected primitive type. + */ + fun asString(): String = + _value().asString().orElseThrow { OpenAIInvalidDataException("Value is not a String") } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing fields. + * + * @throws OpenAIInvalidDataException if any value type in this object doesn't match its + * expected type. + */ + fun validate(): GroupType = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OpenAIInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is GroupType && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + override fun equals(other: Any?): Boolean { if (this === other) { return true diff --git a/openai-java-core/src/main/kotlin/com/openai/models/admin/organization/groups/GroupRetrieveParams.kt b/openai-java-core/src/main/kotlin/com/openai/models/admin/organization/groups/GroupRetrieveParams.kt new file mode 100644 index 000000000..551772730 --- /dev/null +++ b/openai-java-core/src/main/kotlin/com/openai/models/admin/organization/groups/GroupRetrieveParams.kt @@ -0,0 +1,189 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.models.admin.organization.groups + +import com.openai.core.Params +import com.openai.core.http.Headers +import com.openai.core.http.QueryParams +import java.util.Objects +import java.util.Optional +import kotlin.jvm.optionals.getOrNull + +/** Retrieves a group. */ +class GroupRetrieveParams +private constructor( + private val groupId: String?, + private val additionalHeaders: Headers, + private val additionalQueryParams: QueryParams, +) : Params { + + fun groupId(): Optional = Optional.ofNullable(groupId) + + /** Additional headers to send with the request. */ + fun _additionalHeaders(): Headers = additionalHeaders + + /** Additional query param to send with the request. */ + fun _additionalQueryParams(): QueryParams = additionalQueryParams + + fun toBuilder() = Builder().from(this) + + companion object { + + @JvmStatic fun none(): GroupRetrieveParams = builder().build() + + /** Returns a mutable builder for constructing an instance of [GroupRetrieveParams]. */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [GroupRetrieveParams]. */ + class Builder internal constructor() { + + private var groupId: String? = null + private var additionalHeaders: Headers.Builder = Headers.builder() + private var additionalQueryParams: QueryParams.Builder = QueryParams.builder() + + @JvmSynthetic + internal fun from(groupRetrieveParams: GroupRetrieveParams) = apply { + groupId = groupRetrieveParams.groupId + additionalHeaders = groupRetrieveParams.additionalHeaders.toBuilder() + additionalQueryParams = groupRetrieveParams.additionalQueryParams.toBuilder() + } + + fun groupId(groupId: String?) = apply { this.groupId = groupId } + + /** 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) + } + + 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 [GroupRetrieveParams]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): GroupRetrieveParams = + GroupRetrieveParams(groupId, additionalHeaders.build(), additionalQueryParams.build()) + } + + 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 + } + + return other is GroupRetrieveParams && + groupId == other.groupId && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams + } + + override fun hashCode(): Int = Objects.hash(groupId, additionalHeaders, additionalQueryParams) + + override fun toString() = + "GroupRetrieveParams{groupId=$groupId, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" +} diff --git a/openai-java-core/src/main/kotlin/com/openai/models/admin/organization/groups/roles/RoleListResponse.kt b/openai-java-core/src/main/kotlin/com/openai/models/admin/organization/groups/roles/RoleListResponse.kt index aabc3da55..abe7437ed 100644 --- a/openai-java-core/src/main/kotlin/com/openai/models/admin/organization/groups/roles/RoleListResponse.kt +++ b/openai-java-core/src/main/kotlin/com/openai/models/admin/organization/groups/roles/RoleListResponse.kt @@ -24,6 +24,7 @@ class RoleListResponse @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val id: JsonField, + private val assignmentSources: JsonField>, private val createdAt: JsonField, private val createdBy: JsonField, private val createdByUserObj: JsonField, @@ -40,6 +41,9 @@ private constructor( @JsonCreator private constructor( @JsonProperty("id") @ExcludeMissing id: JsonField = JsonMissing.of(), + @JsonProperty("assignment_sources") + @ExcludeMissing + assignmentSources: JsonField> = JsonMissing.of(), @JsonProperty("created_at") @ExcludeMissing createdAt: JsonField = JsonMissing.of(), @JsonProperty("created_by") @ExcludeMissing createdBy: JsonField = JsonMissing.of(), @JsonProperty("created_by_user_obj") @@ -62,6 +66,7 @@ private constructor( @JsonProperty("updated_at") @ExcludeMissing updatedAt: JsonField = JsonMissing.of(), ) : this( id, + assignmentSources, createdAt, createdBy, createdByUserObj, @@ -83,6 +88,15 @@ private constructor( */ fun id(): String = id.getRequired("id") + /** + * Principals from which the role assignment is inherited, when available. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun assignmentSources(): Optional> = + assignmentSources.getOptional("assignment_sources") + /** * When the role was created. * @@ -171,6 +185,16 @@ private constructor( */ @JsonProperty("id") @ExcludeMissing fun _id(): JsonField = id + /** + * Returns the raw JSON value of [assignmentSources]. + * + * Unlike [assignmentSources], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("assignment_sources") + @ExcludeMissing + fun _assignmentSources(): JsonField> = assignmentSources + /** * Returns the raw JSON value of [createdAt]. * @@ -270,6 +294,7 @@ private constructor( * The following fields are required: * ```java * .id() + * .assignmentSources() * .createdAt() * .createdBy() * .createdByUserObj() @@ -289,6 +314,7 @@ private constructor( class Builder internal constructor() { private var id: JsonField? = null + private var assignmentSources: JsonField>? = null private var createdAt: JsonField? = null private var createdBy: JsonField? = null private var createdByUserObj: JsonField? = null @@ -304,6 +330,7 @@ private constructor( @JvmSynthetic internal fun from(roleListResponse: RoleListResponse) = apply { id = roleListResponse.id + assignmentSources = roleListResponse.assignmentSources.map { it.toMutableList() } createdAt = roleListResponse.createdAt createdBy = roleListResponse.createdBy createdByUserObj = roleListResponse.createdByUserObj @@ -328,6 +355,37 @@ private constructor( */ fun id(id: JsonField) = apply { this.id = id } + /** Principals from which the role assignment is inherited, when available. */ + fun assignmentSources(assignmentSources: List?) = + assignmentSources(JsonField.ofNullable(assignmentSources)) + + /** Alias for calling [Builder.assignmentSources] with `assignmentSources.orElse(null)`. */ + fun assignmentSources(assignmentSources: Optional>) = + assignmentSources(assignmentSources.getOrNull()) + + /** + * Sets [Builder.assignmentSources] to an arbitrary JSON value. + * + * You should usually call [Builder.assignmentSources] with a well-typed + * `List` value instead. This method is primarily for setting the field to + * an undocumented or not yet supported value. + */ + fun assignmentSources(assignmentSources: JsonField>) = apply { + this.assignmentSources = assignmentSources.map { it.toMutableList() } + } + + /** + * Adds a single [AssignmentSource] to [assignmentSources]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addAssignmentSource(assignmentSource: AssignmentSource) = apply { + assignmentSources = + (assignmentSources ?: JsonField.of(mutableListOf())).also { + checkKnown("assignmentSources", it).add(assignmentSource) + } + } + /** When the role was created. */ fun createdAt(createdAt: Long?) = createdAt(JsonField.ofNullable(createdAt)) @@ -526,6 +584,7 @@ private constructor( * The following fields are required: * ```java * .id() + * .assignmentSources() * .createdAt() * .createdBy() * .createdByUserObj() @@ -543,6 +602,7 @@ private constructor( fun build(): RoleListResponse = RoleListResponse( checkRequired("id", id), + checkRequired("assignmentSources", assignmentSources).map { it.toImmutable() }, checkRequired("createdAt", createdAt), checkRequired("createdBy", createdBy), checkRequired("createdByUserObj", createdByUserObj), @@ -573,6 +633,7 @@ private constructor( } id() + assignmentSources().ifPresent { it.forEach { it.validate() } } createdAt() createdBy() createdByUserObj().ifPresent { it.validate() } @@ -602,6 +663,7 @@ private constructor( @JvmSynthetic internal fun validity(): Int = (if (id.asKnown().isPresent) 1 else 0) + + (assignmentSources.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + (if (createdAt.asKnown().isPresent) 1 else 0) + (if (createdBy.asKnown().isPresent) 1 else 0) + (createdByUserObj.asKnown().getOrNull()?.validity() ?: 0) + @@ -613,6 +675,222 @@ private constructor( (if (resourceType.asKnown().isPresent) 1 else 0) + (if (updatedAt.asKnown().isPresent) 1 else 0) + class AssignmentSource + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val principalId: JsonField, + private val principalType: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("principal_id") + @ExcludeMissing + principalId: JsonField = JsonMissing.of(), + @JsonProperty("principal_type") + @ExcludeMissing + principalType: JsonField = JsonMissing.of(), + ) : this(principalId, principalType, mutableMapOf()) + + /** + * @throws OpenAIInvalidDataException 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 principalId(): String = principalId.getRequired("principal_id") + + /** + * @throws OpenAIInvalidDataException 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 principalType(): String = principalType.getRequired("principal_type") + + /** + * Returns the raw JSON value of [principalId]. + * + * Unlike [principalId], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("principal_id") + @ExcludeMissing + fun _principalId(): JsonField = principalId + + /** + * Returns the raw JSON value of [principalType]. + * + * Unlike [principalType], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("principal_type") + @ExcludeMissing + fun _principalType(): JsonField = principalType + + @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 [AssignmentSource]. + * + * The following fields are required: + * ```java + * .principalId() + * .principalType() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [AssignmentSource]. */ + class Builder internal constructor() { + + private var principalId: JsonField? = null + private var principalType: JsonField? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(assignmentSource: AssignmentSource) = apply { + principalId = assignmentSource.principalId + principalType = assignmentSource.principalType + additionalProperties = assignmentSource.additionalProperties.toMutableMap() + } + + fun principalId(principalId: String) = principalId(JsonField.of(principalId)) + + /** + * Sets [Builder.principalId] to an arbitrary JSON value. + * + * You should usually call [Builder.principalId] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun principalId(principalId: JsonField) = apply { + this.principalId = principalId + } + + fun principalType(principalType: String) = principalType(JsonField.of(principalType)) + + /** + * Sets [Builder.principalType] to an arbitrary JSON value. + * + * You should usually call [Builder.principalType] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun principalType(principalType: JsonField) = apply { + this.principalType = principalType + } + + 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 [AssignmentSource]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .principalId() + * .principalType() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): AssignmentSource = + AssignmentSource( + checkRequired("principalId", principalId), + checkRequired("principalType", principalType), + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing fields. + * + * @throws OpenAIInvalidDataException if any value type in this object doesn't match its + * expected type. + */ + fun validate(): AssignmentSource = apply { + if (validated) { + return@apply + } + + principalId() + principalType() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OpenAIInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (if (principalId.asKnown().isPresent) 1 else 0) + + (if (principalType.asKnown().isPresent) 1 else 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is AssignmentSource && + principalId == other.principalId && + principalType == other.principalType && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(principalId, principalType, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "AssignmentSource{principalId=$principalId, principalType=$principalType, additionalProperties=$additionalProperties}" + } + /** User details for the actor that created the role, when available. */ class CreatedByUserObj @JsonCreator @@ -838,6 +1116,7 @@ private constructor( return other is RoleListResponse && id == other.id && + assignmentSources == other.assignmentSources && createdAt == other.createdAt && createdBy == other.createdBy && createdByUserObj == other.createdByUserObj && @@ -854,6 +1133,7 @@ private constructor( private val hashCode: Int by lazy { Objects.hash( id, + assignmentSources, createdAt, createdBy, createdByUserObj, @@ -871,5 +1151,5 @@ private constructor( override fun hashCode(): Int = hashCode override fun toString() = - "RoleListResponse{id=$id, createdAt=$createdAt, createdBy=$createdBy, createdByUserObj=$createdByUserObj, description=$description, metadata=$metadata, name=$name, permissions=$permissions, predefinedRole=$predefinedRole, resourceType=$resourceType, updatedAt=$updatedAt, additionalProperties=$additionalProperties}" + "RoleListResponse{id=$id, assignmentSources=$assignmentSources, createdAt=$createdAt, createdBy=$createdBy, createdByUserObj=$createdByUserObj, description=$description, metadata=$metadata, name=$name, permissions=$permissions, predefinedRole=$predefinedRole, resourceType=$resourceType, updatedAt=$updatedAt, additionalProperties=$additionalProperties}" } diff --git a/openai-java-core/src/main/kotlin/com/openai/models/admin/organization/groups/roles/RoleRetrieveParams.kt b/openai-java-core/src/main/kotlin/com/openai/models/admin/organization/groups/roles/RoleRetrieveParams.kt new file mode 100644 index 000000000..522eb4d9e --- /dev/null +++ b/openai-java-core/src/main/kotlin/com/openai/models/admin/organization/groups/roles/RoleRetrieveParams.kt @@ -0,0 +1,217 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.models.admin.organization.groups.roles + +import com.openai.core.Params +import com.openai.core.checkRequired +import com.openai.core.http.Headers +import com.openai.core.http.QueryParams +import java.util.Objects +import java.util.Optional +import kotlin.jvm.optionals.getOrNull + +/** Retrieves an organization role assigned to a group. */ +class RoleRetrieveParams +private constructor( + private val groupId: String, + private val roleId: String?, + private val additionalHeaders: Headers, + private val additionalQueryParams: QueryParams, +) : Params { + + fun groupId(): String = groupId + + fun roleId(): Optional = Optional.ofNullable(roleId) + + /** Additional headers to send with the request. */ + fun _additionalHeaders(): Headers = additionalHeaders + + /** Additional query param to send with the request. */ + fun _additionalQueryParams(): QueryParams = additionalQueryParams + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of [RoleRetrieveParams]. + * + * The following fields are required: + * ```java + * .groupId() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [RoleRetrieveParams]. */ + class Builder internal constructor() { + + private var groupId: String? = null + private var roleId: String? = null + private var additionalHeaders: Headers.Builder = Headers.builder() + private var additionalQueryParams: QueryParams.Builder = QueryParams.builder() + + @JvmSynthetic + internal fun from(roleRetrieveParams: RoleRetrieveParams) = apply { + groupId = roleRetrieveParams.groupId + roleId = roleRetrieveParams.roleId + additionalHeaders = roleRetrieveParams.additionalHeaders.toBuilder() + additionalQueryParams = roleRetrieveParams.additionalQueryParams.toBuilder() + } + + fun groupId(groupId: String) = apply { this.groupId = groupId } + + fun roleId(roleId: String?) = apply { this.roleId = roleId } + + /** Alias for calling [Builder.roleId] with `roleId.orElse(null)`. */ + fun roleId(roleId: Optional) = roleId(roleId.getOrNull()) + + 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 [RoleRetrieveParams]. + * + * 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(): RoleRetrieveParams = + RoleRetrieveParams( + checkRequired("groupId", groupId), + roleId, + additionalHeaders.build(), + additionalQueryParams.build(), + ) + } + + fun _pathParam(index: Int): String = + when (index) { + 0 -> groupId + 1 -> roleId ?: "" + else -> "" + } + + override fun _headers(): Headers = additionalHeaders + + override fun _queryParams(): QueryParams = additionalQueryParams + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is RoleRetrieveParams && + groupId == other.groupId && + roleId == other.roleId && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams + } + + override fun hashCode(): Int = + Objects.hash(groupId, roleId, additionalHeaders, additionalQueryParams) + + override fun toString() = + "RoleRetrieveParams{groupId=$groupId, roleId=$roleId, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" +} diff --git a/openai-java-core/src/main/kotlin/com/openai/models/admin/organization/groups/roles/RoleRetrieveResponse.kt b/openai-java-core/src/main/kotlin/com/openai/models/admin/organization/groups/roles/RoleRetrieveResponse.kt new file mode 100644 index 000000000..2c7c7f22f --- /dev/null +++ b/openai-java-core/src/main/kotlin/com/openai/models/admin/organization/groups/roles/RoleRetrieveResponse.kt @@ -0,0 +1,1155 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.models.admin.organization.groups.roles + +import com.fasterxml.jackson.annotation.JsonAnyGetter +import com.fasterxml.jackson.annotation.JsonAnySetter +import com.fasterxml.jackson.annotation.JsonCreator +import com.fasterxml.jackson.annotation.JsonProperty +import com.openai.core.ExcludeMissing +import com.openai.core.JsonField +import com.openai.core.JsonMissing +import com.openai.core.JsonValue +import com.openai.core.checkKnown +import com.openai.core.checkRequired +import com.openai.core.toImmutable +import com.openai.errors.OpenAIInvalidDataException +import java.util.Collections +import java.util.Objects +import java.util.Optional +import kotlin.jvm.optionals.getOrNull + +/** Detailed information about a role assignment entry returned when listing assignments. */ +class RoleRetrieveResponse +@JsonCreator(mode = JsonCreator.Mode.DISABLED) +private constructor( + private val id: JsonField, + private val assignmentSources: JsonField>, + private val createdAt: JsonField, + private val createdBy: JsonField, + private val createdByUserObj: JsonField, + private val description: JsonField, + private val metadata: JsonField, + private val name: JsonField, + private val permissions: JsonField>, + private val predefinedRole: JsonField, + private val resourceType: JsonField, + private val updatedAt: JsonField, + private val additionalProperties: MutableMap, +) { + + @JsonCreator + private constructor( + @JsonProperty("id") @ExcludeMissing id: JsonField = JsonMissing.of(), + @JsonProperty("assignment_sources") + @ExcludeMissing + assignmentSources: JsonField> = JsonMissing.of(), + @JsonProperty("created_at") @ExcludeMissing createdAt: JsonField = JsonMissing.of(), + @JsonProperty("created_by") @ExcludeMissing createdBy: JsonField = JsonMissing.of(), + @JsonProperty("created_by_user_obj") + @ExcludeMissing + createdByUserObj: 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("permissions") + @ExcludeMissing + permissions: JsonField> = JsonMissing.of(), + @JsonProperty("predefined_role") + @ExcludeMissing + predefinedRole: JsonField = JsonMissing.of(), + @JsonProperty("resource_type") + @ExcludeMissing + resourceType: JsonField = JsonMissing.of(), + @JsonProperty("updated_at") @ExcludeMissing updatedAt: JsonField = JsonMissing.of(), + ) : this( + id, + assignmentSources, + createdAt, + createdBy, + createdByUserObj, + description, + metadata, + name, + permissions, + predefinedRole, + resourceType, + updatedAt, + mutableMapOf(), + ) + + /** + * Identifier for the role. + * + * @throws OpenAIInvalidDataException 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 id(): String = id.getRequired("id") + + /** + * Principals from which the role assignment is inherited, when available. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun assignmentSources(): Optional> = + assignmentSources.getOptional("assignment_sources") + + /** + * When the role was created. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun createdAt(): Optional = createdAt.getOptional("created_at") + + /** + * Identifier of the actor who created the role. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun createdBy(): Optional = createdBy.getOptional("created_by") + + /** + * User details for the actor that created the role, when available. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun createdByUserObj(): Optional = + createdByUserObj.getOptional("created_by_user_obj") + + /** + * Description of the role. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun description(): Optional = description.getOptional("description") + + /** + * Arbitrary metadata stored on the role. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun metadata(): Optional = metadata.getOptional("metadata") + + /** + * Name of the role. + * + * @throws OpenAIInvalidDataException 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") + + /** + * Permissions associated with the role. + * + * @throws OpenAIInvalidDataException 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 permissions(): List = permissions.getRequired("permissions") + + /** + * Whether the role is predefined by OpenAI. + * + * @throws OpenAIInvalidDataException 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 predefinedRole(): Boolean = predefinedRole.getRequired("predefined_role") + + /** + * Resource type the role applies to. + * + * @throws OpenAIInvalidDataException 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 resourceType(): String = resourceType.getRequired("resource_type") + + /** + * When the role was last updated. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun updatedAt(): Optional = updatedAt.getOptional("updated_at") + + /** + * Returns the raw JSON value of [id]. + * + * Unlike [id], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("id") @ExcludeMissing fun _id(): JsonField = id + + /** + * Returns the raw JSON value of [assignmentSources]. + * + * Unlike [assignmentSources], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("assignment_sources") + @ExcludeMissing + fun _assignmentSources(): JsonField> = assignmentSources + + /** + * Returns the raw JSON value of [createdAt]. + * + * Unlike [createdAt], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("created_at") @ExcludeMissing fun _createdAt(): JsonField = createdAt + + /** + * Returns the raw JSON value of [createdBy]. + * + * Unlike [createdBy], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("created_by") @ExcludeMissing fun _createdBy(): JsonField = createdBy + + /** + * Returns the raw JSON value of [createdByUserObj]. + * + * Unlike [createdByUserObj], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("created_by_user_obj") + @ExcludeMissing + fun _createdByUserObj(): JsonField = createdByUserObj + + /** + * 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 + + /** + * Returns the raw JSON value of [permissions]. + * + * Unlike [permissions], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("permissions") + @ExcludeMissing + fun _permissions(): JsonField> = permissions + + /** + * Returns the raw JSON value of [predefinedRole]. + * + * Unlike [predefinedRole], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("predefined_role") + @ExcludeMissing + fun _predefinedRole(): JsonField = predefinedRole + + /** + * Returns the raw JSON value of [resourceType]. + * + * Unlike [resourceType], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("resource_type") + @ExcludeMissing + fun _resourceType(): JsonField = resourceType + + /** + * Returns the raw JSON value of [updatedAt]. + * + * Unlike [updatedAt], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("updated_at") @ExcludeMissing fun _updatedAt(): JsonField = updatedAt + + @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 [RoleRetrieveResponse]. + * + * The following fields are required: + * ```java + * .id() + * .assignmentSources() + * .createdAt() + * .createdBy() + * .createdByUserObj() + * .description() + * .metadata() + * .name() + * .permissions() + * .predefinedRole() + * .resourceType() + * .updatedAt() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [RoleRetrieveResponse]. */ + class Builder internal constructor() { + + private var id: JsonField? = null + private var assignmentSources: JsonField>? = null + private var createdAt: JsonField? = null + private var createdBy: JsonField? = null + private var createdByUserObj: JsonField? = null + private var description: JsonField? = null + private var metadata: JsonField? = null + private var name: JsonField? = null + private var permissions: JsonField>? = null + private var predefinedRole: JsonField? = null + private var resourceType: JsonField? = null + private var updatedAt: JsonField? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(roleRetrieveResponse: RoleRetrieveResponse) = apply { + id = roleRetrieveResponse.id + assignmentSources = roleRetrieveResponse.assignmentSources.map { it.toMutableList() } + createdAt = roleRetrieveResponse.createdAt + createdBy = roleRetrieveResponse.createdBy + createdByUserObj = roleRetrieveResponse.createdByUserObj + description = roleRetrieveResponse.description + metadata = roleRetrieveResponse.metadata + name = roleRetrieveResponse.name + permissions = roleRetrieveResponse.permissions.map { it.toMutableList() } + predefinedRole = roleRetrieveResponse.predefinedRole + resourceType = roleRetrieveResponse.resourceType + updatedAt = roleRetrieveResponse.updatedAt + additionalProperties = roleRetrieveResponse.additionalProperties.toMutableMap() + } + + /** Identifier for the role. */ + fun id(id: String) = id(JsonField.of(id)) + + /** + * Sets [Builder.id] to an arbitrary JSON value. + * + * You should usually call [Builder.id] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun id(id: JsonField) = apply { this.id = id } + + /** Principals from which the role assignment is inherited, when available. */ + fun assignmentSources(assignmentSources: List?) = + assignmentSources(JsonField.ofNullable(assignmentSources)) + + /** Alias for calling [Builder.assignmentSources] with `assignmentSources.orElse(null)`. */ + fun assignmentSources(assignmentSources: Optional>) = + assignmentSources(assignmentSources.getOrNull()) + + /** + * Sets [Builder.assignmentSources] to an arbitrary JSON value. + * + * You should usually call [Builder.assignmentSources] with a well-typed + * `List` value instead. This method is primarily for setting the field to + * an undocumented or not yet supported value. + */ + fun assignmentSources(assignmentSources: JsonField>) = apply { + this.assignmentSources = assignmentSources.map { it.toMutableList() } + } + + /** + * Adds a single [AssignmentSource] to [assignmentSources]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addAssignmentSource(assignmentSource: AssignmentSource) = apply { + assignmentSources = + (assignmentSources ?: JsonField.of(mutableListOf())).also { + checkKnown("assignmentSources", it).add(assignmentSource) + } + } + + /** When the role was created. */ + fun createdAt(createdAt: Long?) = createdAt(JsonField.ofNullable(createdAt)) + + /** + * Alias for [Builder.createdAt]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun createdAt(createdAt: Long) = createdAt(createdAt as Long?) + + /** Alias for calling [Builder.createdAt] with `createdAt.orElse(null)`. */ + fun createdAt(createdAt: Optional) = createdAt(createdAt.getOrNull()) + + /** + * Sets [Builder.createdAt] to an arbitrary JSON value. + * + * You should usually call [Builder.createdAt] with a well-typed [Long] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun createdAt(createdAt: JsonField) = apply { this.createdAt = createdAt } + + /** Identifier of the actor who created the role. */ + fun createdBy(createdBy: String?) = createdBy(JsonField.ofNullable(createdBy)) + + /** Alias for calling [Builder.createdBy] with `createdBy.orElse(null)`. */ + fun createdBy(createdBy: Optional) = createdBy(createdBy.getOrNull()) + + /** + * Sets [Builder.createdBy] to an arbitrary JSON value. + * + * You should usually call [Builder.createdBy] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun createdBy(createdBy: JsonField) = apply { this.createdBy = createdBy } + + /** User details for the actor that created the role, when available. */ + fun createdByUserObj(createdByUserObj: CreatedByUserObj?) = + createdByUserObj(JsonField.ofNullable(createdByUserObj)) + + /** Alias for calling [Builder.createdByUserObj] with `createdByUserObj.orElse(null)`. */ + fun createdByUserObj(createdByUserObj: Optional) = + createdByUserObj(createdByUserObj.getOrNull()) + + /** + * Sets [Builder.createdByUserObj] to an arbitrary JSON value. + * + * You should usually call [Builder.createdByUserObj] with a well-typed [CreatedByUserObj] + * value instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun createdByUserObj(createdByUserObj: JsonField) = apply { + this.createdByUserObj = createdByUserObj + } + + /** 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 } + + /** Arbitrary metadata stored on the role. */ + 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 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 } + + /** Permissions associated with the role. */ + fun permissions(permissions: List) = permissions(JsonField.of(permissions)) + + /** + * Sets [Builder.permissions] to an arbitrary JSON value. + * + * You should usually call [Builder.permissions] with a well-typed `List` value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun permissions(permissions: JsonField>) = apply { + this.permissions = permissions.map { it.toMutableList() } + } + + /** + * Adds a single [String] to [permissions]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addPermission(permission: String) = apply { + permissions = + (permissions ?: JsonField.of(mutableListOf())).also { + checkKnown("permissions", it).add(permission) + } + } + + /** Whether the role is predefined by OpenAI. */ + fun predefinedRole(predefinedRole: Boolean) = predefinedRole(JsonField.of(predefinedRole)) + + /** + * Sets [Builder.predefinedRole] to an arbitrary JSON value. + * + * You should usually call [Builder.predefinedRole] with a well-typed [Boolean] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun predefinedRole(predefinedRole: JsonField) = apply { + this.predefinedRole = predefinedRole + } + + /** Resource type the role applies to. */ + fun resourceType(resourceType: String) = resourceType(JsonField.of(resourceType)) + + /** + * Sets [Builder.resourceType] to an arbitrary JSON value. + * + * You should usually call [Builder.resourceType] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun resourceType(resourceType: JsonField) = apply { + this.resourceType = resourceType + } + + /** When the role was last updated. */ + fun updatedAt(updatedAt: Long?) = updatedAt(JsonField.ofNullable(updatedAt)) + + /** + * Alias for [Builder.updatedAt]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun updatedAt(updatedAt: Long) = updatedAt(updatedAt as Long?) + + /** Alias for calling [Builder.updatedAt] with `updatedAt.orElse(null)`. */ + fun updatedAt(updatedAt: Optional) = updatedAt(updatedAt.getOrNull()) + + /** + * Sets [Builder.updatedAt] to an arbitrary JSON value. + * + * You should usually call [Builder.updatedAt] with a well-typed [Long] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun updatedAt(updatedAt: JsonField) = apply { this.updatedAt = updatedAt } + + 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 [RoleRetrieveResponse]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .id() + * .assignmentSources() + * .createdAt() + * .createdBy() + * .createdByUserObj() + * .description() + * .metadata() + * .name() + * .permissions() + * .predefinedRole() + * .resourceType() + * .updatedAt() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): RoleRetrieveResponse = + RoleRetrieveResponse( + checkRequired("id", id), + checkRequired("assignmentSources", assignmentSources).map { it.toImmutable() }, + checkRequired("createdAt", createdAt), + checkRequired("createdBy", createdBy), + checkRequired("createdByUserObj", createdByUserObj), + checkRequired("description", description), + checkRequired("metadata", metadata), + checkRequired("name", name), + checkRequired("permissions", permissions).map { it.toImmutable() }, + checkRequired("predefinedRole", predefinedRole), + checkRequired("resourceType", resourceType), + checkRequired("updatedAt", updatedAt), + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected types recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing fields. + * + * @throws OpenAIInvalidDataException if any value type in this object doesn't match its + * expected type. + */ + fun validate(): RoleRetrieveResponse = apply { + if (validated) { + return@apply + } + + id() + assignmentSources().ifPresent { it.forEach { it.validate() } } + createdAt() + createdBy() + createdByUserObj().ifPresent { it.validate() } + description() + metadata().ifPresent { it.validate() } + name() + permissions() + predefinedRole() + resourceType() + updatedAt() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OpenAIInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (if (id.asKnown().isPresent) 1 else 0) + + (assignmentSources.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + + (if (createdAt.asKnown().isPresent) 1 else 0) + + (if (createdBy.asKnown().isPresent) 1 else 0) + + (createdByUserObj.asKnown().getOrNull()?.validity() ?: 0) + + (if (description.asKnown().isPresent) 1 else 0) + + (metadata.asKnown().getOrNull()?.validity() ?: 0) + + (if (name.asKnown().isPresent) 1 else 0) + + (permissions.asKnown().getOrNull()?.size ?: 0) + + (if (predefinedRole.asKnown().isPresent) 1 else 0) + + (if (resourceType.asKnown().isPresent) 1 else 0) + + (if (updatedAt.asKnown().isPresent) 1 else 0) + + class AssignmentSource + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val principalId: JsonField, + private val principalType: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("principal_id") + @ExcludeMissing + principalId: JsonField = JsonMissing.of(), + @JsonProperty("principal_type") + @ExcludeMissing + principalType: JsonField = JsonMissing.of(), + ) : this(principalId, principalType, mutableMapOf()) + + /** + * @throws OpenAIInvalidDataException 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 principalId(): String = principalId.getRequired("principal_id") + + /** + * @throws OpenAIInvalidDataException 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 principalType(): String = principalType.getRequired("principal_type") + + /** + * Returns the raw JSON value of [principalId]. + * + * Unlike [principalId], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("principal_id") + @ExcludeMissing + fun _principalId(): JsonField = principalId + + /** + * Returns the raw JSON value of [principalType]. + * + * Unlike [principalType], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("principal_type") + @ExcludeMissing + fun _principalType(): JsonField = principalType + + @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 [AssignmentSource]. + * + * The following fields are required: + * ```java + * .principalId() + * .principalType() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [AssignmentSource]. */ + class Builder internal constructor() { + + private var principalId: JsonField? = null + private var principalType: JsonField? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(assignmentSource: AssignmentSource) = apply { + principalId = assignmentSource.principalId + principalType = assignmentSource.principalType + additionalProperties = assignmentSource.additionalProperties.toMutableMap() + } + + fun principalId(principalId: String) = principalId(JsonField.of(principalId)) + + /** + * Sets [Builder.principalId] to an arbitrary JSON value. + * + * You should usually call [Builder.principalId] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun principalId(principalId: JsonField) = apply { + this.principalId = principalId + } + + fun principalType(principalType: String) = principalType(JsonField.of(principalType)) + + /** + * Sets [Builder.principalType] to an arbitrary JSON value. + * + * You should usually call [Builder.principalType] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun principalType(principalType: JsonField) = apply { + this.principalType = principalType + } + + 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 [AssignmentSource]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .principalId() + * .principalType() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): AssignmentSource = + AssignmentSource( + checkRequired("principalId", principalId), + checkRequired("principalType", principalType), + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing fields. + * + * @throws OpenAIInvalidDataException if any value type in this object doesn't match its + * expected type. + */ + fun validate(): AssignmentSource = apply { + if (validated) { + return@apply + } + + principalId() + principalType() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OpenAIInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (if (principalId.asKnown().isPresent) 1 else 0) + + (if (principalType.asKnown().isPresent) 1 else 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is AssignmentSource && + principalId == other.principalId && + principalType == other.principalType && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(principalId, principalType, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "AssignmentSource{principalId=$principalId, principalType=$principalType, additionalProperties=$additionalProperties}" + } + + /** User details for the actor that created the role, when available. */ + class CreatedByUserObj + @JsonCreator + private constructor( + @com.fasterxml.jackson.annotation.JsonValue + private val additionalProperties: Map + ) { + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = additionalProperties + + fun toBuilder() = Builder().from(this) + + companion object { + + /** Returns a mutable builder for constructing an instance of [CreatedByUserObj]. */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [CreatedByUserObj]. */ + class Builder internal constructor() { + + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(createdByUserObj: CreatedByUserObj) = apply { + additionalProperties = createdByUserObj.additionalProperties.toMutableMap() + } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [CreatedByUserObj]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): CreatedByUserObj = CreatedByUserObj(additionalProperties.toImmutable()) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing fields. + * + * @throws OpenAIInvalidDataException if any value type in this object doesn't match its + * expected type. + */ + fun validate(): CreatedByUserObj = apply { + if (validated) { + return@apply + } + + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OpenAIInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + additionalProperties.count { (_, value) -> !value.isNull() && !value.isMissing() } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is CreatedByUserObj && additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = "CreatedByUserObj{additionalProperties=$additionalProperties}" + } + + /** Arbitrary metadata stored on the role. */ + class Metadata + @JsonCreator + private constructor( + @com.fasterxml.jackson.annotation.JsonValue + private val additionalProperties: Map + ) { + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = additionalProperties + + fun toBuilder() = Builder().from(this) + + companion object { + + /** Returns a mutable builder for constructing an instance of [Metadata]. */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [Metadata]. */ + class Builder internal constructor() { + + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(metadata: Metadata) = apply { + additionalProperties = metadata.additionalProperties.toMutableMap() + } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [Metadata]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): Metadata = Metadata(additionalProperties.toImmutable()) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing fields. + * + * @throws OpenAIInvalidDataException if any value type in this object doesn't match its + * expected type. + */ + fun validate(): Metadata = apply { + if (validated) { + return@apply + } + + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OpenAIInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + additionalProperties.count { (_, value) -> !value.isNull() && !value.isMissing() } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Metadata && additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = "Metadata{additionalProperties=$additionalProperties}" + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is RoleRetrieveResponse && + id == other.id && + assignmentSources == other.assignmentSources && + createdAt == other.createdAt && + createdBy == other.createdBy && + createdByUserObj == other.createdByUserObj && + description == other.description && + metadata == other.metadata && + name == other.name && + permissions == other.permissions && + predefinedRole == other.predefinedRole && + resourceType == other.resourceType && + updatedAt == other.updatedAt && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + id, + assignmentSources, + createdAt, + createdBy, + createdByUserObj, + description, + metadata, + name, + permissions, + predefinedRole, + resourceType, + updatedAt, + additionalProperties, + ) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "RoleRetrieveResponse{id=$id, assignmentSources=$assignmentSources, createdAt=$createdAt, createdBy=$createdBy, createdByUserObj=$createdByUserObj, description=$description, metadata=$metadata, name=$name, permissions=$permissions, predefinedRole=$predefinedRole, resourceType=$resourceType, updatedAt=$updatedAt, additionalProperties=$additionalProperties}" +} diff --git a/openai-java-core/src/main/kotlin/com/openai/models/admin/organization/groups/users/UserRetrieveParams.kt b/openai-java-core/src/main/kotlin/com/openai/models/admin/organization/groups/users/UserRetrieveParams.kt new file mode 100644 index 000000000..68e311bfb --- /dev/null +++ b/openai-java-core/src/main/kotlin/com/openai/models/admin/organization/groups/users/UserRetrieveParams.kt @@ -0,0 +1,217 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.models.admin.organization.groups.users + +import com.openai.core.Params +import com.openai.core.checkRequired +import com.openai.core.http.Headers +import com.openai.core.http.QueryParams +import java.util.Objects +import java.util.Optional +import kotlin.jvm.optionals.getOrNull + +/** Retrieves a user in a group. */ +class UserRetrieveParams +private constructor( + private val groupId: String, + private val userId: String?, + private val additionalHeaders: Headers, + private val additionalQueryParams: QueryParams, +) : Params { + + fun groupId(): String = groupId + + fun userId(): Optional = Optional.ofNullable(userId) + + /** Additional headers to send with the request. */ + fun _additionalHeaders(): Headers = additionalHeaders + + /** Additional query param to send with the request. */ + fun _additionalQueryParams(): QueryParams = additionalQueryParams + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of [UserRetrieveParams]. + * + * The following fields are required: + * ```java + * .groupId() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [UserRetrieveParams]. */ + class Builder internal constructor() { + + private var groupId: String? = null + private var userId: String? = null + private var additionalHeaders: Headers.Builder = Headers.builder() + private var additionalQueryParams: QueryParams.Builder = QueryParams.builder() + + @JvmSynthetic + internal fun from(userRetrieveParams: UserRetrieveParams) = apply { + groupId = userRetrieveParams.groupId + userId = userRetrieveParams.userId + additionalHeaders = userRetrieveParams.additionalHeaders.toBuilder() + additionalQueryParams = userRetrieveParams.additionalQueryParams.toBuilder() + } + + fun groupId(groupId: String) = apply { this.groupId = groupId } + + fun userId(userId: String?) = apply { this.userId = userId } + + /** Alias for calling [Builder.userId] with `userId.orElse(null)`. */ + fun userId(userId: Optional) = userId(userId.getOrNull()) + + 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 [UserRetrieveParams]. + * + * 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(): UserRetrieveParams = + UserRetrieveParams( + checkRequired("groupId", groupId), + userId, + additionalHeaders.build(), + additionalQueryParams.build(), + ) + } + + fun _pathParam(index: Int): String = + when (index) { + 0 -> groupId + 1 -> userId ?: "" + else -> "" + } + + override fun _headers(): Headers = additionalHeaders + + override fun _queryParams(): QueryParams = additionalQueryParams + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is UserRetrieveParams && + groupId == other.groupId && + userId == other.userId && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams + } + + override fun hashCode(): Int = + Objects.hash(groupId, userId, additionalHeaders, additionalQueryParams) + + override fun toString() = + "UserRetrieveParams{groupId=$groupId, userId=$userId, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" +} diff --git a/openai-java-core/src/main/kotlin/com/openai/models/admin/organization/groups/users/UserRetrieveResponse.kt b/openai-java-core/src/main/kotlin/com/openai/models/admin/organization/groups/users/UserRetrieveResponse.kt new file mode 100644 index 000000000..154d9f03e --- /dev/null +++ b/openai-java-core/src/main/kotlin/com/openai/models/admin/organization/groups/users/UserRetrieveResponse.kt @@ -0,0 +1,532 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.models.admin.organization.groups.users + +import com.fasterxml.jackson.annotation.JsonAnyGetter +import com.fasterxml.jackson.annotation.JsonAnySetter +import com.fasterxml.jackson.annotation.JsonCreator +import com.fasterxml.jackson.annotation.JsonProperty +import com.openai.core.Enum +import com.openai.core.ExcludeMissing +import com.openai.core.JsonField +import com.openai.core.JsonMissing +import com.openai.core.JsonValue +import com.openai.core.checkRequired +import com.openai.errors.OpenAIInvalidDataException +import java.util.Collections +import java.util.Objects +import java.util.Optional +import kotlin.jvm.optionals.getOrNull + +/** Details about a user returned from an organization group membership lookup. */ +class UserRetrieveResponse +@JsonCreator(mode = JsonCreator.Mode.DISABLED) +private constructor( + private val id: JsonField, + private val email: JsonField, + private val isServiceAccount: JsonField, + private val name: JsonField, + private val picture: JsonField, + private val userType: JsonField, + private val additionalProperties: MutableMap, +) { + + @JsonCreator + private constructor( + @JsonProperty("id") @ExcludeMissing id: JsonField = JsonMissing.of(), + @JsonProperty("email") @ExcludeMissing email: JsonField = JsonMissing.of(), + @JsonProperty("is_service_account") + @ExcludeMissing + isServiceAccount: JsonField = JsonMissing.of(), + @JsonProperty("name") @ExcludeMissing name: JsonField = JsonMissing.of(), + @JsonProperty("picture") @ExcludeMissing picture: JsonField = JsonMissing.of(), + @JsonProperty("user_type") @ExcludeMissing userType: JsonField = JsonMissing.of(), + ) : this(id, email, isServiceAccount, name, picture, userType, mutableMapOf()) + + /** + * Identifier for the user. + * + * @throws OpenAIInvalidDataException 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 id(): String = id.getRequired("id") + + /** + * Email address of the user, or `null` for users without an email. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun email(): Optional = email.getOptional("email") + + /** + * Whether the user is a service account. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun isServiceAccount(): Optional = isServiceAccount.getOptional("is_service_account") + + /** + * Display name of the user. + * + * @throws OpenAIInvalidDataException 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") + + /** + * URL of the user's profile picture, if available. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun picture(): Optional = picture.getOptional("picture") + + /** + * The type of user. + * + * @throws OpenAIInvalidDataException 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 userType(): UserType = userType.getRequired("user_type") + + /** + * Returns the raw JSON value of [id]. + * + * Unlike [id], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("id") @ExcludeMissing fun _id(): JsonField = id + + /** + * Returns the raw JSON value of [email]. + * + * Unlike [email], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("email") @ExcludeMissing fun _email(): JsonField = email + + /** + * Returns the raw JSON value of [isServiceAccount]. + * + * Unlike [isServiceAccount], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("is_service_account") + @ExcludeMissing + fun _isServiceAccount(): JsonField = isServiceAccount + + /** + * 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 [picture]. + * + * Unlike [picture], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("picture") @ExcludeMissing fun _picture(): JsonField = picture + + /** + * Returns the raw JSON value of [userType]. + * + * Unlike [userType], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("user_type") @ExcludeMissing fun _userType(): JsonField = userType + + @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 [UserRetrieveResponse]. + * + * The following fields are required: + * ```java + * .id() + * .email() + * .isServiceAccount() + * .name() + * .picture() + * .userType() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [UserRetrieveResponse]. */ + class Builder internal constructor() { + + private var id: JsonField? = null + private var email: JsonField? = null + private var isServiceAccount: JsonField? = null + private var name: JsonField? = null + private var picture: JsonField? = null + private var userType: JsonField? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(userRetrieveResponse: UserRetrieveResponse) = apply { + id = userRetrieveResponse.id + email = userRetrieveResponse.email + isServiceAccount = userRetrieveResponse.isServiceAccount + name = userRetrieveResponse.name + picture = userRetrieveResponse.picture + userType = userRetrieveResponse.userType + additionalProperties = userRetrieveResponse.additionalProperties.toMutableMap() + } + + /** Identifier for the user. */ + fun id(id: String) = id(JsonField.of(id)) + + /** + * Sets [Builder.id] to an arbitrary JSON value. + * + * You should usually call [Builder.id] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun id(id: JsonField) = apply { this.id = id } + + /** Email address of the user, or `null` for users without an email. */ + fun email(email: String?) = email(JsonField.ofNullable(email)) + + /** Alias for calling [Builder.email] with `email.orElse(null)`. */ + fun email(email: Optional) = email(email.getOrNull()) + + /** + * Sets [Builder.email] to an arbitrary JSON value. + * + * You should usually call [Builder.email] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun email(email: JsonField) = apply { this.email = email } + + /** Whether the user is a service account. */ + fun isServiceAccount(isServiceAccount: Boolean?) = + isServiceAccount(JsonField.ofNullable(isServiceAccount)) + + /** + * Alias for [Builder.isServiceAccount]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun isServiceAccount(isServiceAccount: Boolean) = + isServiceAccount(isServiceAccount as Boolean?) + + /** Alias for calling [Builder.isServiceAccount] with `isServiceAccount.orElse(null)`. */ + fun isServiceAccount(isServiceAccount: Optional) = + isServiceAccount(isServiceAccount.getOrNull()) + + /** + * Sets [Builder.isServiceAccount] to an arbitrary JSON value. + * + * You should usually call [Builder.isServiceAccount] with a well-typed [Boolean] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun isServiceAccount(isServiceAccount: JsonField) = apply { + this.isServiceAccount = isServiceAccount + } + + /** Display name of the user. */ + 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 } + + /** URL of the user's profile picture, if available. */ + fun picture(picture: String?) = picture(JsonField.ofNullable(picture)) + + /** Alias for calling [Builder.picture] with `picture.orElse(null)`. */ + fun picture(picture: Optional) = picture(picture.getOrNull()) + + /** + * Sets [Builder.picture] to an arbitrary JSON value. + * + * You should usually call [Builder.picture] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun picture(picture: JsonField) = apply { this.picture = picture } + + /** The type of user. */ + fun userType(userType: UserType) = userType(JsonField.of(userType)) + + /** + * Sets [Builder.userType] to an arbitrary JSON value. + * + * You should usually call [Builder.userType] with a well-typed [UserType] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun userType(userType: JsonField) = apply { this.userType = userType } + + 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 [UserRetrieveResponse]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .id() + * .email() + * .isServiceAccount() + * .name() + * .picture() + * .userType() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): UserRetrieveResponse = + UserRetrieveResponse( + checkRequired("id", id), + checkRequired("email", email), + checkRequired("isServiceAccount", isServiceAccount), + checkRequired("name", name), + checkRequired("picture", picture), + checkRequired("userType", userType), + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected types recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing fields. + * + * @throws OpenAIInvalidDataException if any value type in this object doesn't match its + * expected type. + */ + fun validate(): UserRetrieveResponse = apply { + if (validated) { + return@apply + } + + id() + email() + isServiceAccount() + name() + picture() + userType().validate() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OpenAIInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (if (id.asKnown().isPresent) 1 else 0) + + (if (email.asKnown().isPresent) 1 else 0) + + (if (isServiceAccount.asKnown().isPresent) 1 else 0) + + (if (name.asKnown().isPresent) 1 else 0) + + (if (picture.asKnown().isPresent) 1 else 0) + + (userType.asKnown().getOrNull()?.validity() ?: 0) + + /** The type of user. */ + class UserType @JsonCreator private constructor(private val value: JsonField) : Enum { + + /** + * Returns this class instance's raw value. + * + * This is usually only useful if this instance was deserialized from data that doesn't + * match any known member, and you want to know that value. For example, if the SDK is on an + * older version than the API, then the API may respond with new members that the SDK is + * unaware of. + */ + @com.fasterxml.jackson.annotation.JsonValue fun _value(): JsonField = value + + companion object { + + @JvmField val USER = of("user") + + @JvmField val TENANT_USER = of("tenant_user") + + @JvmStatic fun of(value: String) = UserType(JsonField.of(value)) + } + + /** An enum containing [UserType]'s known values. */ + enum class Known { + USER, + TENANT_USER, + } + + /** + * An enum containing [UserType]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [UserType] can contain an unknown value in a couple of cases: + * - It was deserialized from data that doesn't match any known member. For example, if the + * SDK is on an older version than the API, then the API may respond with new members that + * the SDK is unaware of. + * - It was constructed with an arbitrary value using the [of] method. + */ + enum class Value { + USER, + TENANT_USER, + /** An enum member indicating that [UserType] was instantiated with an unknown value. */ + _UNKNOWN, + } + + /** + * Returns an enum member corresponding to this class instance's value, or [Value._UNKNOWN] + * if the class was instantiated with an unknown value. + * + * Use the [known] method instead if you're certain the value is always known or if you want + * to throw for the unknown case. + */ + fun value(): Value = + when (this) { + USER -> Value.USER + TENANT_USER -> Value.TENANT_USER + else -> Value._UNKNOWN + } + + /** + * Returns an enum member corresponding to this class instance's value. + * + * Use the [value] method instead if you're uncertain the value is always known and don't + * want to throw for the unknown case. + * + * @throws OpenAIInvalidDataException if this class instance's value is a not a known + * member. + */ + fun known(): Known = + when (this) { + USER -> Known.USER + TENANT_USER -> Known.TENANT_USER + else -> throw OpenAIInvalidDataException("Unknown UserType: $value") + } + + /** + * Returns this class instance's primitive wire representation. + * + * This differs from the [toString] method because that method is primarily for debugging + * and generally doesn't throw. + * + * @throws OpenAIInvalidDataException if this class instance's value does not have the + * expected primitive type. + */ + fun asString(): String = + _value().asString().orElseThrow { OpenAIInvalidDataException("Value is not a String") } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing fields. + * + * @throws OpenAIInvalidDataException if any value type in this object doesn't match its + * expected type. + */ + fun validate(): UserType = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OpenAIInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is UserType && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is UserRetrieveResponse && + id == other.id && + email == other.email && + isServiceAccount == other.isServiceAccount && + name == other.name && + picture == other.picture && + userType == other.userType && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(id, email, isServiceAccount, name, picture, userType, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "UserRetrieveResponse{id=$id, email=$email, isServiceAccount=$isServiceAccount, name=$name, picture=$picture, userType=$userType, additionalProperties=$additionalProperties}" +} diff --git a/openai-java-core/src/main/kotlin/com/openai/models/admin/organization/projects/dataretention/DataRetentionRetrieveParams.kt b/openai-java-core/src/main/kotlin/com/openai/models/admin/organization/projects/dataretention/DataRetentionRetrieveParams.kt new file mode 100644 index 000000000..44a2be796 --- /dev/null +++ b/openai-java-core/src/main/kotlin/com/openai/models/admin/organization/projects/dataretention/DataRetentionRetrieveParams.kt @@ -0,0 +1,195 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.models.admin.organization.projects.dataretention + +import com.openai.core.Params +import com.openai.core.http.Headers +import com.openai.core.http.QueryParams +import java.util.Objects +import java.util.Optional +import kotlin.jvm.optionals.getOrNull + +/** Retrieves project data retention controls. */ +class DataRetentionRetrieveParams +private constructor( + private val projectId: String?, + private val additionalHeaders: Headers, + private val additionalQueryParams: QueryParams, +) : Params { + + fun projectId(): Optional = Optional.ofNullable(projectId) + + /** Additional headers to send with the request. */ + fun _additionalHeaders(): Headers = additionalHeaders + + /** Additional query param to send with the request. */ + fun _additionalQueryParams(): QueryParams = additionalQueryParams + + fun toBuilder() = Builder().from(this) + + companion object { + + @JvmStatic fun none(): DataRetentionRetrieveParams = builder().build() + + /** + * Returns a mutable builder for constructing an instance of [DataRetentionRetrieveParams]. + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [DataRetentionRetrieveParams]. */ + class Builder internal constructor() { + + private var projectId: String? = null + private var additionalHeaders: Headers.Builder = Headers.builder() + private var additionalQueryParams: QueryParams.Builder = QueryParams.builder() + + @JvmSynthetic + internal fun from(dataRetentionRetrieveParams: DataRetentionRetrieveParams) = apply { + projectId = dataRetentionRetrieveParams.projectId + additionalHeaders = dataRetentionRetrieveParams.additionalHeaders.toBuilder() + additionalQueryParams = dataRetentionRetrieveParams.additionalQueryParams.toBuilder() + } + + fun projectId(projectId: String?) = apply { this.projectId = projectId } + + /** Alias for calling [Builder.projectId] with `projectId.orElse(null)`. */ + fun projectId(projectId: Optional) = projectId(projectId.getOrNull()) + + 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 [DataRetentionRetrieveParams]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): DataRetentionRetrieveParams = + DataRetentionRetrieveParams( + projectId, + additionalHeaders.build(), + additionalQueryParams.build(), + ) + } + + 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 + } + + return other is DataRetentionRetrieveParams && + projectId == other.projectId && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams + } + + override fun hashCode(): Int = Objects.hash(projectId, additionalHeaders, additionalQueryParams) + + override fun toString() = + "DataRetentionRetrieveParams{projectId=$projectId, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" +} diff --git a/openai-java-core/src/main/kotlin/com/openai/models/admin/organization/projects/dataretention/DataRetentionUpdateParams.kt b/openai-java-core/src/main/kotlin/com/openai/models/admin/organization/projects/dataretention/DataRetentionUpdateParams.kt new file mode 100644 index 000000000..2abc75258 --- /dev/null +++ b/openai-java-core/src/main/kotlin/com/openai/models/admin/organization/projects/dataretention/DataRetentionUpdateParams.kt @@ -0,0 +1,628 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.models.admin.organization.projects.dataretention + +import com.fasterxml.jackson.annotation.JsonAnyGetter +import com.fasterxml.jackson.annotation.JsonAnySetter +import com.fasterxml.jackson.annotation.JsonCreator +import com.fasterxml.jackson.annotation.JsonProperty +import com.openai.core.Enum +import com.openai.core.ExcludeMissing +import com.openai.core.JsonField +import com.openai.core.JsonMissing +import com.openai.core.JsonValue +import com.openai.core.Params +import com.openai.core.checkRequired +import com.openai.core.http.Headers +import com.openai.core.http.QueryParams +import com.openai.errors.OpenAIInvalidDataException +import java.util.Collections +import java.util.Objects +import java.util.Optional +import kotlin.jvm.optionals.getOrNull + +/** Updates project data retention controls. */ +class DataRetentionUpdateParams +private constructor( + private val projectId: String?, + private val body: Body, + private val additionalHeaders: Headers, + private val additionalQueryParams: QueryParams, +) : Params { + + fun projectId(): Optional = Optional.ofNullable(projectId) + + /** + * The desired project data retention type. + * + * @throws OpenAIInvalidDataException 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 retentionType(): RetentionType = body.retentionType() + + /** + * Returns the raw JSON value of [retentionType]. + * + * Unlike [retentionType], this method doesn't throw if the JSON field has an unexpected type. + */ + fun _retentionType(): JsonField = body._retentionType() + + fun _additionalBodyProperties(): Map = body._additionalProperties() + + /** Additional headers to send with the request. */ + fun _additionalHeaders(): Headers = additionalHeaders + + /** Additional query param to send with the request. */ + fun _additionalQueryParams(): QueryParams = additionalQueryParams + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of [DataRetentionUpdateParams]. + * + * The following fields are required: + * ```java + * .retentionType() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [DataRetentionUpdateParams]. */ + 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 from(dataRetentionUpdateParams: DataRetentionUpdateParams) = apply { + projectId = dataRetentionUpdateParams.projectId + body = dataRetentionUpdateParams.body.toBuilder() + additionalHeaders = dataRetentionUpdateParams.additionalHeaders.toBuilder() + additionalQueryParams = dataRetentionUpdateParams.additionalQueryParams.toBuilder() + } + + fun projectId(projectId: String?) = apply { this.projectId = projectId } + + /** Alias for calling [Builder.projectId] with `projectId.orElse(null)`. */ + fun projectId(projectId: Optional) = projectId(projectId.getOrNull()) + + /** + * Sets the entire request body. + * + * This is generally only useful if you are already constructing the body separately. + * Otherwise, it's more convenient to use the top-level setters instead: + * - [retentionType] + */ + fun body(body: Body) = apply { this.body = body.toBuilder() } + + /** The desired project data retention type. */ + fun retentionType(retentionType: RetentionType) = apply { + body.retentionType(retentionType) + } + + /** + * Sets [Builder.retentionType] to an arbitrary JSON value. + * + * You should usually call [Builder.retentionType] with a well-typed [RetentionType] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun retentionType(retentionType: JsonField) = apply { + body.retentionType(retentionType) + } + + 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 [DataRetentionUpdateParams]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .retentionType() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): DataRetentionUpdateParams = + DataRetentionUpdateParams( + projectId, + body.build(), + additionalHeaders.build(), + additionalQueryParams.build(), + ) + } + + fun _body(): Body = body + + fun _pathParam(index: Int): String = + when (index) { + 0 -> projectId ?: "" + else -> "" + } + + override fun _headers(): Headers = additionalHeaders + + override fun _queryParams(): QueryParams = additionalQueryParams + + /** Parameters for updating project data retention controls. */ + class Body + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val retentionType: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("retention_type") + @ExcludeMissing + retentionType: JsonField = JsonMissing.of() + ) : this(retentionType, mutableMapOf()) + + /** + * The desired project data retention type. + * + * @throws OpenAIInvalidDataException 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 retentionType(): RetentionType = retentionType.getRequired("retention_type") + + /** + * Returns the raw JSON value of [retentionType]. + * + * Unlike [retentionType], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("retention_type") + @ExcludeMissing + fun _retentionType(): JsonField = retentionType + + @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 + * .retentionType() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [Body]. */ + class Builder internal constructor() { + + private var retentionType: JsonField? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(body: Body) = apply { + retentionType = body.retentionType + additionalProperties = body.additionalProperties.toMutableMap() + } + + /** The desired project data retention type. */ + fun retentionType(retentionType: RetentionType) = + retentionType(JsonField.of(retentionType)) + + /** + * Sets [Builder.retentionType] to an arbitrary JSON value. + * + * You should usually call [Builder.retentionType] with a well-typed [RetentionType] + * value instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun retentionType(retentionType: JsonField) = apply { + this.retentionType = retentionType + } + + 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 + * .retentionType() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): Body = + Body( + checkRequired("retentionType", retentionType), + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing fields. + * + * @throws OpenAIInvalidDataException if any value type in this object doesn't match its + * expected type. + */ + fun validate(): Body = apply { + if (validated) { + return@apply + } + + retentionType().validate() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OpenAIInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = (retentionType.asKnown().getOrNull()?.validity() ?: 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Body && + retentionType == other.retentionType && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(retentionType, additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Body{retentionType=$retentionType, additionalProperties=$additionalProperties}" + } + + /** The desired project data retention type. */ + class RetentionType @JsonCreator private constructor(private val value: JsonField) : + Enum { + + /** + * Returns this class instance's raw value. + * + * This is usually only useful if this instance was deserialized from data that doesn't + * match any known member, and you want to know that value. For example, if the SDK is on an + * older version than the API, then the API may respond with new members that the SDK is + * unaware of. + */ + @com.fasterxml.jackson.annotation.JsonValue fun _value(): JsonField = value + + companion object { + + @JvmField val ORGANIZATION_DEFAULT = of("organization_default") + + @JvmField val NONE = of("none") + + @JvmField val ZERO_DATA_RETENTION = of("zero_data_retention") + + @JvmField val MODIFIED_ABUSE_MONITORING = of("modified_abuse_monitoring") + + @JvmField val ENHANCED_ZERO_DATA_RETENTION = of("enhanced_zero_data_retention") + + @JvmField + val ENHANCED_MODIFIED_ABUSE_MONITORING = of("enhanced_modified_abuse_monitoring") + + @JvmStatic fun of(value: String) = RetentionType(JsonField.of(value)) + } + + /** An enum containing [RetentionType]'s known values. */ + enum class Known { + ORGANIZATION_DEFAULT, + NONE, + ZERO_DATA_RETENTION, + MODIFIED_ABUSE_MONITORING, + ENHANCED_ZERO_DATA_RETENTION, + ENHANCED_MODIFIED_ABUSE_MONITORING, + } + + /** + * An enum containing [RetentionType]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [RetentionType] can contain an unknown value in a couple of cases: + * - It was deserialized from data that doesn't match any known member. For example, if the + * SDK is on an older version than the API, then the API may respond with new members that + * the SDK is unaware of. + * - It was constructed with an arbitrary value using the [of] method. + */ + enum class Value { + ORGANIZATION_DEFAULT, + NONE, + ZERO_DATA_RETENTION, + MODIFIED_ABUSE_MONITORING, + ENHANCED_ZERO_DATA_RETENTION, + ENHANCED_MODIFIED_ABUSE_MONITORING, + /** + * An enum member indicating that [RetentionType] was instantiated with an unknown + * value. + */ + _UNKNOWN, + } + + /** + * Returns an enum member corresponding to this class instance's value, or [Value._UNKNOWN] + * if the class was instantiated with an unknown value. + * + * Use the [known] method instead if you're certain the value is always known or if you want + * to throw for the unknown case. + */ + fun value(): Value = + when (this) { + ORGANIZATION_DEFAULT -> Value.ORGANIZATION_DEFAULT + NONE -> Value.NONE + ZERO_DATA_RETENTION -> Value.ZERO_DATA_RETENTION + MODIFIED_ABUSE_MONITORING -> Value.MODIFIED_ABUSE_MONITORING + ENHANCED_ZERO_DATA_RETENTION -> Value.ENHANCED_ZERO_DATA_RETENTION + ENHANCED_MODIFIED_ABUSE_MONITORING -> Value.ENHANCED_MODIFIED_ABUSE_MONITORING + else -> Value._UNKNOWN + } + + /** + * Returns an enum member corresponding to this class instance's value. + * + * Use the [value] method instead if you're uncertain the value is always known and don't + * want to throw for the unknown case. + * + * @throws OpenAIInvalidDataException if this class instance's value is a not a known + * member. + */ + fun known(): Known = + when (this) { + ORGANIZATION_DEFAULT -> Known.ORGANIZATION_DEFAULT + NONE -> Known.NONE + ZERO_DATA_RETENTION -> Known.ZERO_DATA_RETENTION + MODIFIED_ABUSE_MONITORING -> Known.MODIFIED_ABUSE_MONITORING + ENHANCED_ZERO_DATA_RETENTION -> Known.ENHANCED_ZERO_DATA_RETENTION + ENHANCED_MODIFIED_ABUSE_MONITORING -> Known.ENHANCED_MODIFIED_ABUSE_MONITORING + else -> throw OpenAIInvalidDataException("Unknown RetentionType: $value") + } + + /** + * Returns this class instance's primitive wire representation. + * + * This differs from the [toString] method because that method is primarily for debugging + * and generally doesn't throw. + * + * @throws OpenAIInvalidDataException if this class instance's value does not have the + * expected primitive type. + */ + fun asString(): String = + _value().asString().orElseThrow { OpenAIInvalidDataException("Value is not a String") } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing fields. + * + * @throws OpenAIInvalidDataException if any value type in this object doesn't match its + * expected type. + */ + fun validate(): RetentionType = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OpenAIInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is RetentionType && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is DataRetentionUpdateParams && + projectId == other.projectId && + body == other.body && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams + } + + override fun hashCode(): Int = + Objects.hash(projectId, body, additionalHeaders, additionalQueryParams) + + override fun toString() = + "DataRetentionUpdateParams{projectId=$projectId, body=$body, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" +} diff --git a/openai-java-core/src/main/kotlin/com/openai/models/admin/organization/projects/dataretention/ProjectDataRetention.kt b/openai-java-core/src/main/kotlin/com/openai/models/admin/organization/projects/dataretention/ProjectDataRetention.kt new file mode 100644 index 000000000..51be8c906 --- /dev/null +++ b/openai-java-core/src/main/kotlin/com/openai/models/admin/organization/projects/dataretention/ProjectDataRetention.kt @@ -0,0 +1,385 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.models.admin.organization.projects.dataretention + +import com.fasterxml.jackson.annotation.JsonAnyGetter +import com.fasterxml.jackson.annotation.JsonAnySetter +import com.fasterxml.jackson.annotation.JsonCreator +import com.fasterxml.jackson.annotation.JsonProperty +import com.openai.core.Enum +import com.openai.core.ExcludeMissing +import com.openai.core.JsonField +import com.openai.core.JsonMissing +import com.openai.core.JsonValue +import com.openai.core.checkRequired +import com.openai.errors.OpenAIInvalidDataException +import java.util.Collections +import java.util.Objects +import kotlin.jvm.optionals.getOrNull + +/** Represents a project's data retention control setting. */ +class ProjectDataRetention +@JsonCreator(mode = JsonCreator.Mode.DISABLED) +private constructor( + private val object_: JsonValue, + private val type: JsonField, + private val additionalProperties: MutableMap, +) { + + @JsonCreator + private constructor( + @JsonProperty("object") @ExcludeMissing object_: JsonValue = JsonMissing.of(), + @JsonProperty("type") @ExcludeMissing type: JsonField = JsonMissing.of(), + ) : this(object_, type, mutableMapOf()) + + /** + * The object type, which is always `project.data_retention`. + * + * Expected to always return the following: + * ```java + * JsonValue.from("project.data_retention") + * ``` + * + * However, this method can be useful for debugging and logging (e.g. if the server responded + * with an unexpected value). + */ + @JsonProperty("object") @ExcludeMissing fun _object_(): JsonValue = object_ + + /** + * The configured project data retention type. + * + * @throws OpenAIInvalidDataException 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 type(): Type = type.getRequired("type") + + /** + * 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 = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of [ProjectDataRetention]. + * + * The following fields are required: + * ```java + * .type() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [ProjectDataRetention]. */ + class Builder internal constructor() { + + private var object_: JsonValue = JsonValue.from("project.data_retention") + private var type: JsonField? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(projectDataRetention: ProjectDataRetention) = apply { + object_ = projectDataRetention.object_ + type = projectDataRetention.type + additionalProperties = projectDataRetention.additionalProperties.toMutableMap() + } + + /** + * Sets the field to an arbitrary JSON value. + * + * It is usually unnecessary to call this method because the field defaults to the + * following: + * ```java + * JsonValue.from("project.data_retention") + * ``` + * + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun object_(object_: JsonValue) = apply { this.object_ = object_ } + + /** The configured project data retention type. */ + fun type(type: Type) = type(JsonField.of(type)) + + /** + * Sets [Builder.type] to an arbitrary JSON value. + * + * You should usually call [Builder.type] with a well-typed [Type] 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 [ProjectDataRetention]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .type() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): ProjectDataRetention = + ProjectDataRetention( + object_, + checkRequired("type", type), + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected types recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing fields. + * + * @throws OpenAIInvalidDataException if any value type in this object doesn't match its + * expected type. + */ + fun validate(): ProjectDataRetention = apply { + if (validated) { + return@apply + } + + _object_().let { + if (it != JsonValue.from("project.data_retention")) { + throw OpenAIInvalidDataException("'object_' is invalid, received $it") + } + } + type().validate() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OpenAIInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + object_.let { if (it == JsonValue.from("project.data_retention")) 1 else 0 } + + (type.asKnown().getOrNull()?.validity() ?: 0) + + /** The configured project data retention type. */ + class Type @JsonCreator private constructor(private val value: JsonField) : Enum { + + /** + * Returns this class instance's raw value. + * + * This is usually only useful if this instance was deserialized from data that doesn't + * match any known member, and you want to know that value. For example, if the SDK is on an + * older version than the API, then the API may respond with new members that the SDK is + * unaware of. + */ + @com.fasterxml.jackson.annotation.JsonValue fun _value(): JsonField = value + + companion object { + + @JvmField val ORGANIZATION_DEFAULT = of("organization_default") + + @JvmField val NONE = of("none") + + @JvmField val ZERO_DATA_RETENTION = of("zero_data_retention") + + @JvmField val MODIFIED_ABUSE_MONITORING = of("modified_abuse_monitoring") + + @JvmField val ENHANCED_ZERO_DATA_RETENTION = of("enhanced_zero_data_retention") + + @JvmField + val ENHANCED_MODIFIED_ABUSE_MONITORING = of("enhanced_modified_abuse_monitoring") + + @JvmStatic fun of(value: String) = Type(JsonField.of(value)) + } + + /** An enum containing [Type]'s known values. */ + enum class Known { + ORGANIZATION_DEFAULT, + NONE, + ZERO_DATA_RETENTION, + MODIFIED_ABUSE_MONITORING, + ENHANCED_ZERO_DATA_RETENTION, + ENHANCED_MODIFIED_ABUSE_MONITORING, + } + + /** + * An enum containing [Type]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [Type] can contain an unknown value in a couple of cases: + * - It was deserialized from data that doesn't match any known member. For example, if the + * SDK is on an older version than the API, then the API may respond with new members that + * the SDK is unaware of. + * - It was constructed with an arbitrary value using the [of] method. + */ + enum class Value { + ORGANIZATION_DEFAULT, + NONE, + ZERO_DATA_RETENTION, + MODIFIED_ABUSE_MONITORING, + ENHANCED_ZERO_DATA_RETENTION, + ENHANCED_MODIFIED_ABUSE_MONITORING, + /** An enum member indicating that [Type] was instantiated with an unknown value. */ + _UNKNOWN, + } + + /** + * Returns an enum member corresponding to this class instance's value, or [Value._UNKNOWN] + * if the class was instantiated with an unknown value. + * + * Use the [known] method instead if you're certain the value is always known or if you want + * to throw for the unknown case. + */ + fun value(): Value = + when (this) { + ORGANIZATION_DEFAULT -> Value.ORGANIZATION_DEFAULT + NONE -> Value.NONE + ZERO_DATA_RETENTION -> Value.ZERO_DATA_RETENTION + MODIFIED_ABUSE_MONITORING -> Value.MODIFIED_ABUSE_MONITORING + ENHANCED_ZERO_DATA_RETENTION -> Value.ENHANCED_ZERO_DATA_RETENTION + ENHANCED_MODIFIED_ABUSE_MONITORING -> Value.ENHANCED_MODIFIED_ABUSE_MONITORING + else -> Value._UNKNOWN + } + + /** + * Returns an enum member corresponding to this class instance's value. + * + * Use the [value] method instead if you're uncertain the value is always known and don't + * want to throw for the unknown case. + * + * @throws OpenAIInvalidDataException if this class instance's value is a not a known + * member. + */ + fun known(): Known = + when (this) { + ORGANIZATION_DEFAULT -> Known.ORGANIZATION_DEFAULT + NONE -> Known.NONE + ZERO_DATA_RETENTION -> Known.ZERO_DATA_RETENTION + MODIFIED_ABUSE_MONITORING -> Known.MODIFIED_ABUSE_MONITORING + ENHANCED_ZERO_DATA_RETENTION -> Known.ENHANCED_ZERO_DATA_RETENTION + ENHANCED_MODIFIED_ABUSE_MONITORING -> Known.ENHANCED_MODIFIED_ABUSE_MONITORING + else -> throw OpenAIInvalidDataException("Unknown Type: $value") + } + + /** + * Returns this class instance's primitive wire representation. + * + * This differs from the [toString] method because that method is primarily for debugging + * and generally doesn't throw. + * + * @throws OpenAIInvalidDataException if this class instance's value does not have the + * expected primitive type. + */ + fun asString(): String = + _value().asString().orElseThrow { OpenAIInvalidDataException("Value is not a String") } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing fields. + * + * @throws OpenAIInvalidDataException if any value type in this object doesn't match its + * expected type. + */ + fun validate(): Type = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OpenAIInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Type && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is ProjectDataRetention && + object_ == other.object_ && + type == other.type && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(object_, type, additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "ProjectDataRetention{object_=$object_, type=$type, additionalProperties=$additionalProperties}" +} diff --git a/openai-java-core/src/main/kotlin/com/openai/models/admin/organization/projects/groups/GroupRetrieveParams.kt b/openai-java-core/src/main/kotlin/com/openai/models/admin/organization/projects/groups/GroupRetrieveParams.kt new file mode 100644 index 000000000..601c6dc78 --- /dev/null +++ b/openai-java-core/src/main/kotlin/com/openai/models/admin/organization/projects/groups/GroupRetrieveParams.kt @@ -0,0 +1,378 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.models.admin.organization.projects.groups + +import com.fasterxml.jackson.annotation.JsonCreator +import com.openai.core.Enum +import com.openai.core.JsonField +import com.openai.core.Params +import com.openai.core.checkRequired +import com.openai.core.http.Headers +import com.openai.core.http.QueryParams +import com.openai.errors.OpenAIInvalidDataException +import java.util.Objects +import java.util.Optional +import kotlin.jvm.optionals.getOrNull + +/** Retrieves a project's group. */ +class GroupRetrieveParams +private constructor( + private val projectId: String, + private val groupId: String?, + private val groupType: GroupType?, + private val additionalHeaders: Headers, + private val additionalQueryParams: QueryParams, +) : Params { + + fun projectId(): String = projectId + + fun groupId(): Optional = Optional.ofNullable(groupId) + + /** The type of group to retrieve. */ + fun groupType(): Optional = Optional.ofNullable(groupType) + + /** Additional headers to send with the request. */ + fun _additionalHeaders(): Headers = additionalHeaders + + /** Additional query param to send with the request. */ + fun _additionalQueryParams(): QueryParams = additionalQueryParams + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of [GroupRetrieveParams]. + * + * The following fields are required: + * ```java + * .projectId() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [GroupRetrieveParams]. */ + class Builder internal constructor() { + + private var projectId: String? = null + private var groupId: String? = null + private var groupType: GroupType? = null + private var additionalHeaders: Headers.Builder = Headers.builder() + private var additionalQueryParams: QueryParams.Builder = QueryParams.builder() + + @JvmSynthetic + internal fun from(groupRetrieveParams: GroupRetrieveParams) = apply { + projectId = groupRetrieveParams.projectId + groupId = groupRetrieveParams.groupId + groupType = groupRetrieveParams.groupType + additionalHeaders = groupRetrieveParams.additionalHeaders.toBuilder() + additionalQueryParams = groupRetrieveParams.additionalQueryParams.toBuilder() + } + + fun projectId(projectId: String) = apply { this.projectId = projectId } + + fun groupId(groupId: String?) = apply { this.groupId = groupId } + + /** Alias for calling [Builder.groupId] with `groupId.orElse(null)`. */ + fun groupId(groupId: Optional) = groupId(groupId.getOrNull()) + + /** The type of group to retrieve. */ + fun groupType(groupType: GroupType?) = apply { this.groupType = groupType } + + /** Alias for calling [Builder.groupType] with `groupType.orElse(null)`. */ + fun groupType(groupType: Optional) = groupType(groupType.getOrNull()) + + 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 [GroupRetrieveParams]. + * + * 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(): GroupRetrieveParams = + GroupRetrieveParams( + checkRequired("projectId", projectId), + groupId, + groupType, + additionalHeaders.build(), + additionalQueryParams.build(), + ) + } + + fun _pathParam(index: Int): String = + when (index) { + 0 -> projectId + 1 -> groupId ?: "" + else -> "" + } + + override fun _headers(): Headers = additionalHeaders + + override fun _queryParams(): QueryParams = + QueryParams.builder() + .apply { + groupType?.let { put("group_type", it.toString()) } + putAll(additionalQueryParams) + } + .build() + + /** The type of group to retrieve. */ + class GroupType @JsonCreator private constructor(private val value: JsonField) : Enum { + + /** + * Returns this class instance's raw value. + * + * This is usually only useful if this instance was deserialized from data that doesn't + * match any known member, and you want to know that value. For example, if the SDK is on an + * older version than the API, then the API may respond with new members that the SDK is + * unaware of. + */ + @com.fasterxml.jackson.annotation.JsonValue fun _value(): JsonField = value + + companion object { + + @JvmField val GROUP = of("group") + + @JvmField val TENANT_GROUP = of("tenant_group") + + @JvmStatic fun of(value: String) = GroupType(JsonField.of(value)) + } + + /** An enum containing [GroupType]'s known values. */ + enum class Known { + GROUP, + TENANT_GROUP, + } + + /** + * An enum containing [GroupType]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [GroupType] can contain an unknown value in a couple of cases: + * - It was deserialized from data that doesn't match any known member. For example, if the + * SDK is on an older version than the API, then the API may respond with new members that + * the SDK is unaware of. + * - It was constructed with an arbitrary value using the [of] method. + */ + enum class Value { + GROUP, + TENANT_GROUP, + /** + * An enum member indicating that [GroupType] was instantiated with an unknown value. + */ + _UNKNOWN, + } + + /** + * Returns an enum member corresponding to this class instance's value, or [Value._UNKNOWN] + * if the class was instantiated with an unknown value. + * + * Use the [known] method instead if you're certain the value is always known or if you want + * to throw for the unknown case. + */ + fun value(): Value = + when (this) { + GROUP -> Value.GROUP + TENANT_GROUP -> Value.TENANT_GROUP + else -> Value._UNKNOWN + } + + /** + * Returns an enum member corresponding to this class instance's value. + * + * Use the [value] method instead if you're uncertain the value is always known and don't + * want to throw for the unknown case. + * + * @throws OpenAIInvalidDataException if this class instance's value is a not a known + * member. + */ + fun known(): Known = + when (this) { + GROUP -> Known.GROUP + TENANT_GROUP -> Known.TENANT_GROUP + else -> throw OpenAIInvalidDataException("Unknown GroupType: $value") + } + + /** + * Returns this class instance's primitive wire representation. + * + * This differs from the [toString] method because that method is primarily for debugging + * and generally doesn't throw. + * + * @throws OpenAIInvalidDataException if this class instance's value does not have the + * expected primitive type. + */ + fun asString(): String = + _value().asString().orElseThrow { OpenAIInvalidDataException("Value is not a String") } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing fields. + * + * @throws OpenAIInvalidDataException if any value type in this object doesn't match its + * expected type. + */ + fun validate(): GroupType = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OpenAIInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is GroupType && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is GroupRetrieveParams && + projectId == other.projectId && + groupId == other.groupId && + groupType == other.groupType && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams + } + + override fun hashCode(): Int = + Objects.hash(projectId, groupId, groupType, additionalHeaders, additionalQueryParams) + + override fun toString() = + "GroupRetrieveParams{projectId=$projectId, groupId=$groupId, groupType=$groupType, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" +} diff --git a/openai-java-core/src/main/kotlin/com/openai/models/admin/organization/projects/groups/ProjectGroup.kt b/openai-java-core/src/main/kotlin/com/openai/models/admin/organization/projects/groups/ProjectGroup.kt index d1ac52444..347201479 100644 --- a/openai-java-core/src/main/kotlin/com/openai/models/admin/organization/projects/groups/ProjectGroup.kt +++ b/openai-java-core/src/main/kotlin/com/openai/models/admin/organization/projects/groups/ProjectGroup.kt @@ -6,6 +6,7 @@ import com.fasterxml.jackson.annotation.JsonAnyGetter import com.fasterxml.jackson.annotation.JsonAnySetter import com.fasterxml.jackson.annotation.JsonCreator import com.fasterxml.jackson.annotation.JsonProperty +import com.openai.core.Enum import com.openai.core.ExcludeMissing import com.openai.core.JsonField import com.openai.core.JsonMissing @@ -14,6 +15,7 @@ import com.openai.core.checkRequired import com.openai.errors.OpenAIInvalidDataException import java.util.Collections import java.util.Objects +import kotlin.jvm.optionals.getOrNull /** Details about a group's membership in a project. */ class ProjectGroup @@ -22,7 +24,7 @@ private constructor( private val createdAt: JsonField, private val groupId: JsonField, private val groupName: JsonField, - private val groupType: JsonField, + private val groupType: JsonField, private val object_: JsonValue, private val projectId: JsonField, private val additionalProperties: MutableMap, @@ -33,7 +35,9 @@ private constructor( @JsonProperty("created_at") @ExcludeMissing createdAt: JsonField = JsonMissing.of(), @JsonProperty("group_id") @ExcludeMissing groupId: JsonField = JsonMissing.of(), @JsonProperty("group_name") @ExcludeMissing groupName: JsonField = JsonMissing.of(), - @JsonProperty("group_type") @ExcludeMissing groupType: JsonField = JsonMissing.of(), + @JsonProperty("group_type") + @ExcludeMissing + groupType: JsonField = JsonMissing.of(), @JsonProperty("object") @ExcludeMissing object_: JsonValue = JsonMissing.of(), @JsonProperty("project_id") @ExcludeMissing projectId: JsonField = JsonMissing.of(), ) : this(createdAt, groupId, groupName, groupType, object_, projectId, mutableMapOf()) @@ -68,7 +72,7 @@ private constructor( * @throws OpenAIInvalidDataException 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 groupType(): String = groupType.getRequired("group_type") + fun groupType(): GroupType = groupType.getRequired("group_type") /** * Always `project.group`. @@ -117,7 +121,7 @@ private constructor( * * Unlike [groupType], this method doesn't throw if the JSON field has an unexpected type. */ - @JsonProperty("group_type") @ExcludeMissing fun _groupType(): JsonField = groupType + @JsonProperty("group_type") @ExcludeMissing fun _groupType(): JsonField = groupType /** * Returns the raw JSON value of [projectId]. @@ -161,7 +165,7 @@ private constructor( private var createdAt: JsonField? = null private var groupId: JsonField? = null private var groupName: JsonField? = null - private var groupType: JsonField? = null + private var groupType: JsonField? = null private var object_: JsonValue = JsonValue.from("project.group") private var projectId: JsonField? = null private var additionalProperties: MutableMap = mutableMapOf() @@ -212,16 +216,16 @@ private constructor( fun groupName(groupName: JsonField) = apply { this.groupName = groupName } /** The type of the group. */ - fun groupType(groupType: String) = groupType(JsonField.of(groupType)) + fun groupType(groupType: GroupType) = groupType(JsonField.of(groupType)) /** * Sets [Builder.groupType] to an arbitrary JSON value. * - * You should usually call [Builder.groupType] with a well-typed [String] value instead. + * You should usually call [Builder.groupType] with a well-typed [GroupType] value instead. * This method is primarily for setting the field to an undocumented or not yet supported * value. */ - fun groupType(groupType: JsonField) = apply { this.groupType = groupType } + fun groupType(groupType: JsonField) = apply { this.groupType = groupType } /** * Sets the field to an arbitrary JSON value. @@ -314,7 +318,7 @@ private constructor( createdAt() groupId() groupName() - groupType() + groupType().validate() _object_().let { if (it != JsonValue.from("project.group")) { throw OpenAIInvalidDataException("'object_' is invalid, received $it") @@ -342,10 +346,147 @@ private constructor( (if (createdAt.asKnown().isPresent) 1 else 0) + (if (groupId.asKnown().isPresent) 1 else 0) + (if (groupName.asKnown().isPresent) 1 else 0) + - (if (groupType.asKnown().isPresent) 1 else 0) + + (groupType.asKnown().getOrNull()?.validity() ?: 0) + object_.let { if (it == JsonValue.from("project.group")) 1 else 0 } + (if (projectId.asKnown().isPresent) 1 else 0) + /** The type of the group. */ + class GroupType @JsonCreator private constructor(private val value: JsonField) : Enum { + + /** + * Returns this class instance's raw value. + * + * This is usually only useful if this instance was deserialized from data that doesn't + * match any known member, and you want to know that value. For example, if the SDK is on an + * older version than the API, then the API may respond with new members that the SDK is + * unaware of. + */ + @com.fasterxml.jackson.annotation.JsonValue fun _value(): JsonField = value + + companion object { + + @JvmField val GROUP = of("group") + + @JvmField val TENANT_GROUP = of("tenant_group") + + @JvmStatic fun of(value: String) = GroupType(JsonField.of(value)) + } + + /** An enum containing [GroupType]'s known values. */ + enum class Known { + GROUP, + TENANT_GROUP, + } + + /** + * An enum containing [GroupType]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [GroupType] can contain an unknown value in a couple of cases: + * - It was deserialized from data that doesn't match any known member. For example, if the + * SDK is on an older version than the API, then the API may respond with new members that + * the SDK is unaware of. + * - It was constructed with an arbitrary value using the [of] method. + */ + enum class Value { + GROUP, + TENANT_GROUP, + /** + * An enum member indicating that [GroupType] was instantiated with an unknown value. + */ + _UNKNOWN, + } + + /** + * Returns an enum member corresponding to this class instance's value, or [Value._UNKNOWN] + * if the class was instantiated with an unknown value. + * + * Use the [known] method instead if you're certain the value is always known or if you want + * to throw for the unknown case. + */ + fun value(): Value = + when (this) { + GROUP -> Value.GROUP + TENANT_GROUP -> Value.TENANT_GROUP + else -> Value._UNKNOWN + } + + /** + * Returns an enum member corresponding to this class instance's value. + * + * Use the [value] method instead if you're uncertain the value is always known and don't + * want to throw for the unknown case. + * + * @throws OpenAIInvalidDataException if this class instance's value is a not a known + * member. + */ + fun known(): Known = + when (this) { + GROUP -> Known.GROUP + TENANT_GROUP -> Known.TENANT_GROUP + else -> throw OpenAIInvalidDataException("Unknown GroupType: $value") + } + + /** + * Returns this class instance's primitive wire representation. + * + * This differs from the [toString] method because that method is primarily for debugging + * and generally doesn't throw. + * + * @throws OpenAIInvalidDataException if this class instance's value does not have the + * expected primitive type. + */ + fun asString(): String = + _value().asString().orElseThrow { OpenAIInvalidDataException("Value is not a String") } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing fields. + * + * @throws OpenAIInvalidDataException if any value type in this object doesn't match its + * expected type. + */ + fun validate(): GroupType = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OpenAIInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is GroupType && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + override fun equals(other: Any?): Boolean { if (this === other) { return true diff --git a/openai-java-core/src/main/kotlin/com/openai/models/admin/organization/projects/groups/roles/RoleListResponse.kt b/openai-java-core/src/main/kotlin/com/openai/models/admin/organization/projects/groups/roles/RoleListResponse.kt index 76aa79864..f626700ad 100644 --- a/openai-java-core/src/main/kotlin/com/openai/models/admin/organization/projects/groups/roles/RoleListResponse.kt +++ b/openai-java-core/src/main/kotlin/com/openai/models/admin/organization/projects/groups/roles/RoleListResponse.kt @@ -24,6 +24,7 @@ class RoleListResponse @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val id: JsonField, + private val assignmentSources: JsonField>, private val createdAt: JsonField, private val createdBy: JsonField, private val createdByUserObj: JsonField, @@ -40,6 +41,9 @@ private constructor( @JsonCreator private constructor( @JsonProperty("id") @ExcludeMissing id: JsonField = JsonMissing.of(), + @JsonProperty("assignment_sources") + @ExcludeMissing + assignmentSources: JsonField> = JsonMissing.of(), @JsonProperty("created_at") @ExcludeMissing createdAt: JsonField = JsonMissing.of(), @JsonProperty("created_by") @ExcludeMissing createdBy: JsonField = JsonMissing.of(), @JsonProperty("created_by_user_obj") @@ -62,6 +66,7 @@ private constructor( @JsonProperty("updated_at") @ExcludeMissing updatedAt: JsonField = JsonMissing.of(), ) : this( id, + assignmentSources, createdAt, createdBy, createdByUserObj, @@ -83,6 +88,15 @@ private constructor( */ fun id(): String = id.getRequired("id") + /** + * Principals from which the role assignment is inherited, when available. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun assignmentSources(): Optional> = + assignmentSources.getOptional("assignment_sources") + /** * When the role was created. * @@ -171,6 +185,16 @@ private constructor( */ @JsonProperty("id") @ExcludeMissing fun _id(): JsonField = id + /** + * Returns the raw JSON value of [assignmentSources]. + * + * Unlike [assignmentSources], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("assignment_sources") + @ExcludeMissing + fun _assignmentSources(): JsonField> = assignmentSources + /** * Returns the raw JSON value of [createdAt]. * @@ -270,6 +294,7 @@ private constructor( * The following fields are required: * ```java * .id() + * .assignmentSources() * .createdAt() * .createdBy() * .createdByUserObj() @@ -289,6 +314,7 @@ private constructor( class Builder internal constructor() { private var id: JsonField? = null + private var assignmentSources: JsonField>? = null private var createdAt: JsonField? = null private var createdBy: JsonField? = null private var createdByUserObj: JsonField? = null @@ -304,6 +330,7 @@ private constructor( @JvmSynthetic internal fun from(roleListResponse: RoleListResponse) = apply { id = roleListResponse.id + assignmentSources = roleListResponse.assignmentSources.map { it.toMutableList() } createdAt = roleListResponse.createdAt createdBy = roleListResponse.createdBy createdByUserObj = roleListResponse.createdByUserObj @@ -328,6 +355,37 @@ private constructor( */ fun id(id: JsonField) = apply { this.id = id } + /** Principals from which the role assignment is inherited, when available. */ + fun assignmentSources(assignmentSources: List?) = + assignmentSources(JsonField.ofNullable(assignmentSources)) + + /** Alias for calling [Builder.assignmentSources] with `assignmentSources.orElse(null)`. */ + fun assignmentSources(assignmentSources: Optional>) = + assignmentSources(assignmentSources.getOrNull()) + + /** + * Sets [Builder.assignmentSources] to an arbitrary JSON value. + * + * You should usually call [Builder.assignmentSources] with a well-typed + * `List` value instead. This method is primarily for setting the field to + * an undocumented or not yet supported value. + */ + fun assignmentSources(assignmentSources: JsonField>) = apply { + this.assignmentSources = assignmentSources.map { it.toMutableList() } + } + + /** + * Adds a single [AssignmentSource] to [assignmentSources]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addAssignmentSource(assignmentSource: AssignmentSource) = apply { + assignmentSources = + (assignmentSources ?: JsonField.of(mutableListOf())).also { + checkKnown("assignmentSources", it).add(assignmentSource) + } + } + /** When the role was created. */ fun createdAt(createdAt: Long?) = createdAt(JsonField.ofNullable(createdAt)) @@ -526,6 +584,7 @@ private constructor( * The following fields are required: * ```java * .id() + * .assignmentSources() * .createdAt() * .createdBy() * .createdByUserObj() @@ -543,6 +602,7 @@ private constructor( fun build(): RoleListResponse = RoleListResponse( checkRequired("id", id), + checkRequired("assignmentSources", assignmentSources).map { it.toImmutable() }, checkRequired("createdAt", createdAt), checkRequired("createdBy", createdBy), checkRequired("createdByUserObj", createdByUserObj), @@ -573,6 +633,7 @@ private constructor( } id() + assignmentSources().ifPresent { it.forEach { it.validate() } } createdAt() createdBy() createdByUserObj().ifPresent { it.validate() } @@ -602,6 +663,7 @@ private constructor( @JvmSynthetic internal fun validity(): Int = (if (id.asKnown().isPresent) 1 else 0) + + (assignmentSources.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + (if (createdAt.asKnown().isPresent) 1 else 0) + (if (createdBy.asKnown().isPresent) 1 else 0) + (createdByUserObj.asKnown().getOrNull()?.validity() ?: 0) + @@ -613,6 +675,222 @@ private constructor( (if (resourceType.asKnown().isPresent) 1 else 0) + (if (updatedAt.asKnown().isPresent) 1 else 0) + class AssignmentSource + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val principalId: JsonField, + private val principalType: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("principal_id") + @ExcludeMissing + principalId: JsonField = JsonMissing.of(), + @JsonProperty("principal_type") + @ExcludeMissing + principalType: JsonField = JsonMissing.of(), + ) : this(principalId, principalType, mutableMapOf()) + + /** + * @throws OpenAIInvalidDataException 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 principalId(): String = principalId.getRequired("principal_id") + + /** + * @throws OpenAIInvalidDataException 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 principalType(): String = principalType.getRequired("principal_type") + + /** + * Returns the raw JSON value of [principalId]. + * + * Unlike [principalId], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("principal_id") + @ExcludeMissing + fun _principalId(): JsonField = principalId + + /** + * Returns the raw JSON value of [principalType]. + * + * Unlike [principalType], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("principal_type") + @ExcludeMissing + fun _principalType(): JsonField = principalType + + @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 [AssignmentSource]. + * + * The following fields are required: + * ```java + * .principalId() + * .principalType() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [AssignmentSource]. */ + class Builder internal constructor() { + + private var principalId: JsonField? = null + private var principalType: JsonField? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(assignmentSource: AssignmentSource) = apply { + principalId = assignmentSource.principalId + principalType = assignmentSource.principalType + additionalProperties = assignmentSource.additionalProperties.toMutableMap() + } + + fun principalId(principalId: String) = principalId(JsonField.of(principalId)) + + /** + * Sets [Builder.principalId] to an arbitrary JSON value. + * + * You should usually call [Builder.principalId] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun principalId(principalId: JsonField) = apply { + this.principalId = principalId + } + + fun principalType(principalType: String) = principalType(JsonField.of(principalType)) + + /** + * Sets [Builder.principalType] to an arbitrary JSON value. + * + * You should usually call [Builder.principalType] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun principalType(principalType: JsonField) = apply { + this.principalType = principalType + } + + 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 [AssignmentSource]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .principalId() + * .principalType() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): AssignmentSource = + AssignmentSource( + checkRequired("principalId", principalId), + checkRequired("principalType", principalType), + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing fields. + * + * @throws OpenAIInvalidDataException if any value type in this object doesn't match its + * expected type. + */ + fun validate(): AssignmentSource = apply { + if (validated) { + return@apply + } + + principalId() + principalType() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OpenAIInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (if (principalId.asKnown().isPresent) 1 else 0) + + (if (principalType.asKnown().isPresent) 1 else 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is AssignmentSource && + principalId == other.principalId && + principalType == other.principalType && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(principalId, principalType, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "AssignmentSource{principalId=$principalId, principalType=$principalType, additionalProperties=$additionalProperties}" + } + /** User details for the actor that created the role, when available. */ class CreatedByUserObj @JsonCreator @@ -838,6 +1116,7 @@ private constructor( return other is RoleListResponse && id == other.id && + assignmentSources == other.assignmentSources && createdAt == other.createdAt && createdBy == other.createdBy && createdByUserObj == other.createdByUserObj && @@ -854,6 +1133,7 @@ private constructor( private val hashCode: Int by lazy { Objects.hash( id, + assignmentSources, createdAt, createdBy, createdByUserObj, @@ -871,5 +1151,5 @@ private constructor( override fun hashCode(): Int = hashCode override fun toString() = - "RoleListResponse{id=$id, createdAt=$createdAt, createdBy=$createdBy, createdByUserObj=$createdByUserObj, description=$description, metadata=$metadata, name=$name, permissions=$permissions, predefinedRole=$predefinedRole, resourceType=$resourceType, updatedAt=$updatedAt, additionalProperties=$additionalProperties}" + "RoleListResponse{id=$id, assignmentSources=$assignmentSources, createdAt=$createdAt, createdBy=$createdBy, createdByUserObj=$createdByUserObj, description=$description, metadata=$metadata, name=$name, permissions=$permissions, predefinedRole=$predefinedRole, resourceType=$resourceType, updatedAt=$updatedAt, additionalProperties=$additionalProperties}" } diff --git a/openai-java-core/src/main/kotlin/com/openai/models/admin/organization/projects/groups/roles/RoleRetrieveParams.kt b/openai-java-core/src/main/kotlin/com/openai/models/admin/organization/projects/groups/roles/RoleRetrieveParams.kt new file mode 100644 index 000000000..8575221a5 --- /dev/null +++ b/openai-java-core/src/main/kotlin/com/openai/models/admin/organization/projects/groups/roles/RoleRetrieveParams.kt @@ -0,0 +1,229 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.models.admin.organization.projects.groups.roles + +import com.openai.core.Params +import com.openai.core.checkRequired +import com.openai.core.http.Headers +import com.openai.core.http.QueryParams +import java.util.Objects +import java.util.Optional +import kotlin.jvm.optionals.getOrNull + +/** Retrieves a project role assigned to a group. */ +class RoleRetrieveParams +private constructor( + private val projectId: String, + private val groupId: String, + private val roleId: String?, + private val additionalHeaders: Headers, + private val additionalQueryParams: QueryParams, +) : Params { + + fun projectId(): String = projectId + + fun groupId(): String = groupId + + fun roleId(): Optional = Optional.ofNullable(roleId) + + /** Additional headers to send with the request. */ + fun _additionalHeaders(): Headers = additionalHeaders + + /** Additional query param to send with the request. */ + fun _additionalQueryParams(): QueryParams = additionalQueryParams + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of [RoleRetrieveParams]. + * + * The following fields are required: + * ```java + * .projectId() + * .groupId() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [RoleRetrieveParams]. */ + class Builder internal constructor() { + + private var projectId: String? = null + private var groupId: String? = null + private var roleId: String? = null + private var additionalHeaders: Headers.Builder = Headers.builder() + private var additionalQueryParams: QueryParams.Builder = QueryParams.builder() + + @JvmSynthetic + internal fun from(roleRetrieveParams: RoleRetrieveParams) = apply { + projectId = roleRetrieveParams.projectId + groupId = roleRetrieveParams.groupId + roleId = roleRetrieveParams.roleId + additionalHeaders = roleRetrieveParams.additionalHeaders.toBuilder() + additionalQueryParams = roleRetrieveParams.additionalQueryParams.toBuilder() + } + + fun projectId(projectId: String) = apply { this.projectId = projectId } + + fun groupId(groupId: String) = apply { this.groupId = groupId } + + fun roleId(roleId: String?) = apply { this.roleId = roleId } + + /** Alias for calling [Builder.roleId] with `roleId.orElse(null)`. */ + fun roleId(roleId: Optional) = roleId(roleId.getOrNull()) + + 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 [RoleRetrieveParams]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .projectId() + * .groupId() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): RoleRetrieveParams = + RoleRetrieveParams( + checkRequired("projectId", projectId), + checkRequired("groupId", groupId), + roleId, + additionalHeaders.build(), + additionalQueryParams.build(), + ) + } + + fun _pathParam(index: Int): String = + when (index) { + 0 -> projectId + 1 -> groupId + 2 -> roleId ?: "" + else -> "" + } + + override fun _headers(): Headers = additionalHeaders + + override fun _queryParams(): QueryParams = additionalQueryParams + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is RoleRetrieveParams && + projectId == other.projectId && + groupId == other.groupId && + roleId == other.roleId && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams + } + + override fun hashCode(): Int = + Objects.hash(projectId, groupId, roleId, additionalHeaders, additionalQueryParams) + + override fun toString() = + "RoleRetrieveParams{projectId=$projectId, groupId=$groupId, roleId=$roleId, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" +} diff --git a/openai-java-core/src/main/kotlin/com/openai/models/admin/organization/projects/groups/roles/RoleRetrieveResponse.kt b/openai-java-core/src/main/kotlin/com/openai/models/admin/organization/projects/groups/roles/RoleRetrieveResponse.kt new file mode 100644 index 000000000..a75dcf63f --- /dev/null +++ b/openai-java-core/src/main/kotlin/com/openai/models/admin/organization/projects/groups/roles/RoleRetrieveResponse.kt @@ -0,0 +1,1155 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.models.admin.organization.projects.groups.roles + +import com.fasterxml.jackson.annotation.JsonAnyGetter +import com.fasterxml.jackson.annotation.JsonAnySetter +import com.fasterxml.jackson.annotation.JsonCreator +import com.fasterxml.jackson.annotation.JsonProperty +import com.openai.core.ExcludeMissing +import com.openai.core.JsonField +import com.openai.core.JsonMissing +import com.openai.core.JsonValue +import com.openai.core.checkKnown +import com.openai.core.checkRequired +import com.openai.core.toImmutable +import com.openai.errors.OpenAIInvalidDataException +import java.util.Collections +import java.util.Objects +import java.util.Optional +import kotlin.jvm.optionals.getOrNull + +/** Detailed information about a role assignment entry returned when listing assignments. */ +class RoleRetrieveResponse +@JsonCreator(mode = JsonCreator.Mode.DISABLED) +private constructor( + private val id: JsonField, + private val assignmentSources: JsonField>, + private val createdAt: JsonField, + private val createdBy: JsonField, + private val createdByUserObj: JsonField, + private val description: JsonField, + private val metadata: JsonField, + private val name: JsonField, + private val permissions: JsonField>, + private val predefinedRole: JsonField, + private val resourceType: JsonField, + private val updatedAt: JsonField, + private val additionalProperties: MutableMap, +) { + + @JsonCreator + private constructor( + @JsonProperty("id") @ExcludeMissing id: JsonField = JsonMissing.of(), + @JsonProperty("assignment_sources") + @ExcludeMissing + assignmentSources: JsonField> = JsonMissing.of(), + @JsonProperty("created_at") @ExcludeMissing createdAt: JsonField = JsonMissing.of(), + @JsonProperty("created_by") @ExcludeMissing createdBy: JsonField = JsonMissing.of(), + @JsonProperty("created_by_user_obj") + @ExcludeMissing + createdByUserObj: 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("permissions") + @ExcludeMissing + permissions: JsonField> = JsonMissing.of(), + @JsonProperty("predefined_role") + @ExcludeMissing + predefinedRole: JsonField = JsonMissing.of(), + @JsonProperty("resource_type") + @ExcludeMissing + resourceType: JsonField = JsonMissing.of(), + @JsonProperty("updated_at") @ExcludeMissing updatedAt: JsonField = JsonMissing.of(), + ) : this( + id, + assignmentSources, + createdAt, + createdBy, + createdByUserObj, + description, + metadata, + name, + permissions, + predefinedRole, + resourceType, + updatedAt, + mutableMapOf(), + ) + + /** + * Identifier for the role. + * + * @throws OpenAIInvalidDataException 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 id(): String = id.getRequired("id") + + /** + * Principals from which the role assignment is inherited, when available. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun assignmentSources(): Optional> = + assignmentSources.getOptional("assignment_sources") + + /** + * When the role was created. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun createdAt(): Optional = createdAt.getOptional("created_at") + + /** + * Identifier of the actor who created the role. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun createdBy(): Optional = createdBy.getOptional("created_by") + + /** + * User details for the actor that created the role, when available. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun createdByUserObj(): Optional = + createdByUserObj.getOptional("created_by_user_obj") + + /** + * Description of the role. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun description(): Optional = description.getOptional("description") + + /** + * Arbitrary metadata stored on the role. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun metadata(): Optional = metadata.getOptional("metadata") + + /** + * Name of the role. + * + * @throws OpenAIInvalidDataException 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") + + /** + * Permissions associated with the role. + * + * @throws OpenAIInvalidDataException 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 permissions(): List = permissions.getRequired("permissions") + + /** + * Whether the role is predefined by OpenAI. + * + * @throws OpenAIInvalidDataException 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 predefinedRole(): Boolean = predefinedRole.getRequired("predefined_role") + + /** + * Resource type the role applies to. + * + * @throws OpenAIInvalidDataException 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 resourceType(): String = resourceType.getRequired("resource_type") + + /** + * When the role was last updated. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun updatedAt(): Optional = updatedAt.getOptional("updated_at") + + /** + * Returns the raw JSON value of [id]. + * + * Unlike [id], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("id") @ExcludeMissing fun _id(): JsonField = id + + /** + * Returns the raw JSON value of [assignmentSources]. + * + * Unlike [assignmentSources], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("assignment_sources") + @ExcludeMissing + fun _assignmentSources(): JsonField> = assignmentSources + + /** + * Returns the raw JSON value of [createdAt]. + * + * Unlike [createdAt], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("created_at") @ExcludeMissing fun _createdAt(): JsonField = createdAt + + /** + * Returns the raw JSON value of [createdBy]. + * + * Unlike [createdBy], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("created_by") @ExcludeMissing fun _createdBy(): JsonField = createdBy + + /** + * Returns the raw JSON value of [createdByUserObj]. + * + * Unlike [createdByUserObj], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("created_by_user_obj") + @ExcludeMissing + fun _createdByUserObj(): JsonField = createdByUserObj + + /** + * 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 + + /** + * Returns the raw JSON value of [permissions]. + * + * Unlike [permissions], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("permissions") + @ExcludeMissing + fun _permissions(): JsonField> = permissions + + /** + * Returns the raw JSON value of [predefinedRole]. + * + * Unlike [predefinedRole], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("predefined_role") + @ExcludeMissing + fun _predefinedRole(): JsonField = predefinedRole + + /** + * Returns the raw JSON value of [resourceType]. + * + * Unlike [resourceType], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("resource_type") + @ExcludeMissing + fun _resourceType(): JsonField = resourceType + + /** + * Returns the raw JSON value of [updatedAt]. + * + * Unlike [updatedAt], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("updated_at") @ExcludeMissing fun _updatedAt(): JsonField = updatedAt + + @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 [RoleRetrieveResponse]. + * + * The following fields are required: + * ```java + * .id() + * .assignmentSources() + * .createdAt() + * .createdBy() + * .createdByUserObj() + * .description() + * .metadata() + * .name() + * .permissions() + * .predefinedRole() + * .resourceType() + * .updatedAt() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [RoleRetrieveResponse]. */ + class Builder internal constructor() { + + private var id: JsonField? = null + private var assignmentSources: JsonField>? = null + private var createdAt: JsonField? = null + private var createdBy: JsonField? = null + private var createdByUserObj: JsonField? = null + private var description: JsonField? = null + private var metadata: JsonField? = null + private var name: JsonField? = null + private var permissions: JsonField>? = null + private var predefinedRole: JsonField? = null + private var resourceType: JsonField? = null + private var updatedAt: JsonField? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(roleRetrieveResponse: RoleRetrieveResponse) = apply { + id = roleRetrieveResponse.id + assignmentSources = roleRetrieveResponse.assignmentSources.map { it.toMutableList() } + createdAt = roleRetrieveResponse.createdAt + createdBy = roleRetrieveResponse.createdBy + createdByUserObj = roleRetrieveResponse.createdByUserObj + description = roleRetrieveResponse.description + metadata = roleRetrieveResponse.metadata + name = roleRetrieveResponse.name + permissions = roleRetrieveResponse.permissions.map { it.toMutableList() } + predefinedRole = roleRetrieveResponse.predefinedRole + resourceType = roleRetrieveResponse.resourceType + updatedAt = roleRetrieveResponse.updatedAt + additionalProperties = roleRetrieveResponse.additionalProperties.toMutableMap() + } + + /** Identifier for the role. */ + fun id(id: String) = id(JsonField.of(id)) + + /** + * Sets [Builder.id] to an arbitrary JSON value. + * + * You should usually call [Builder.id] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun id(id: JsonField) = apply { this.id = id } + + /** Principals from which the role assignment is inherited, when available. */ + fun assignmentSources(assignmentSources: List?) = + assignmentSources(JsonField.ofNullable(assignmentSources)) + + /** Alias for calling [Builder.assignmentSources] with `assignmentSources.orElse(null)`. */ + fun assignmentSources(assignmentSources: Optional>) = + assignmentSources(assignmentSources.getOrNull()) + + /** + * Sets [Builder.assignmentSources] to an arbitrary JSON value. + * + * You should usually call [Builder.assignmentSources] with a well-typed + * `List` value instead. This method is primarily for setting the field to + * an undocumented or not yet supported value. + */ + fun assignmentSources(assignmentSources: JsonField>) = apply { + this.assignmentSources = assignmentSources.map { it.toMutableList() } + } + + /** + * Adds a single [AssignmentSource] to [assignmentSources]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addAssignmentSource(assignmentSource: AssignmentSource) = apply { + assignmentSources = + (assignmentSources ?: JsonField.of(mutableListOf())).also { + checkKnown("assignmentSources", it).add(assignmentSource) + } + } + + /** When the role was created. */ + fun createdAt(createdAt: Long?) = createdAt(JsonField.ofNullable(createdAt)) + + /** + * Alias for [Builder.createdAt]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun createdAt(createdAt: Long) = createdAt(createdAt as Long?) + + /** Alias for calling [Builder.createdAt] with `createdAt.orElse(null)`. */ + fun createdAt(createdAt: Optional) = createdAt(createdAt.getOrNull()) + + /** + * Sets [Builder.createdAt] to an arbitrary JSON value. + * + * You should usually call [Builder.createdAt] with a well-typed [Long] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun createdAt(createdAt: JsonField) = apply { this.createdAt = createdAt } + + /** Identifier of the actor who created the role. */ + fun createdBy(createdBy: String?) = createdBy(JsonField.ofNullable(createdBy)) + + /** Alias for calling [Builder.createdBy] with `createdBy.orElse(null)`. */ + fun createdBy(createdBy: Optional) = createdBy(createdBy.getOrNull()) + + /** + * Sets [Builder.createdBy] to an arbitrary JSON value. + * + * You should usually call [Builder.createdBy] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun createdBy(createdBy: JsonField) = apply { this.createdBy = createdBy } + + /** User details for the actor that created the role, when available. */ + fun createdByUserObj(createdByUserObj: CreatedByUserObj?) = + createdByUserObj(JsonField.ofNullable(createdByUserObj)) + + /** Alias for calling [Builder.createdByUserObj] with `createdByUserObj.orElse(null)`. */ + fun createdByUserObj(createdByUserObj: Optional) = + createdByUserObj(createdByUserObj.getOrNull()) + + /** + * Sets [Builder.createdByUserObj] to an arbitrary JSON value. + * + * You should usually call [Builder.createdByUserObj] with a well-typed [CreatedByUserObj] + * value instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun createdByUserObj(createdByUserObj: JsonField) = apply { + this.createdByUserObj = createdByUserObj + } + + /** 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 } + + /** Arbitrary metadata stored on the role. */ + 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 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 } + + /** Permissions associated with the role. */ + fun permissions(permissions: List) = permissions(JsonField.of(permissions)) + + /** + * Sets [Builder.permissions] to an arbitrary JSON value. + * + * You should usually call [Builder.permissions] with a well-typed `List` value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun permissions(permissions: JsonField>) = apply { + this.permissions = permissions.map { it.toMutableList() } + } + + /** + * Adds a single [String] to [permissions]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addPermission(permission: String) = apply { + permissions = + (permissions ?: JsonField.of(mutableListOf())).also { + checkKnown("permissions", it).add(permission) + } + } + + /** Whether the role is predefined by OpenAI. */ + fun predefinedRole(predefinedRole: Boolean) = predefinedRole(JsonField.of(predefinedRole)) + + /** + * Sets [Builder.predefinedRole] to an arbitrary JSON value. + * + * You should usually call [Builder.predefinedRole] with a well-typed [Boolean] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun predefinedRole(predefinedRole: JsonField) = apply { + this.predefinedRole = predefinedRole + } + + /** Resource type the role applies to. */ + fun resourceType(resourceType: String) = resourceType(JsonField.of(resourceType)) + + /** + * Sets [Builder.resourceType] to an arbitrary JSON value. + * + * You should usually call [Builder.resourceType] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun resourceType(resourceType: JsonField) = apply { + this.resourceType = resourceType + } + + /** When the role was last updated. */ + fun updatedAt(updatedAt: Long?) = updatedAt(JsonField.ofNullable(updatedAt)) + + /** + * Alias for [Builder.updatedAt]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun updatedAt(updatedAt: Long) = updatedAt(updatedAt as Long?) + + /** Alias for calling [Builder.updatedAt] with `updatedAt.orElse(null)`. */ + fun updatedAt(updatedAt: Optional) = updatedAt(updatedAt.getOrNull()) + + /** + * Sets [Builder.updatedAt] to an arbitrary JSON value. + * + * You should usually call [Builder.updatedAt] with a well-typed [Long] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun updatedAt(updatedAt: JsonField) = apply { this.updatedAt = updatedAt } + + 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 [RoleRetrieveResponse]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .id() + * .assignmentSources() + * .createdAt() + * .createdBy() + * .createdByUserObj() + * .description() + * .metadata() + * .name() + * .permissions() + * .predefinedRole() + * .resourceType() + * .updatedAt() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): RoleRetrieveResponse = + RoleRetrieveResponse( + checkRequired("id", id), + checkRequired("assignmentSources", assignmentSources).map { it.toImmutable() }, + checkRequired("createdAt", createdAt), + checkRequired("createdBy", createdBy), + checkRequired("createdByUserObj", createdByUserObj), + checkRequired("description", description), + checkRequired("metadata", metadata), + checkRequired("name", name), + checkRequired("permissions", permissions).map { it.toImmutable() }, + checkRequired("predefinedRole", predefinedRole), + checkRequired("resourceType", resourceType), + checkRequired("updatedAt", updatedAt), + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected types recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing fields. + * + * @throws OpenAIInvalidDataException if any value type in this object doesn't match its + * expected type. + */ + fun validate(): RoleRetrieveResponse = apply { + if (validated) { + return@apply + } + + id() + assignmentSources().ifPresent { it.forEach { it.validate() } } + createdAt() + createdBy() + createdByUserObj().ifPresent { it.validate() } + description() + metadata().ifPresent { it.validate() } + name() + permissions() + predefinedRole() + resourceType() + updatedAt() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OpenAIInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (if (id.asKnown().isPresent) 1 else 0) + + (assignmentSources.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + + (if (createdAt.asKnown().isPresent) 1 else 0) + + (if (createdBy.asKnown().isPresent) 1 else 0) + + (createdByUserObj.asKnown().getOrNull()?.validity() ?: 0) + + (if (description.asKnown().isPresent) 1 else 0) + + (metadata.asKnown().getOrNull()?.validity() ?: 0) + + (if (name.asKnown().isPresent) 1 else 0) + + (permissions.asKnown().getOrNull()?.size ?: 0) + + (if (predefinedRole.asKnown().isPresent) 1 else 0) + + (if (resourceType.asKnown().isPresent) 1 else 0) + + (if (updatedAt.asKnown().isPresent) 1 else 0) + + class AssignmentSource + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val principalId: JsonField, + private val principalType: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("principal_id") + @ExcludeMissing + principalId: JsonField = JsonMissing.of(), + @JsonProperty("principal_type") + @ExcludeMissing + principalType: JsonField = JsonMissing.of(), + ) : this(principalId, principalType, mutableMapOf()) + + /** + * @throws OpenAIInvalidDataException 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 principalId(): String = principalId.getRequired("principal_id") + + /** + * @throws OpenAIInvalidDataException 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 principalType(): String = principalType.getRequired("principal_type") + + /** + * Returns the raw JSON value of [principalId]. + * + * Unlike [principalId], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("principal_id") + @ExcludeMissing + fun _principalId(): JsonField = principalId + + /** + * Returns the raw JSON value of [principalType]. + * + * Unlike [principalType], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("principal_type") + @ExcludeMissing + fun _principalType(): JsonField = principalType + + @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 [AssignmentSource]. + * + * The following fields are required: + * ```java + * .principalId() + * .principalType() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [AssignmentSource]. */ + class Builder internal constructor() { + + private var principalId: JsonField? = null + private var principalType: JsonField? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(assignmentSource: AssignmentSource) = apply { + principalId = assignmentSource.principalId + principalType = assignmentSource.principalType + additionalProperties = assignmentSource.additionalProperties.toMutableMap() + } + + fun principalId(principalId: String) = principalId(JsonField.of(principalId)) + + /** + * Sets [Builder.principalId] to an arbitrary JSON value. + * + * You should usually call [Builder.principalId] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun principalId(principalId: JsonField) = apply { + this.principalId = principalId + } + + fun principalType(principalType: String) = principalType(JsonField.of(principalType)) + + /** + * Sets [Builder.principalType] to an arbitrary JSON value. + * + * You should usually call [Builder.principalType] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun principalType(principalType: JsonField) = apply { + this.principalType = principalType + } + + 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 [AssignmentSource]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .principalId() + * .principalType() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): AssignmentSource = + AssignmentSource( + checkRequired("principalId", principalId), + checkRequired("principalType", principalType), + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing fields. + * + * @throws OpenAIInvalidDataException if any value type in this object doesn't match its + * expected type. + */ + fun validate(): AssignmentSource = apply { + if (validated) { + return@apply + } + + principalId() + principalType() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OpenAIInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (if (principalId.asKnown().isPresent) 1 else 0) + + (if (principalType.asKnown().isPresent) 1 else 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is AssignmentSource && + principalId == other.principalId && + principalType == other.principalType && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(principalId, principalType, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "AssignmentSource{principalId=$principalId, principalType=$principalType, additionalProperties=$additionalProperties}" + } + + /** User details for the actor that created the role, when available. */ + class CreatedByUserObj + @JsonCreator + private constructor( + @com.fasterxml.jackson.annotation.JsonValue + private val additionalProperties: Map + ) { + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = additionalProperties + + fun toBuilder() = Builder().from(this) + + companion object { + + /** Returns a mutable builder for constructing an instance of [CreatedByUserObj]. */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [CreatedByUserObj]. */ + class Builder internal constructor() { + + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(createdByUserObj: CreatedByUserObj) = apply { + additionalProperties = createdByUserObj.additionalProperties.toMutableMap() + } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [CreatedByUserObj]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): CreatedByUserObj = CreatedByUserObj(additionalProperties.toImmutable()) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing fields. + * + * @throws OpenAIInvalidDataException if any value type in this object doesn't match its + * expected type. + */ + fun validate(): CreatedByUserObj = apply { + if (validated) { + return@apply + } + + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OpenAIInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + additionalProperties.count { (_, value) -> !value.isNull() && !value.isMissing() } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is CreatedByUserObj && additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = "CreatedByUserObj{additionalProperties=$additionalProperties}" + } + + /** Arbitrary metadata stored on the role. */ + class Metadata + @JsonCreator + private constructor( + @com.fasterxml.jackson.annotation.JsonValue + private val additionalProperties: Map + ) { + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = additionalProperties + + fun toBuilder() = Builder().from(this) + + companion object { + + /** Returns a mutable builder for constructing an instance of [Metadata]. */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [Metadata]. */ + class Builder internal constructor() { + + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(metadata: Metadata) = apply { + additionalProperties = metadata.additionalProperties.toMutableMap() + } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [Metadata]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): Metadata = Metadata(additionalProperties.toImmutable()) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing fields. + * + * @throws OpenAIInvalidDataException if any value type in this object doesn't match its + * expected type. + */ + fun validate(): Metadata = apply { + if (validated) { + return@apply + } + + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OpenAIInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + additionalProperties.count { (_, value) -> !value.isNull() && !value.isMissing() } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Metadata && additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = "Metadata{additionalProperties=$additionalProperties}" + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is RoleRetrieveResponse && + id == other.id && + assignmentSources == other.assignmentSources && + createdAt == other.createdAt && + createdBy == other.createdBy && + createdByUserObj == other.createdByUserObj && + description == other.description && + metadata == other.metadata && + name == other.name && + permissions == other.permissions && + predefinedRole == other.predefinedRole && + resourceType == other.resourceType && + updatedAt == other.updatedAt && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + id, + assignmentSources, + createdAt, + createdBy, + createdByUserObj, + description, + metadata, + name, + permissions, + predefinedRole, + resourceType, + updatedAt, + additionalProperties, + ) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "RoleRetrieveResponse{id=$id, assignmentSources=$assignmentSources, createdAt=$createdAt, createdBy=$createdBy, createdByUserObj=$createdByUserObj, description=$description, metadata=$metadata, name=$name, permissions=$permissions, predefinedRole=$predefinedRole, resourceType=$resourceType, updatedAt=$updatedAt, additionalProperties=$additionalProperties}" +} diff --git a/openai-java-core/src/main/kotlin/com/openai/models/admin/organization/projects/roles/RoleRetrieveParams.kt b/openai-java-core/src/main/kotlin/com/openai/models/admin/organization/projects/roles/RoleRetrieveParams.kt new file mode 100644 index 000000000..1b76a9421 --- /dev/null +++ b/openai-java-core/src/main/kotlin/com/openai/models/admin/organization/projects/roles/RoleRetrieveParams.kt @@ -0,0 +1,217 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.models.admin.organization.projects.roles + +import com.openai.core.Params +import com.openai.core.checkRequired +import com.openai.core.http.Headers +import com.openai.core.http.QueryParams +import java.util.Objects +import java.util.Optional +import kotlin.jvm.optionals.getOrNull + +/** Retrieves a project role. */ +class RoleRetrieveParams +private constructor( + private val projectId: String, + private val roleId: String?, + private val additionalHeaders: Headers, + private val additionalQueryParams: QueryParams, +) : Params { + + fun projectId(): String = projectId + + fun roleId(): Optional = Optional.ofNullable(roleId) + + /** Additional headers to send with the request. */ + fun _additionalHeaders(): Headers = additionalHeaders + + /** Additional query param to send with the request. */ + fun _additionalQueryParams(): QueryParams = additionalQueryParams + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of [RoleRetrieveParams]. + * + * The following fields are required: + * ```java + * .projectId() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [RoleRetrieveParams]. */ + class Builder internal constructor() { + + private var projectId: String? = null + private var roleId: String? = null + private var additionalHeaders: Headers.Builder = Headers.builder() + private var additionalQueryParams: QueryParams.Builder = QueryParams.builder() + + @JvmSynthetic + internal fun from(roleRetrieveParams: RoleRetrieveParams) = apply { + projectId = roleRetrieveParams.projectId + roleId = roleRetrieveParams.roleId + additionalHeaders = roleRetrieveParams.additionalHeaders.toBuilder() + additionalQueryParams = roleRetrieveParams.additionalQueryParams.toBuilder() + } + + fun projectId(projectId: String) = apply { this.projectId = projectId } + + fun roleId(roleId: String?) = apply { this.roleId = roleId } + + /** Alias for calling [Builder.roleId] with `roleId.orElse(null)`. */ + fun roleId(roleId: Optional) = roleId(roleId.getOrNull()) + + 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 [RoleRetrieveParams]. + * + * 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(): RoleRetrieveParams = + RoleRetrieveParams( + checkRequired("projectId", projectId), + roleId, + additionalHeaders.build(), + additionalQueryParams.build(), + ) + } + + fun _pathParam(index: Int): String = + when (index) { + 0 -> projectId + 1 -> roleId ?: "" + else -> "" + } + + override fun _headers(): Headers = additionalHeaders + + override fun _queryParams(): QueryParams = additionalQueryParams + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is RoleRetrieveParams && + projectId == other.projectId && + roleId == other.roleId && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams + } + + override fun hashCode(): Int = + Objects.hash(projectId, roleId, additionalHeaders, additionalQueryParams) + + override fun toString() = + "RoleRetrieveParams{projectId=$projectId, roleId=$roleId, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" +} diff --git a/openai-java-core/src/main/kotlin/com/openai/models/admin/organization/projects/serviceaccounts/ServiceAccountUpdateParams.kt b/openai-java-core/src/main/kotlin/com/openai/models/admin/organization/projects/serviceaccounts/ServiceAccountUpdateParams.kt new file mode 100644 index 000000000..a592bd02f --- /dev/null +++ b/openai-java-core/src/main/kotlin/com/openai/models/admin/organization/projects/serviceaccounts/ServiceAccountUpdateParams.kt @@ -0,0 +1,642 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.models.admin.organization.projects.serviceaccounts + +import com.fasterxml.jackson.annotation.JsonAnyGetter +import com.fasterxml.jackson.annotation.JsonAnySetter +import com.fasterxml.jackson.annotation.JsonCreator +import com.fasterxml.jackson.annotation.JsonProperty +import com.openai.core.Enum +import com.openai.core.ExcludeMissing +import com.openai.core.JsonField +import com.openai.core.JsonMissing +import com.openai.core.JsonValue +import com.openai.core.Params +import com.openai.core.checkRequired +import com.openai.core.http.Headers +import com.openai.core.http.QueryParams +import com.openai.errors.OpenAIInvalidDataException +import java.util.Collections +import java.util.Objects +import java.util.Optional +import kotlin.jvm.optionals.getOrNull + +/** Updates a service account in the project. */ +class ServiceAccountUpdateParams +private constructor( + private val projectId: String, + private val serviceAccountId: String?, + private val body: Body, + private val additionalHeaders: Headers, + private val additionalQueryParams: QueryParams, +) : Params { + + fun projectId(): String = projectId + + fun serviceAccountId(): Optional = Optional.ofNullable(serviceAccountId) + + /** + * The updated service account name. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun name(): Optional = body.name() + + /** + * The updated service account role. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun role(): Optional = body.role() + + /** + * Returns the raw JSON value of [name]. + * + * Unlike [name], this method doesn't throw if the JSON field has an unexpected type. + */ + fun _name(): JsonField = body._name() + + /** + * Returns the raw JSON value of [role]. + * + * Unlike [role], this method doesn't throw if the JSON field has an unexpected type. + */ + fun _role(): JsonField = body._role() + + fun _additionalBodyProperties(): Map = body._additionalProperties() + + /** Additional headers to send with the request. */ + fun _additionalHeaders(): Headers = additionalHeaders + + /** Additional query param to send with the request. */ + fun _additionalQueryParams(): QueryParams = additionalQueryParams + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of [ServiceAccountUpdateParams]. + * + * The following fields are required: + * ```java + * .projectId() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [ServiceAccountUpdateParams]. */ + class Builder internal constructor() { + + private var projectId: String? = null + private var serviceAccountId: 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(serviceAccountUpdateParams: ServiceAccountUpdateParams) = apply { + projectId = serviceAccountUpdateParams.projectId + serviceAccountId = serviceAccountUpdateParams.serviceAccountId + body = serviceAccountUpdateParams.body.toBuilder() + additionalHeaders = serviceAccountUpdateParams.additionalHeaders.toBuilder() + additionalQueryParams = serviceAccountUpdateParams.additionalQueryParams.toBuilder() + } + + fun projectId(projectId: String) = apply { this.projectId = projectId } + + fun serviceAccountId(serviceAccountId: String?) = apply { + this.serviceAccountId = serviceAccountId + } + + /** Alias for calling [Builder.serviceAccountId] with `serviceAccountId.orElse(null)`. */ + fun serviceAccountId(serviceAccountId: Optional) = + serviceAccountId(serviceAccountId.getOrNull()) + + /** + * Sets the entire request body. + * + * This is generally only useful if you are already constructing the body separately. + * Otherwise, it's more convenient to use the top-level setters instead: + * - [name] + * - [role] + */ + fun body(body: Body) = apply { this.body = body.toBuilder() } + + /** The updated service account name. */ + 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 updated service account role. */ + fun role(role: Role) = apply { body.role(role) } + + /** + * Sets [Builder.role] to an arbitrary JSON value. + * + * You should usually call [Builder.role] with a well-typed [Role] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun role(role: JsonField) = apply { body.role(role) } + + 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 [ServiceAccountUpdateParams]. + * + * 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(): ServiceAccountUpdateParams = + ServiceAccountUpdateParams( + checkRequired("projectId", projectId), + serviceAccountId, + body.build(), + additionalHeaders.build(), + additionalQueryParams.build(), + ) + } + + fun _body(): Body = body + + fun _pathParam(index: Int): String = + when (index) { + 0 -> projectId + 1 -> serviceAccountId ?: "" + else -> "" + } + + override fun _headers(): Headers = additionalHeaders + + override fun _queryParams(): QueryParams = additionalQueryParams + + /** Parameters for updating a project service account. */ + class Body + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val name: JsonField, + private val role: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("name") @ExcludeMissing name: JsonField = JsonMissing.of(), + @JsonProperty("role") @ExcludeMissing role: JsonField = JsonMissing.of(), + ) : this(name, role, mutableMapOf()) + + /** + * The updated service account name. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun name(): Optional = name.getOptional("name") + + /** + * The updated service account role. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun role(): Optional = role.getOptional("role") + + /** + * 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 [role]. + * + * Unlike [role], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("role") @ExcludeMissing fun _role(): JsonField = role + + @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 role: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(body: Body) = apply { + name = body.name + role = body.role + additionalProperties = body.additionalProperties.toMutableMap() + } + + /** The updated service account name. */ + 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 updated service account role. */ + fun role(role: Role) = role(JsonField.of(role)) + + /** + * Sets [Builder.role] to an arbitrary JSON value. + * + * You should usually call [Builder.role] with a well-typed [Role] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun role(role: JsonField) = apply { this.role = role } + + 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, role, additionalProperties.toMutableMap()) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing fields. + * + * @throws OpenAIInvalidDataException if any value type in this object doesn't match its + * expected type. + */ + fun validate(): Body = apply { + if (validated) { + return@apply + } + + name() + role().ifPresent { it.validate() } + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OpenAIInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (if (name.asKnown().isPresent) 1 else 0) + (role.asKnown().getOrNull()?.validity() ?: 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Body && + name == other.name && + role == other.role && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(name, role, additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Body{name=$name, role=$role, additionalProperties=$additionalProperties}" + } + + /** The updated service account role. */ + class Role @JsonCreator private constructor(private val value: JsonField) : Enum { + + /** + * Returns this class instance's raw value. + * + * This is usually only useful if this instance was deserialized from data that doesn't + * match any known member, and you want to know that value. For example, if the SDK is on an + * older version than the API, then the API may respond with new members that the SDK is + * unaware of. + */ + @com.fasterxml.jackson.annotation.JsonValue fun _value(): JsonField = value + + companion object { + + @JvmField val MEMBER = of("member") + + @JvmField val OWNER = of("owner") + + @JvmStatic fun of(value: String) = Role(JsonField.of(value)) + } + + /** An enum containing [Role]'s known values. */ + enum class Known { + MEMBER, + OWNER, + } + + /** + * An enum containing [Role]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [Role] can contain an unknown value in a couple of cases: + * - It was deserialized from data that doesn't match any known member. For example, if the + * SDK is on an older version than the API, then the API may respond with new members that + * the SDK is unaware of. + * - It was constructed with an arbitrary value using the [of] method. + */ + enum class Value { + MEMBER, + OWNER, + /** An enum member indicating that [Role] was instantiated with an unknown value. */ + _UNKNOWN, + } + + /** + * Returns an enum member corresponding to this class instance's value, or [Value._UNKNOWN] + * if the class was instantiated with an unknown value. + * + * Use the [known] method instead if you're certain the value is always known or if you want + * to throw for the unknown case. + */ + fun value(): Value = + when (this) { + MEMBER -> Value.MEMBER + OWNER -> Value.OWNER + else -> Value._UNKNOWN + } + + /** + * Returns an enum member corresponding to this class instance's value. + * + * Use the [value] method instead if you're uncertain the value is always known and don't + * want to throw for the unknown case. + * + * @throws OpenAIInvalidDataException if this class instance's value is a not a known + * member. + */ + fun known(): Known = + when (this) { + MEMBER -> Known.MEMBER + OWNER -> Known.OWNER + else -> throw OpenAIInvalidDataException("Unknown Role: $value") + } + + /** + * Returns this class instance's primitive wire representation. + * + * This differs from the [toString] method because that method is primarily for debugging + * and generally doesn't throw. + * + * @throws OpenAIInvalidDataException if this class instance's value does not have the + * expected primitive type. + */ + fun asString(): String = + _value().asString().orElseThrow { OpenAIInvalidDataException("Value is not a String") } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing fields. + * + * @throws OpenAIInvalidDataException if any value type in this object doesn't match its + * expected type. + */ + fun validate(): Role = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OpenAIInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Role && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is ServiceAccountUpdateParams && + projectId == other.projectId && + serviceAccountId == other.serviceAccountId && + body == other.body && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams + } + + override fun hashCode(): Int = + Objects.hash(projectId, serviceAccountId, body, additionalHeaders, additionalQueryParams) + + override fun toString() = + "ServiceAccountUpdateParams{projectId=$projectId, serviceAccountId=$serviceAccountId, body=$body, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" +} diff --git a/openai-java-core/src/main/kotlin/com/openai/models/admin/organization/projects/spendalerts/ProjectSpendAlert.kt b/openai-java-core/src/main/kotlin/com/openai/models/admin/organization/projects/spendalerts/ProjectSpendAlert.kt new file mode 100644 index 000000000..d8ca37a88 --- /dev/null +++ b/openai-java-core/src/main/kotlin/com/openai/models/admin/organization/projects/spendalerts/ProjectSpendAlert.kt @@ -0,0 +1,936 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.models.admin.organization.projects.spendalerts + +import com.fasterxml.jackson.annotation.JsonAnyGetter +import com.fasterxml.jackson.annotation.JsonAnySetter +import com.fasterxml.jackson.annotation.JsonCreator +import com.fasterxml.jackson.annotation.JsonProperty +import com.openai.core.Enum +import com.openai.core.ExcludeMissing +import com.openai.core.JsonField +import com.openai.core.JsonMissing +import com.openai.core.JsonValue +import com.openai.core.checkKnown +import com.openai.core.checkRequired +import com.openai.core.toImmutable +import com.openai.errors.OpenAIInvalidDataException +import java.util.Collections +import java.util.Objects +import java.util.Optional +import kotlin.jvm.optionals.getOrNull + +/** Represents a spend alert configured at the project level. */ +class ProjectSpendAlert +@JsonCreator(mode = JsonCreator.Mode.DISABLED) +private constructor( + private val id: JsonField, + private val currency: JsonField, + private val interval: JsonField, + private val notificationChannel: JsonField, + private val object_: JsonValue, + private val thresholdAmount: JsonField, + private val additionalProperties: MutableMap, +) { + + @JsonCreator + private constructor( + @JsonProperty("id") @ExcludeMissing id: JsonField = JsonMissing.of(), + @JsonProperty("currency") @ExcludeMissing currency: JsonField = JsonMissing.of(), + @JsonProperty("interval") @ExcludeMissing interval: JsonField = JsonMissing.of(), + @JsonProperty("notification_channel") + @ExcludeMissing + notificationChannel: JsonField = JsonMissing.of(), + @JsonProperty("object") @ExcludeMissing object_: JsonValue = JsonMissing.of(), + @JsonProperty("threshold_amount") + @ExcludeMissing + thresholdAmount: JsonField = JsonMissing.of(), + ) : this(id, currency, interval, notificationChannel, object_, thresholdAmount, mutableMapOf()) + + /** + * The identifier, which can be referenced in API endpoints. + * + * @throws OpenAIInvalidDataException 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 id(): String = id.getRequired("id") + + /** + * The currency for the threshold amount. + * + * @throws OpenAIInvalidDataException 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 currency(): Currency = currency.getRequired("currency") + + /** + * The time interval for evaluating spend against the threshold. + * + * @throws OpenAIInvalidDataException 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 interval(): Interval = interval.getRequired("interval") + + /** + * Email notification settings for a spend alert. + * + * @throws OpenAIInvalidDataException 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 notificationChannel(): NotificationChannel = + notificationChannel.getRequired("notification_channel") + + /** + * The object type, which is always `project.spend_alert`. + * + * Expected to always return the following: + * ```java + * JsonValue.from("project.spend_alert") + * ``` + * + * However, this method can be useful for debugging and logging (e.g. if the server responded + * with an unexpected value). + */ + @JsonProperty("object") @ExcludeMissing fun _object_(): JsonValue = object_ + + /** + * The alert threshold amount, in cents. + * + * @throws OpenAIInvalidDataException 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 thresholdAmount(): Long = thresholdAmount.getRequired("threshold_amount") + + /** + * Returns the raw JSON value of [id]. + * + * Unlike [id], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("id") @ExcludeMissing fun _id(): JsonField = id + + /** + * Returns the raw JSON value of [currency]. + * + * Unlike [currency], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("currency") @ExcludeMissing fun _currency(): JsonField = currency + + /** + * Returns the raw JSON value of [interval]. + * + * Unlike [interval], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("interval") @ExcludeMissing fun _interval(): JsonField = interval + + /** + * Returns the raw JSON value of [notificationChannel]. + * + * Unlike [notificationChannel], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("notification_channel") + @ExcludeMissing + fun _notificationChannel(): JsonField = notificationChannel + + /** + * Returns the raw JSON value of [thresholdAmount]. + * + * Unlike [thresholdAmount], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("threshold_amount") + @ExcludeMissing + fun _thresholdAmount(): JsonField = thresholdAmount + + @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 [ProjectSpendAlert]. + * + * The following fields are required: + * ```java + * .id() + * .currency() + * .interval() + * .notificationChannel() + * .thresholdAmount() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [ProjectSpendAlert]. */ + class Builder internal constructor() { + + private var id: JsonField? = null + private var currency: JsonField? = null + private var interval: JsonField? = null + private var notificationChannel: JsonField? = null + private var object_: JsonValue = JsonValue.from("project.spend_alert") + private var thresholdAmount: JsonField? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(projectSpendAlert: ProjectSpendAlert) = apply { + id = projectSpendAlert.id + currency = projectSpendAlert.currency + interval = projectSpendAlert.interval + notificationChannel = projectSpendAlert.notificationChannel + object_ = projectSpendAlert.object_ + thresholdAmount = projectSpendAlert.thresholdAmount + additionalProperties = projectSpendAlert.additionalProperties.toMutableMap() + } + + /** The identifier, which can be referenced in API endpoints. */ + fun id(id: String) = id(JsonField.of(id)) + + /** + * Sets [Builder.id] to an arbitrary JSON value. + * + * You should usually call [Builder.id] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun id(id: JsonField) = apply { this.id = id } + + /** The currency for the threshold amount. */ + fun currency(currency: Currency) = currency(JsonField.of(currency)) + + /** + * Sets [Builder.currency] to an arbitrary JSON value. + * + * You should usually call [Builder.currency] with a well-typed [Currency] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun currency(currency: JsonField) = apply { this.currency = currency } + + /** The time interval for evaluating spend against the threshold. */ + fun interval(interval: Interval) = interval(JsonField.of(interval)) + + /** + * Sets [Builder.interval] to an arbitrary JSON value. + * + * You should usually call [Builder.interval] with a well-typed [Interval] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun interval(interval: JsonField) = apply { this.interval = interval } + + /** Email notification settings for a spend alert. */ + fun notificationChannel(notificationChannel: NotificationChannel) = + notificationChannel(JsonField.of(notificationChannel)) + + /** + * Sets [Builder.notificationChannel] to an arbitrary JSON value. + * + * You should usually call [Builder.notificationChannel] with a well-typed + * [NotificationChannel] value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun notificationChannel(notificationChannel: JsonField) = apply { + this.notificationChannel = notificationChannel + } + + /** + * Sets the field to an arbitrary JSON value. + * + * It is usually unnecessary to call this method because the field defaults to the + * following: + * ```java + * JsonValue.from("project.spend_alert") + * ``` + * + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun object_(object_: JsonValue) = apply { this.object_ = object_ } + + /** The alert threshold amount, in cents. */ + fun thresholdAmount(thresholdAmount: Long) = thresholdAmount(JsonField.of(thresholdAmount)) + + /** + * Sets [Builder.thresholdAmount] to an arbitrary JSON value. + * + * You should usually call [Builder.thresholdAmount] with a well-typed [Long] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun thresholdAmount(thresholdAmount: JsonField) = apply { + this.thresholdAmount = thresholdAmount + } + + 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 [ProjectSpendAlert]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .id() + * .currency() + * .interval() + * .notificationChannel() + * .thresholdAmount() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): ProjectSpendAlert = + ProjectSpendAlert( + checkRequired("id", id), + checkRequired("currency", currency), + checkRequired("interval", interval), + checkRequired("notificationChannel", notificationChannel), + object_, + checkRequired("thresholdAmount", thresholdAmount), + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected types recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing fields. + * + * @throws OpenAIInvalidDataException if any value type in this object doesn't match its + * expected type. + */ + fun validate(): ProjectSpendAlert = apply { + if (validated) { + return@apply + } + + id() + currency().validate() + interval().validate() + notificationChannel().validate() + _object_().let { + if (it != JsonValue.from("project.spend_alert")) { + throw OpenAIInvalidDataException("'object_' is invalid, received $it") + } + } + thresholdAmount() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OpenAIInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (if (id.asKnown().isPresent) 1 else 0) + + (currency.asKnown().getOrNull()?.validity() ?: 0) + + (interval.asKnown().getOrNull()?.validity() ?: 0) + + (notificationChannel.asKnown().getOrNull()?.validity() ?: 0) + + object_.let { if (it == JsonValue.from("project.spend_alert")) 1 else 0 } + + (if (thresholdAmount.asKnown().isPresent) 1 else 0) + + /** The currency for the threshold amount. */ + class Currency @JsonCreator private constructor(private val value: JsonField) : Enum { + + /** + * Returns this class instance's raw value. + * + * This is usually only useful if this instance was deserialized from data that doesn't + * match any known member, and you want to know that value. For example, if the SDK is on an + * older version than the API, then the API may respond with new members that the SDK is + * unaware of. + */ + @com.fasterxml.jackson.annotation.JsonValue fun _value(): JsonField = value + + companion object { + + @JvmField val USD = of("USD") + + @JvmStatic fun of(value: String) = Currency(JsonField.of(value)) + } + + /** An enum containing [Currency]'s known values. */ + enum class Known { + USD + } + + /** + * An enum containing [Currency]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [Currency] can contain an unknown value in a couple of cases: + * - It was deserialized from data that doesn't match any known member. For example, if the + * SDK is on an older version than the API, then the API may respond with new members that + * the SDK is unaware of. + * - It was constructed with an arbitrary value using the [of] method. + */ + enum class Value { + USD, + /** An enum member indicating that [Currency] was instantiated with an unknown value. */ + _UNKNOWN, + } + + /** + * Returns an enum member corresponding to this class instance's value, or [Value._UNKNOWN] + * if the class was instantiated with an unknown value. + * + * Use the [known] method instead if you're certain the value is always known or if you want + * to throw for the unknown case. + */ + fun value(): Value = + when (this) { + USD -> Value.USD + else -> Value._UNKNOWN + } + + /** + * Returns an enum member corresponding to this class instance's value. + * + * Use the [value] method instead if you're uncertain the value is always known and don't + * want to throw for the unknown case. + * + * @throws OpenAIInvalidDataException if this class instance's value is a not a known + * member. + */ + fun known(): Known = + when (this) { + USD -> Known.USD + else -> throw OpenAIInvalidDataException("Unknown Currency: $value") + } + + /** + * Returns this class instance's primitive wire representation. + * + * This differs from the [toString] method because that method is primarily for debugging + * and generally doesn't throw. + * + * @throws OpenAIInvalidDataException if this class instance's value does not have the + * expected primitive type. + */ + fun asString(): String = + _value().asString().orElseThrow { OpenAIInvalidDataException("Value is not a String") } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing fields. + * + * @throws OpenAIInvalidDataException if any value type in this object doesn't match its + * expected type. + */ + fun validate(): Currency = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OpenAIInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Currency && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + /** The time interval for evaluating spend against the threshold. */ + class Interval @JsonCreator private constructor(private val value: JsonField) : Enum { + + /** + * Returns this class instance's raw value. + * + * This is usually only useful if this instance was deserialized from data that doesn't + * match any known member, and you want to know that value. For example, if the SDK is on an + * older version than the API, then the API may respond with new members that the SDK is + * unaware of. + */ + @com.fasterxml.jackson.annotation.JsonValue fun _value(): JsonField = value + + companion object { + + @JvmField val MONTH = of("month") + + @JvmStatic fun of(value: String) = Interval(JsonField.of(value)) + } + + /** An enum containing [Interval]'s known values. */ + enum class Known { + MONTH + } + + /** + * An enum containing [Interval]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [Interval] can contain an unknown value in a couple of cases: + * - It was deserialized from data that doesn't match any known member. For example, if the + * SDK is on an older version than the API, then the API may respond with new members that + * the SDK is unaware of. + * - It was constructed with an arbitrary value using the [of] method. + */ + enum class Value { + MONTH, + /** An enum member indicating that [Interval] was instantiated with an unknown value. */ + _UNKNOWN, + } + + /** + * Returns an enum member corresponding to this class instance's value, or [Value._UNKNOWN] + * if the class was instantiated with an unknown value. + * + * Use the [known] method instead if you're certain the value is always known or if you want + * to throw for the unknown case. + */ + fun value(): Value = + when (this) { + MONTH -> Value.MONTH + else -> Value._UNKNOWN + } + + /** + * Returns an enum member corresponding to this class instance's value. + * + * Use the [value] method instead if you're uncertain the value is always known and don't + * want to throw for the unknown case. + * + * @throws OpenAIInvalidDataException if this class instance's value is a not a known + * member. + */ + fun known(): Known = + when (this) { + MONTH -> Known.MONTH + else -> throw OpenAIInvalidDataException("Unknown Interval: $value") + } + + /** + * Returns this class instance's primitive wire representation. + * + * This differs from the [toString] method because that method is primarily for debugging + * and generally doesn't throw. + * + * @throws OpenAIInvalidDataException if this class instance's value does not have the + * expected primitive type. + */ + fun asString(): String = + _value().asString().orElseThrow { OpenAIInvalidDataException("Value is not a String") } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing fields. + * + * @throws OpenAIInvalidDataException if any value type in this object doesn't match its + * expected type. + */ + fun validate(): Interval = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OpenAIInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Interval && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + /** Email notification settings for a spend alert. */ + class NotificationChannel + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val recipients: JsonField>, + private val type: JsonValue, + private val subjectPrefix: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("recipients") + @ExcludeMissing + recipients: JsonField> = JsonMissing.of(), + @JsonProperty("type") @ExcludeMissing type: JsonValue = JsonMissing.of(), + @JsonProperty("subject_prefix") + @ExcludeMissing + subjectPrefix: JsonField = JsonMissing.of(), + ) : this(recipients, type, subjectPrefix, mutableMapOf()) + + /** + * Email addresses that receive the spend alert notification. + * + * @throws OpenAIInvalidDataException 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 recipients(): List = recipients.getRequired("recipients") + + /** + * The notification channel type. Currently only `email` is supported. + * + * Expected to always return the following: + * ```java + * JsonValue.from("email") + * ``` + * + * However, this method can be useful for debugging and logging (e.g. if the server + * responded with an unexpected value). + */ + @JsonProperty("type") @ExcludeMissing fun _type(): JsonValue = type + + /** + * Optional subject prefix for alert emails. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun subjectPrefix(): Optional = subjectPrefix.getOptional("subject_prefix") + + /** + * Returns the raw JSON value of [recipients]. + * + * Unlike [recipients], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("recipients") + @ExcludeMissing + fun _recipients(): JsonField> = recipients + + /** + * Returns the raw JSON value of [subjectPrefix]. + * + * Unlike [subjectPrefix], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("subject_prefix") + @ExcludeMissing + fun _subjectPrefix(): JsonField = subjectPrefix + + @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 [NotificationChannel]. + * + * The following fields are required: + * ```java + * .recipients() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [NotificationChannel]. */ + class Builder internal constructor() { + + private var recipients: JsonField>? = null + private var type: JsonValue = JsonValue.from("email") + private var subjectPrefix: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(notificationChannel: NotificationChannel) = apply { + recipients = notificationChannel.recipients.map { it.toMutableList() } + type = notificationChannel.type + subjectPrefix = notificationChannel.subjectPrefix + additionalProperties = notificationChannel.additionalProperties.toMutableMap() + } + + /** Email addresses that receive the spend alert notification. */ + fun recipients(recipients: List) = recipients(JsonField.of(recipients)) + + /** + * Sets [Builder.recipients] to an arbitrary JSON value. + * + * You should usually call [Builder.recipients] with a well-typed `List` value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun recipients(recipients: JsonField>) = apply { + this.recipients = recipients.map { it.toMutableList() } + } + + /** + * Adds a single [String] to [recipients]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addRecipient(recipient: String) = apply { + recipients = + (recipients ?: JsonField.of(mutableListOf())).also { + checkKnown("recipients", it).add(recipient) + } + } + + /** + * Sets the field to an arbitrary JSON value. + * + * It is usually unnecessary to call this method because the field defaults to the + * following: + * ```java + * JsonValue.from("email") + * ``` + * + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun type(type: JsonValue) = apply { this.type = type } + + /** Optional subject prefix for alert emails. */ + fun subjectPrefix(subjectPrefix: String?) = + subjectPrefix(JsonField.ofNullable(subjectPrefix)) + + /** Alias for calling [Builder.subjectPrefix] with `subjectPrefix.orElse(null)`. */ + fun subjectPrefix(subjectPrefix: Optional) = + subjectPrefix(subjectPrefix.getOrNull()) + + /** + * Sets [Builder.subjectPrefix] to an arbitrary JSON value. + * + * You should usually call [Builder.subjectPrefix] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun subjectPrefix(subjectPrefix: JsonField) = apply { + this.subjectPrefix = subjectPrefix + } + + 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 [NotificationChannel]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .recipients() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): NotificationChannel = + NotificationChannel( + checkRequired("recipients", recipients).map { it.toImmutable() }, + type, + subjectPrefix, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing fields. + * + * @throws OpenAIInvalidDataException if any value type in this object doesn't match its + * expected type. + */ + fun validate(): NotificationChannel = apply { + if (validated) { + return@apply + } + + recipients() + _type().let { + if (it != JsonValue.from("email")) { + throw OpenAIInvalidDataException("'type' is invalid, received $it") + } + } + subjectPrefix() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OpenAIInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (recipients.asKnown().getOrNull()?.size ?: 0) + + type.let { if (it == JsonValue.from("email")) 1 else 0 } + + (if (subjectPrefix.asKnown().isPresent) 1 else 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is NotificationChannel && + recipients == other.recipients && + type == other.type && + subjectPrefix == other.subjectPrefix && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(recipients, type, subjectPrefix, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "NotificationChannel{recipients=$recipients, type=$type, subjectPrefix=$subjectPrefix, additionalProperties=$additionalProperties}" + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is ProjectSpendAlert && + id == other.id && + currency == other.currency && + interval == other.interval && + notificationChannel == other.notificationChannel && + object_ == other.object_ && + thresholdAmount == other.thresholdAmount && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + id, + currency, + interval, + notificationChannel, + object_, + thresholdAmount, + additionalProperties, + ) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "ProjectSpendAlert{id=$id, currency=$currency, interval=$interval, notificationChannel=$notificationChannel, object_=$object_, thresholdAmount=$thresholdAmount, additionalProperties=$additionalProperties}" +} diff --git a/openai-java-core/src/main/kotlin/com/openai/models/admin/organization/projects/spendalerts/ProjectSpendAlertDeleted.kt b/openai-java-core/src/main/kotlin/com/openai/models/admin/organization/projects/spendalerts/ProjectSpendAlertDeleted.kt new file mode 100644 index 000000000..a2d747860 --- /dev/null +++ b/openai-java-core/src/main/kotlin/com/openai/models/admin/organization/projects/spendalerts/ProjectSpendAlertDeleted.kt @@ -0,0 +1,259 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.models.admin.organization.projects.spendalerts + +import com.fasterxml.jackson.annotation.JsonAnyGetter +import com.fasterxml.jackson.annotation.JsonAnySetter +import com.fasterxml.jackson.annotation.JsonCreator +import com.fasterxml.jackson.annotation.JsonProperty +import com.openai.core.ExcludeMissing +import com.openai.core.JsonField +import com.openai.core.JsonMissing +import com.openai.core.JsonValue +import com.openai.core.checkRequired +import com.openai.errors.OpenAIInvalidDataException +import java.util.Collections +import java.util.Objects + +/** Confirmation payload returned after deleting a project spend alert. */ +class ProjectSpendAlertDeleted +@JsonCreator(mode = JsonCreator.Mode.DISABLED) +private constructor( + private val id: JsonField, + private val deleted: JsonField, + private val object_: JsonValue, + private val additionalProperties: MutableMap, +) { + + @JsonCreator + private constructor( + @JsonProperty("id") @ExcludeMissing id: JsonField = JsonMissing.of(), + @JsonProperty("deleted") @ExcludeMissing deleted: JsonField = JsonMissing.of(), + @JsonProperty("object") @ExcludeMissing object_: JsonValue = JsonMissing.of(), + ) : this(id, deleted, object_, mutableMapOf()) + + /** + * The deleted spend alert ID. + * + * @throws OpenAIInvalidDataException 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 id(): String = id.getRequired("id") + + /** + * Whether the spend alert was deleted. + * + * @throws OpenAIInvalidDataException 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 deleted(): Boolean = deleted.getRequired("deleted") + + /** + * Always `project.spend_alert.deleted`. + * + * Expected to always return the following: + * ```java + * JsonValue.from("project.spend_alert.deleted") + * ``` + * + * However, this method can be useful for debugging and logging (e.g. if the server responded + * with an unexpected value). + */ + @JsonProperty("object") @ExcludeMissing fun _object_(): JsonValue = object_ + + /** + * Returns the raw JSON value of [id]. + * + * Unlike [id], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("id") @ExcludeMissing fun _id(): JsonField = id + + /** + * Returns the raw JSON value of [deleted]. + * + * Unlike [deleted], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("deleted") @ExcludeMissing fun _deleted(): JsonField = deleted + + @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 [ProjectSpendAlertDeleted]. + * + * The following fields are required: + * ```java + * .id() + * .deleted() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [ProjectSpendAlertDeleted]. */ + class Builder internal constructor() { + + private var id: JsonField? = null + private var deleted: JsonField? = null + private var object_: JsonValue = JsonValue.from("project.spend_alert.deleted") + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(projectSpendAlertDeleted: ProjectSpendAlertDeleted) = apply { + id = projectSpendAlertDeleted.id + deleted = projectSpendAlertDeleted.deleted + object_ = projectSpendAlertDeleted.object_ + additionalProperties = projectSpendAlertDeleted.additionalProperties.toMutableMap() + } + + /** The deleted spend alert ID. */ + fun id(id: String) = id(JsonField.of(id)) + + /** + * Sets [Builder.id] to an arbitrary JSON value. + * + * You should usually call [Builder.id] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun id(id: JsonField) = apply { this.id = id } + + /** Whether the spend alert was deleted. */ + fun deleted(deleted: Boolean) = deleted(JsonField.of(deleted)) + + /** + * Sets [Builder.deleted] to an arbitrary JSON value. + * + * You should usually call [Builder.deleted] with a well-typed [Boolean] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun deleted(deleted: JsonField) = apply { this.deleted = deleted } + + /** + * Sets the field to an arbitrary JSON value. + * + * It is usually unnecessary to call this method because the field defaults to the + * following: + * ```java + * JsonValue.from("project.spend_alert.deleted") + * ``` + * + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun object_(object_: JsonValue) = apply { this.object_ = object_ } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [ProjectSpendAlertDeleted]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .id() + * .deleted() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): ProjectSpendAlertDeleted = + ProjectSpendAlertDeleted( + checkRequired("id", id), + checkRequired("deleted", deleted), + object_, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected types recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing fields. + * + * @throws OpenAIInvalidDataException if any value type in this object doesn't match its + * expected type. + */ + fun validate(): ProjectSpendAlertDeleted = apply { + if (validated) { + return@apply + } + + id() + deleted() + _object_().let { + if (it != JsonValue.from("project.spend_alert.deleted")) { + throw OpenAIInvalidDataException("'object_' is invalid, received $it") + } + } + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OpenAIInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (if (id.asKnown().isPresent) 1 else 0) + + (if (deleted.asKnown().isPresent) 1 else 0) + + object_.let { if (it == JsonValue.from("project.spend_alert.deleted")) 1 else 0 } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is ProjectSpendAlertDeleted && + id == other.id && + deleted == other.deleted && + object_ == other.object_ && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(id, deleted, object_, additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "ProjectSpendAlertDeleted{id=$id, deleted=$deleted, object_=$object_, additionalProperties=$additionalProperties}" +} diff --git a/openai-java-core/src/main/kotlin/com/openai/models/admin/organization/projects/spendalerts/SpendAlertCreateParams.kt b/openai-java-core/src/main/kotlin/com/openai/models/admin/organization/projects/spendalerts/SpendAlertCreateParams.kt new file mode 100644 index 000000000..4de3d2edf --- /dev/null +++ b/openai-java-core/src/main/kotlin/com/openai/models/admin/organization/projects/spendalerts/SpendAlertCreateParams.kt @@ -0,0 +1,1227 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.models.admin.organization.projects.spendalerts + +import com.fasterxml.jackson.annotation.JsonAnyGetter +import com.fasterxml.jackson.annotation.JsonAnySetter +import com.fasterxml.jackson.annotation.JsonCreator +import com.fasterxml.jackson.annotation.JsonProperty +import com.openai.core.Enum +import com.openai.core.ExcludeMissing +import com.openai.core.JsonField +import com.openai.core.JsonMissing +import com.openai.core.JsonValue +import com.openai.core.Params +import com.openai.core.checkKnown +import com.openai.core.checkRequired +import com.openai.core.http.Headers +import com.openai.core.http.QueryParams +import com.openai.core.toImmutable +import com.openai.errors.OpenAIInvalidDataException +import java.util.Collections +import java.util.Objects +import java.util.Optional +import kotlin.jvm.optionals.getOrNull + +/** Creates a project spend alert. */ +class SpendAlertCreateParams +private constructor( + private val projectId: String?, + private val body: Body, + private val additionalHeaders: Headers, + private val additionalQueryParams: QueryParams, +) : Params { + + fun projectId(): Optional = Optional.ofNullable(projectId) + + /** + * The currency for the threshold amount. + * + * @throws OpenAIInvalidDataException 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 currency(): Currency = body.currency() + + /** + * The time interval for evaluating spend against the threshold. + * + * @throws OpenAIInvalidDataException 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 interval(): Interval = body.interval() + + /** + * Email notification settings for a spend alert. + * + * @throws OpenAIInvalidDataException 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 notificationChannel(): NotificationChannel = body.notificationChannel() + + /** + * The alert threshold amount, in cents. + * + * @throws OpenAIInvalidDataException 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 thresholdAmount(): Long = body.thresholdAmount() + + /** + * Returns the raw JSON value of [currency]. + * + * Unlike [currency], this method doesn't throw if the JSON field has an unexpected type. + */ + fun _currency(): JsonField = body._currency() + + /** + * Returns the raw JSON value of [interval]. + * + * Unlike [interval], this method doesn't throw if the JSON field has an unexpected type. + */ + fun _interval(): JsonField = body._interval() + + /** + * Returns the raw JSON value of [notificationChannel]. + * + * Unlike [notificationChannel], this method doesn't throw if the JSON field has an unexpected + * type. + */ + fun _notificationChannel(): JsonField = body._notificationChannel() + + /** + * Returns the raw JSON value of [thresholdAmount]. + * + * Unlike [thresholdAmount], this method doesn't throw if the JSON field has an unexpected type. + */ + fun _thresholdAmount(): JsonField = body._thresholdAmount() + + fun _additionalBodyProperties(): Map = body._additionalProperties() + + /** Additional headers to send with the request. */ + fun _additionalHeaders(): Headers = additionalHeaders + + /** Additional query param to send with the request. */ + fun _additionalQueryParams(): QueryParams = additionalQueryParams + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of [SpendAlertCreateParams]. + * + * The following fields are required: + * ```java + * .currency() + * .interval() + * .notificationChannel() + * .thresholdAmount() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [SpendAlertCreateParams]. */ + 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 from(spendAlertCreateParams: SpendAlertCreateParams) = apply { + projectId = spendAlertCreateParams.projectId + body = spendAlertCreateParams.body.toBuilder() + additionalHeaders = spendAlertCreateParams.additionalHeaders.toBuilder() + additionalQueryParams = spendAlertCreateParams.additionalQueryParams.toBuilder() + } + + fun projectId(projectId: String?) = apply { this.projectId = projectId } + + /** Alias for calling [Builder.projectId] with `projectId.orElse(null)`. */ + fun projectId(projectId: Optional) = projectId(projectId.getOrNull()) + + /** + * Sets the entire request body. + * + * This is generally only useful if you are already constructing the body separately. + * Otherwise, it's more convenient to use the top-level setters instead: + * - [currency] + * - [interval] + * - [notificationChannel] + * - [thresholdAmount] + */ + fun body(body: Body) = apply { this.body = body.toBuilder() } + + /** The currency for the threshold amount. */ + fun currency(currency: Currency) = apply { body.currency(currency) } + + /** + * Sets [Builder.currency] to an arbitrary JSON value. + * + * You should usually call [Builder.currency] with a well-typed [Currency] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun currency(currency: JsonField) = apply { body.currency(currency) } + + /** The time interval for evaluating spend against the threshold. */ + fun interval(interval: Interval) = apply { body.interval(interval) } + + /** + * Sets [Builder.interval] to an arbitrary JSON value. + * + * You should usually call [Builder.interval] with a well-typed [Interval] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun interval(interval: JsonField) = apply { body.interval(interval) } + + /** Email notification settings for a spend alert. */ + fun notificationChannel(notificationChannel: NotificationChannel) = apply { + body.notificationChannel(notificationChannel) + } + + /** + * Sets [Builder.notificationChannel] to an arbitrary JSON value. + * + * You should usually call [Builder.notificationChannel] with a well-typed + * [NotificationChannel] value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun notificationChannel(notificationChannel: JsonField) = apply { + body.notificationChannel(notificationChannel) + } + + /** The alert threshold amount, in cents. */ + fun thresholdAmount(thresholdAmount: Long) = apply { body.thresholdAmount(thresholdAmount) } + + /** + * Sets [Builder.thresholdAmount] to an arbitrary JSON value. + * + * You should usually call [Builder.thresholdAmount] with a well-typed [Long] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun thresholdAmount(thresholdAmount: JsonField) = apply { + body.thresholdAmount(thresholdAmount) + } + + 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 [SpendAlertCreateParams]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .currency() + * .interval() + * .notificationChannel() + * .thresholdAmount() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): SpendAlertCreateParams = + SpendAlertCreateParams( + projectId, + body.build(), + additionalHeaders.build(), + additionalQueryParams.build(), + ) + } + + fun _body(): Body = body + + fun _pathParam(index: Int): String = + when (index) { + 0 -> projectId ?: "" + else -> "" + } + + override fun _headers(): Headers = additionalHeaders + + override fun _queryParams(): QueryParams = additionalQueryParams + + /** Parameters for creating or updating a spend alert. */ + class Body + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val currency: JsonField, + private val interval: JsonField, + private val notificationChannel: JsonField, + private val thresholdAmount: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("currency") + @ExcludeMissing + currency: JsonField = JsonMissing.of(), + @JsonProperty("interval") + @ExcludeMissing + interval: JsonField = JsonMissing.of(), + @JsonProperty("notification_channel") + @ExcludeMissing + notificationChannel: JsonField = JsonMissing.of(), + @JsonProperty("threshold_amount") + @ExcludeMissing + thresholdAmount: JsonField = JsonMissing.of(), + ) : this(currency, interval, notificationChannel, thresholdAmount, mutableMapOf()) + + /** + * The currency for the threshold amount. + * + * @throws OpenAIInvalidDataException 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 currency(): Currency = currency.getRequired("currency") + + /** + * The time interval for evaluating spend against the threshold. + * + * @throws OpenAIInvalidDataException 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 interval(): Interval = interval.getRequired("interval") + + /** + * Email notification settings for a spend alert. + * + * @throws OpenAIInvalidDataException 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 notificationChannel(): NotificationChannel = + notificationChannel.getRequired("notification_channel") + + /** + * The alert threshold amount, in cents. + * + * @throws OpenAIInvalidDataException 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 thresholdAmount(): Long = thresholdAmount.getRequired("threshold_amount") + + /** + * Returns the raw JSON value of [currency]. + * + * Unlike [currency], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("currency") @ExcludeMissing fun _currency(): JsonField = currency + + /** + * Returns the raw JSON value of [interval]. + * + * Unlike [interval], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("interval") @ExcludeMissing fun _interval(): JsonField = interval + + /** + * Returns the raw JSON value of [notificationChannel]. + * + * Unlike [notificationChannel], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("notification_channel") + @ExcludeMissing + fun _notificationChannel(): JsonField = notificationChannel + + /** + * Returns the raw JSON value of [thresholdAmount]. + * + * Unlike [thresholdAmount], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("threshold_amount") + @ExcludeMissing + fun _thresholdAmount(): JsonField = thresholdAmount + + @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 + * .currency() + * .interval() + * .notificationChannel() + * .thresholdAmount() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [Body]. */ + class Builder internal constructor() { + + private var currency: JsonField? = null + private var interval: JsonField? = null + private var notificationChannel: JsonField? = null + private var thresholdAmount: JsonField? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(body: Body) = apply { + currency = body.currency + interval = body.interval + notificationChannel = body.notificationChannel + thresholdAmount = body.thresholdAmount + additionalProperties = body.additionalProperties.toMutableMap() + } + + /** The currency for the threshold amount. */ + fun currency(currency: Currency) = currency(JsonField.of(currency)) + + /** + * Sets [Builder.currency] to an arbitrary JSON value. + * + * You should usually call [Builder.currency] with a well-typed [Currency] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun currency(currency: JsonField) = apply { this.currency = currency } + + /** The time interval for evaluating spend against the threshold. */ + fun interval(interval: Interval) = interval(JsonField.of(interval)) + + /** + * Sets [Builder.interval] to an arbitrary JSON value. + * + * You should usually call [Builder.interval] with a well-typed [Interval] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun interval(interval: JsonField) = apply { this.interval = interval } + + /** Email notification settings for a spend alert. */ + fun notificationChannel(notificationChannel: NotificationChannel) = + notificationChannel(JsonField.of(notificationChannel)) + + /** + * Sets [Builder.notificationChannel] to an arbitrary JSON value. + * + * You should usually call [Builder.notificationChannel] with a well-typed + * [NotificationChannel] value instead. This method is primarily for setting the field + * to an undocumented or not yet supported value. + */ + fun notificationChannel(notificationChannel: JsonField) = apply { + this.notificationChannel = notificationChannel + } + + /** The alert threshold amount, in cents. */ + fun thresholdAmount(thresholdAmount: Long) = + thresholdAmount(JsonField.of(thresholdAmount)) + + /** + * Sets [Builder.thresholdAmount] to an arbitrary JSON value. + * + * You should usually call [Builder.thresholdAmount] with a well-typed [Long] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun thresholdAmount(thresholdAmount: JsonField) = apply { + this.thresholdAmount = thresholdAmount + } + + 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 + * .currency() + * .interval() + * .notificationChannel() + * .thresholdAmount() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): Body = + Body( + checkRequired("currency", currency), + checkRequired("interval", interval), + checkRequired("notificationChannel", notificationChannel), + checkRequired("thresholdAmount", thresholdAmount), + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing fields. + * + * @throws OpenAIInvalidDataException if any value type in this object doesn't match its + * expected type. + */ + fun validate(): Body = apply { + if (validated) { + return@apply + } + + currency().validate() + interval().validate() + notificationChannel().validate() + thresholdAmount() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OpenAIInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (currency.asKnown().getOrNull()?.validity() ?: 0) + + (interval.asKnown().getOrNull()?.validity() ?: 0) + + (notificationChannel.asKnown().getOrNull()?.validity() ?: 0) + + (if (thresholdAmount.asKnown().isPresent) 1 else 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Body && + currency == other.currency && + interval == other.interval && + notificationChannel == other.notificationChannel && + thresholdAmount == other.thresholdAmount && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + currency, + interval, + notificationChannel, + thresholdAmount, + additionalProperties, + ) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Body{currency=$currency, interval=$interval, notificationChannel=$notificationChannel, thresholdAmount=$thresholdAmount, additionalProperties=$additionalProperties}" + } + + /** The currency for the threshold amount. */ + class Currency @JsonCreator private constructor(private val value: JsonField) : Enum { + + /** + * Returns this class instance's raw value. + * + * This is usually only useful if this instance was deserialized from data that doesn't + * match any known member, and you want to know that value. For example, if the SDK is on an + * older version than the API, then the API may respond with new members that the SDK is + * unaware of. + */ + @com.fasterxml.jackson.annotation.JsonValue fun _value(): JsonField = value + + companion object { + + @JvmField val USD = of("USD") + + @JvmStatic fun of(value: String) = Currency(JsonField.of(value)) + } + + /** An enum containing [Currency]'s known values. */ + enum class Known { + USD + } + + /** + * An enum containing [Currency]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [Currency] can contain an unknown value in a couple of cases: + * - It was deserialized from data that doesn't match any known member. For example, if the + * SDK is on an older version than the API, then the API may respond with new members that + * the SDK is unaware of. + * - It was constructed with an arbitrary value using the [of] method. + */ + enum class Value { + USD, + /** An enum member indicating that [Currency] was instantiated with an unknown value. */ + _UNKNOWN, + } + + /** + * Returns an enum member corresponding to this class instance's value, or [Value._UNKNOWN] + * if the class was instantiated with an unknown value. + * + * Use the [known] method instead if you're certain the value is always known or if you want + * to throw for the unknown case. + */ + fun value(): Value = + when (this) { + USD -> Value.USD + else -> Value._UNKNOWN + } + + /** + * Returns an enum member corresponding to this class instance's value. + * + * Use the [value] method instead if you're uncertain the value is always known and don't + * want to throw for the unknown case. + * + * @throws OpenAIInvalidDataException if this class instance's value is a not a known + * member. + */ + fun known(): Known = + when (this) { + USD -> Known.USD + else -> throw OpenAIInvalidDataException("Unknown Currency: $value") + } + + /** + * Returns this class instance's primitive wire representation. + * + * This differs from the [toString] method because that method is primarily for debugging + * and generally doesn't throw. + * + * @throws OpenAIInvalidDataException if this class instance's value does not have the + * expected primitive type. + */ + fun asString(): String = + _value().asString().orElseThrow { OpenAIInvalidDataException("Value is not a String") } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing fields. + * + * @throws OpenAIInvalidDataException if any value type in this object doesn't match its + * expected type. + */ + fun validate(): Currency = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OpenAIInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Currency && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + /** The time interval for evaluating spend against the threshold. */ + class Interval @JsonCreator private constructor(private val value: JsonField) : Enum { + + /** + * Returns this class instance's raw value. + * + * This is usually only useful if this instance was deserialized from data that doesn't + * match any known member, and you want to know that value. For example, if the SDK is on an + * older version than the API, then the API may respond with new members that the SDK is + * unaware of. + */ + @com.fasterxml.jackson.annotation.JsonValue fun _value(): JsonField = value + + companion object { + + @JvmField val MONTH = of("month") + + @JvmStatic fun of(value: String) = Interval(JsonField.of(value)) + } + + /** An enum containing [Interval]'s known values. */ + enum class Known { + MONTH + } + + /** + * An enum containing [Interval]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [Interval] can contain an unknown value in a couple of cases: + * - It was deserialized from data that doesn't match any known member. For example, if the + * SDK is on an older version than the API, then the API may respond with new members that + * the SDK is unaware of. + * - It was constructed with an arbitrary value using the [of] method. + */ + enum class Value { + MONTH, + /** An enum member indicating that [Interval] was instantiated with an unknown value. */ + _UNKNOWN, + } + + /** + * Returns an enum member corresponding to this class instance's value, or [Value._UNKNOWN] + * if the class was instantiated with an unknown value. + * + * Use the [known] method instead if you're certain the value is always known or if you want + * to throw for the unknown case. + */ + fun value(): Value = + when (this) { + MONTH -> Value.MONTH + else -> Value._UNKNOWN + } + + /** + * Returns an enum member corresponding to this class instance's value. + * + * Use the [value] method instead if you're uncertain the value is always known and don't + * want to throw for the unknown case. + * + * @throws OpenAIInvalidDataException if this class instance's value is a not a known + * member. + */ + fun known(): Known = + when (this) { + MONTH -> Known.MONTH + else -> throw OpenAIInvalidDataException("Unknown Interval: $value") + } + + /** + * Returns this class instance's primitive wire representation. + * + * This differs from the [toString] method because that method is primarily for debugging + * and generally doesn't throw. + * + * @throws OpenAIInvalidDataException if this class instance's value does not have the + * expected primitive type. + */ + fun asString(): String = + _value().asString().orElseThrow { OpenAIInvalidDataException("Value is not a String") } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing fields. + * + * @throws OpenAIInvalidDataException if any value type in this object doesn't match its + * expected type. + */ + fun validate(): Interval = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OpenAIInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Interval && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + /** Email notification settings for a spend alert. */ + class NotificationChannel + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val recipients: JsonField>, + private val type: JsonValue, + private val subjectPrefix: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("recipients") + @ExcludeMissing + recipients: JsonField> = JsonMissing.of(), + @JsonProperty("type") @ExcludeMissing type: JsonValue = JsonMissing.of(), + @JsonProperty("subject_prefix") + @ExcludeMissing + subjectPrefix: JsonField = JsonMissing.of(), + ) : this(recipients, type, subjectPrefix, mutableMapOf()) + + /** + * Email addresses that receive the spend alert notification. + * + * @throws OpenAIInvalidDataException 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 recipients(): List = recipients.getRequired("recipients") + + /** + * The notification channel type. Currently only `email` is supported. + * + * Expected to always return the following: + * ```java + * JsonValue.from("email") + * ``` + * + * However, this method can be useful for debugging and logging (e.g. if the server + * responded with an unexpected value). + */ + @JsonProperty("type") @ExcludeMissing fun _type(): JsonValue = type + + /** + * Optional subject prefix for alert emails. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun subjectPrefix(): Optional = subjectPrefix.getOptional("subject_prefix") + + /** + * Returns the raw JSON value of [recipients]. + * + * Unlike [recipients], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("recipients") + @ExcludeMissing + fun _recipients(): JsonField> = recipients + + /** + * Returns the raw JSON value of [subjectPrefix]. + * + * Unlike [subjectPrefix], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("subject_prefix") + @ExcludeMissing + fun _subjectPrefix(): JsonField = subjectPrefix + + @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 [NotificationChannel]. + * + * The following fields are required: + * ```java + * .recipients() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [NotificationChannel]. */ + class Builder internal constructor() { + + private var recipients: JsonField>? = null + private var type: JsonValue = JsonValue.from("email") + private var subjectPrefix: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(notificationChannel: NotificationChannel) = apply { + recipients = notificationChannel.recipients.map { it.toMutableList() } + type = notificationChannel.type + subjectPrefix = notificationChannel.subjectPrefix + additionalProperties = notificationChannel.additionalProperties.toMutableMap() + } + + /** Email addresses that receive the spend alert notification. */ + fun recipients(recipients: List) = recipients(JsonField.of(recipients)) + + /** + * Sets [Builder.recipients] to an arbitrary JSON value. + * + * You should usually call [Builder.recipients] with a well-typed `List` value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun recipients(recipients: JsonField>) = apply { + this.recipients = recipients.map { it.toMutableList() } + } + + /** + * Adds a single [String] to [recipients]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addRecipient(recipient: String) = apply { + recipients = + (recipients ?: JsonField.of(mutableListOf())).also { + checkKnown("recipients", it).add(recipient) + } + } + + /** + * Sets the field to an arbitrary JSON value. + * + * It is usually unnecessary to call this method because the field defaults to the + * following: + * ```java + * JsonValue.from("email") + * ``` + * + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun type(type: JsonValue) = apply { this.type = type } + + /** Optional subject prefix for alert emails. */ + fun subjectPrefix(subjectPrefix: String?) = + subjectPrefix(JsonField.ofNullable(subjectPrefix)) + + /** Alias for calling [Builder.subjectPrefix] with `subjectPrefix.orElse(null)`. */ + fun subjectPrefix(subjectPrefix: Optional) = + subjectPrefix(subjectPrefix.getOrNull()) + + /** + * Sets [Builder.subjectPrefix] to an arbitrary JSON value. + * + * You should usually call [Builder.subjectPrefix] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun subjectPrefix(subjectPrefix: JsonField) = apply { + this.subjectPrefix = subjectPrefix + } + + 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 [NotificationChannel]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .recipients() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): NotificationChannel = + NotificationChannel( + checkRequired("recipients", recipients).map { it.toImmutable() }, + type, + subjectPrefix, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing fields. + * + * @throws OpenAIInvalidDataException if any value type in this object doesn't match its + * expected type. + */ + fun validate(): NotificationChannel = apply { + if (validated) { + return@apply + } + + recipients() + _type().let { + if (it != JsonValue.from("email")) { + throw OpenAIInvalidDataException("'type' is invalid, received $it") + } + } + subjectPrefix() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OpenAIInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (recipients.asKnown().getOrNull()?.size ?: 0) + + type.let { if (it == JsonValue.from("email")) 1 else 0 } + + (if (subjectPrefix.asKnown().isPresent) 1 else 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is NotificationChannel && + recipients == other.recipients && + type == other.type && + subjectPrefix == other.subjectPrefix && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(recipients, type, subjectPrefix, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "NotificationChannel{recipients=$recipients, type=$type, subjectPrefix=$subjectPrefix, additionalProperties=$additionalProperties}" + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is SpendAlertCreateParams && + projectId == other.projectId && + body == other.body && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams + } + + override fun hashCode(): Int = + Objects.hash(projectId, body, additionalHeaders, additionalQueryParams) + + override fun toString() = + "SpendAlertCreateParams{projectId=$projectId, body=$body, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" +} diff --git a/openai-java-core/src/main/kotlin/com/openai/models/admin/organization/projects/spendalerts/SpendAlertDeleteParams.kt b/openai-java-core/src/main/kotlin/com/openai/models/admin/organization/projects/spendalerts/SpendAlertDeleteParams.kt new file mode 100644 index 000000000..34d9eb805 --- /dev/null +++ b/openai-java-core/src/main/kotlin/com/openai/models/admin/organization/projects/spendalerts/SpendAlertDeleteParams.kt @@ -0,0 +1,259 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.models.admin.organization.projects.spendalerts + +import com.openai.core.JsonValue +import com.openai.core.Params +import com.openai.core.checkRequired +import com.openai.core.http.Headers +import com.openai.core.http.QueryParams +import com.openai.core.toImmutable +import java.util.Objects +import java.util.Optional +import kotlin.jvm.optionals.getOrNull + +/** Deletes a project spend alert. */ +class SpendAlertDeleteParams +private constructor( + private val projectId: String, + private val alertId: String?, + private val additionalHeaders: Headers, + private val additionalQueryParams: QueryParams, + private val additionalBodyProperties: Map, +) : Params { + + fun projectId(): String = projectId + + fun alertId(): Optional = Optional.ofNullable(alertId) + + /** Additional body properties to send with the request. */ + fun _additionalBodyProperties(): Map = additionalBodyProperties + + /** Additional headers to send with the request. */ + fun _additionalHeaders(): Headers = additionalHeaders + + /** Additional query param to send with the request. */ + fun _additionalQueryParams(): QueryParams = additionalQueryParams + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of [SpendAlertDeleteParams]. + * + * The following fields are required: + * ```java + * .projectId() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [SpendAlertDeleteParams]. */ + class Builder internal constructor() { + + private var projectId: String? = null + private var alertId: String? = null + private var additionalHeaders: Headers.Builder = Headers.builder() + private var additionalQueryParams: QueryParams.Builder = QueryParams.builder() + private var additionalBodyProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(spendAlertDeleteParams: SpendAlertDeleteParams) = apply { + projectId = spendAlertDeleteParams.projectId + alertId = spendAlertDeleteParams.alertId + additionalHeaders = spendAlertDeleteParams.additionalHeaders.toBuilder() + additionalQueryParams = spendAlertDeleteParams.additionalQueryParams.toBuilder() + additionalBodyProperties = + spendAlertDeleteParams.additionalBodyProperties.toMutableMap() + } + + fun projectId(projectId: String) = apply { this.projectId = projectId } + + fun alertId(alertId: String?) = apply { this.alertId = alertId } + + /** Alias for calling [Builder.alertId] with `alertId.orElse(null)`. */ + fun alertId(alertId: Optional) = alertId(alertId.getOrNull()) + + 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) + } + + fun additionalBodyProperties(additionalBodyProperties: Map) = apply { + this.additionalBodyProperties.clear() + putAllAdditionalBodyProperties(additionalBodyProperties) + } + + fun putAdditionalBodyProperty(key: String, value: JsonValue) = apply { + additionalBodyProperties.put(key, value) + } + + fun putAllAdditionalBodyProperties(additionalBodyProperties: Map) = + apply { + this.additionalBodyProperties.putAll(additionalBodyProperties) + } + + fun removeAdditionalBodyProperty(key: String) = apply { + additionalBodyProperties.remove(key) + } + + fun removeAllAdditionalBodyProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalBodyProperty) + } + + /** + * Returns an immutable instance of [SpendAlertDeleteParams]. + * + * 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(): SpendAlertDeleteParams = + SpendAlertDeleteParams( + checkRequired("projectId", projectId), + alertId, + additionalHeaders.build(), + additionalQueryParams.build(), + additionalBodyProperties.toImmutable(), + ) + } + + fun _body(): Optional> = + Optional.ofNullable(additionalBodyProperties.ifEmpty { null }) + + fun _pathParam(index: Int): String = + when (index) { + 0 -> projectId + 1 -> alertId ?: "" + else -> "" + } + + override fun _headers(): Headers = additionalHeaders + + override fun _queryParams(): QueryParams = additionalQueryParams + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is SpendAlertDeleteParams && + projectId == other.projectId && + alertId == other.alertId && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams && + additionalBodyProperties == other.additionalBodyProperties + } + + override fun hashCode(): Int = + Objects.hash( + projectId, + alertId, + additionalHeaders, + additionalQueryParams, + additionalBodyProperties, + ) + + override fun toString() = + "SpendAlertDeleteParams{projectId=$projectId, alertId=$alertId, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams, additionalBodyProperties=$additionalBodyProperties}" +} diff --git a/openai-java-core/src/main/kotlin/com/openai/models/admin/organization/projects/spendalerts/SpendAlertListPage.kt b/openai-java-core/src/main/kotlin/com/openai/models/admin/organization/projects/spendalerts/SpendAlertListPage.kt new file mode 100644 index 000000000..c814be830 --- /dev/null +++ b/openai-java-core/src/main/kotlin/com/openai/models/admin/organization/projects/spendalerts/SpendAlertListPage.kt @@ -0,0 +1,139 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.models.admin.organization.projects.spendalerts + +import com.openai.core.AutoPager +import com.openai.core.Page +import com.openai.core.checkRequired +import com.openai.services.blocking.admin.organization.projects.SpendAlertService +import java.util.Objects +import java.util.Optional +import kotlin.jvm.optionals.getOrNull + +/** @see SpendAlertService.list */ +class SpendAlertListPage +private constructor( + private val service: SpendAlertService, + private val params: SpendAlertListParams, + private val response: SpendAlertListPageResponse, +) : Page { + + /** + * Delegates to [SpendAlertListPageResponse], but gracefully handles missing data. + * + * @see SpendAlertListPageResponse.data + */ + fun data(): List = + response._data().getOptional("data").getOrNull() ?: emptyList() + + /** + * Delegates to [SpendAlertListPageResponse], but gracefully handles missing data. + * + * @see SpendAlertListPageResponse.hasMore + */ + fun hasMore(): Optional = response._hasMore().getOptional("has_more") + + /** + * Delegates to [SpendAlertListPageResponse], but gracefully handles missing data. + * + * @see SpendAlertListPageResponse.lastId + */ + fun lastId(): Optional = response._lastId().getOptional("last_id") + + override fun items(): List = data() + + override fun hasNextPage(): Boolean = items().isNotEmpty() && lastId().isPresent + + fun nextPageParams(): SpendAlertListParams { + val nextCursor = + lastId().getOrNull() ?: throw IllegalStateException("Cannot construct next page params") + return params.toBuilder().after(nextCursor).build() + } + + override fun nextPage(): SpendAlertListPage = service.list(nextPageParams()) + + fun autoPager(): AutoPager = AutoPager.from(this) + + /** The parameters that were used to request this page. */ + fun params(): SpendAlertListParams = params + + /** The response that this page was parsed from. */ + fun response(): SpendAlertListPageResponse = response + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of [SpendAlertListPage]. + * + * The following fields are required: + * ```java + * .service() + * .params() + * .response() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [SpendAlertListPage]. */ + class Builder internal constructor() { + + private var service: SpendAlertService? = null + private var params: SpendAlertListParams? = null + private var response: SpendAlertListPageResponse? = null + + @JvmSynthetic + internal fun from(spendAlertListPage: SpendAlertListPage) = apply { + service = spendAlertListPage.service + params = spendAlertListPage.params + response = spendAlertListPage.response + } + + fun service(service: SpendAlertService) = apply { this.service = service } + + /** The parameters that were used to request this page. */ + fun params(params: SpendAlertListParams) = apply { this.params = params } + + /** The response that this page was parsed from. */ + fun response(response: SpendAlertListPageResponse) = apply { this.response = response } + + /** + * Returns an immutable instance of [SpendAlertListPage]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .service() + * .params() + * .response() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): SpendAlertListPage = + SpendAlertListPage( + checkRequired("service", service), + checkRequired("params", params), + checkRequired("response", response), + ) + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is SpendAlertListPage && + service == other.service && + params == other.params && + response == other.response + } + + override fun hashCode(): Int = Objects.hash(service, params, response) + + override fun toString() = + "SpendAlertListPage{service=$service, params=$params, response=$response}" +} diff --git a/openai-java-core/src/main/kotlin/com/openai/models/admin/organization/projects/spendalerts/SpendAlertListPageAsync.kt b/openai-java-core/src/main/kotlin/com/openai/models/admin/organization/projects/spendalerts/SpendAlertListPageAsync.kt new file mode 100644 index 000000000..0c564df69 --- /dev/null +++ b/openai-java-core/src/main/kotlin/com/openai/models/admin/organization/projects/spendalerts/SpendAlertListPageAsync.kt @@ -0,0 +1,154 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.models.admin.organization.projects.spendalerts + +import com.openai.core.AutoPagerAsync +import com.openai.core.PageAsync +import com.openai.core.checkRequired +import com.openai.services.async.admin.organization.projects.SpendAlertServiceAsync +import java.util.Objects +import java.util.Optional +import java.util.concurrent.CompletableFuture +import java.util.concurrent.Executor +import kotlin.jvm.optionals.getOrNull + +/** @see SpendAlertServiceAsync.list */ +class SpendAlertListPageAsync +private constructor( + private val service: SpendAlertServiceAsync, + private val streamHandlerExecutor: Executor, + private val params: SpendAlertListParams, + private val response: SpendAlertListPageResponse, +) : PageAsync { + + /** + * Delegates to [SpendAlertListPageResponse], but gracefully handles missing data. + * + * @see SpendAlertListPageResponse.data + */ + fun data(): List = + response._data().getOptional("data").getOrNull() ?: emptyList() + + /** + * Delegates to [SpendAlertListPageResponse], but gracefully handles missing data. + * + * @see SpendAlertListPageResponse.hasMore + */ + fun hasMore(): Optional = response._hasMore().getOptional("has_more") + + /** + * Delegates to [SpendAlertListPageResponse], but gracefully handles missing data. + * + * @see SpendAlertListPageResponse.lastId + */ + fun lastId(): Optional = response._lastId().getOptional("last_id") + + override fun items(): List = data() + + override fun hasNextPage(): Boolean = items().isNotEmpty() && lastId().isPresent + + fun nextPageParams(): SpendAlertListParams { + val nextCursor = + lastId().getOrNull() ?: throw IllegalStateException("Cannot construct next page params") + return params.toBuilder().after(nextCursor).build() + } + + override fun nextPage(): CompletableFuture = + service.list(nextPageParams()) + + fun autoPager(): AutoPagerAsync = + AutoPagerAsync.from(this, streamHandlerExecutor) + + /** The parameters that were used to request this page. */ + fun params(): SpendAlertListParams = params + + /** The response that this page was parsed from. */ + fun response(): SpendAlertListPageResponse = response + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of [SpendAlertListPageAsync]. + * + * The following fields are required: + * ```java + * .service() + * .streamHandlerExecutor() + * .params() + * .response() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [SpendAlertListPageAsync]. */ + class Builder internal constructor() { + + private var service: SpendAlertServiceAsync? = null + private var streamHandlerExecutor: Executor? = null + private var params: SpendAlertListParams? = null + private var response: SpendAlertListPageResponse? = null + + @JvmSynthetic + internal fun from(spendAlertListPageAsync: SpendAlertListPageAsync) = apply { + service = spendAlertListPageAsync.service + streamHandlerExecutor = spendAlertListPageAsync.streamHandlerExecutor + params = spendAlertListPageAsync.params + response = spendAlertListPageAsync.response + } + + fun service(service: SpendAlertServiceAsync) = apply { this.service = service } + + fun streamHandlerExecutor(streamHandlerExecutor: Executor) = apply { + this.streamHandlerExecutor = streamHandlerExecutor + } + + /** The parameters that were used to request this page. */ + fun params(params: SpendAlertListParams) = apply { this.params = params } + + /** The response that this page was parsed from. */ + fun response(response: SpendAlertListPageResponse) = apply { this.response = response } + + /** + * Returns an immutable instance of [SpendAlertListPageAsync]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .service() + * .streamHandlerExecutor() + * .params() + * .response() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): SpendAlertListPageAsync = + SpendAlertListPageAsync( + checkRequired("service", service), + checkRequired("streamHandlerExecutor", streamHandlerExecutor), + checkRequired("params", params), + checkRequired("response", response), + ) + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is SpendAlertListPageAsync && + service == other.service && + streamHandlerExecutor == other.streamHandlerExecutor && + params == other.params && + response == other.response + } + + override fun hashCode(): Int = Objects.hash(service, streamHandlerExecutor, params, response) + + override fun toString() = + "SpendAlertListPageAsync{service=$service, streamHandlerExecutor=$streamHandlerExecutor, params=$params, response=$response}" +} diff --git a/openai-java-core/src/main/kotlin/com/openai/models/admin/organization/projects/spendalerts/SpendAlertListPageResponse.kt b/openai-java-core/src/main/kotlin/com/openai/models/admin/organization/projects/spendalerts/SpendAlertListPageResponse.kt new file mode 100644 index 000000000..563946bf7 --- /dev/null +++ b/openai-java-core/src/main/kotlin/com/openai/models/admin/organization/projects/spendalerts/SpendAlertListPageResponse.kt @@ -0,0 +1,360 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.models.admin.organization.projects.spendalerts + +import com.fasterxml.jackson.annotation.JsonAnyGetter +import com.fasterxml.jackson.annotation.JsonAnySetter +import com.fasterxml.jackson.annotation.JsonCreator +import com.fasterxml.jackson.annotation.JsonProperty +import com.openai.core.ExcludeMissing +import com.openai.core.JsonField +import com.openai.core.JsonMissing +import com.openai.core.JsonValue +import com.openai.core.checkKnown +import com.openai.core.checkRequired +import com.openai.core.toImmutable +import com.openai.errors.OpenAIInvalidDataException +import java.util.Collections +import java.util.Objects +import java.util.Optional +import kotlin.jvm.optionals.getOrNull + +/** Paginated list of project spend alerts. */ +class SpendAlertListPageResponse +@JsonCreator(mode = JsonCreator.Mode.DISABLED) +private constructor( + private val data: JsonField>, + private val firstId: JsonField, + private val hasMore: JsonField, + private val lastId: JsonField, + private val object_: JsonValue, + private val additionalProperties: MutableMap, +) { + + @JsonCreator + private constructor( + @JsonProperty("data") + @ExcludeMissing + data: JsonField> = JsonMissing.of(), + @JsonProperty("first_id") @ExcludeMissing firstId: JsonField = JsonMissing.of(), + @JsonProperty("has_more") @ExcludeMissing hasMore: JsonField = JsonMissing.of(), + @JsonProperty("last_id") @ExcludeMissing lastId: JsonField = JsonMissing.of(), + @JsonProperty("object") @ExcludeMissing object_: JsonValue = JsonMissing.of(), + ) : this(data, firstId, hasMore, lastId, object_, mutableMapOf()) + + /** + * Spend alerts returned in the current page. + * + * @throws OpenAIInvalidDataException 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(): List = data.getRequired("data") + + /** + * The ID of the first spend alert in this page. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun firstId(): Optional = firstId.getOptional("first_id") + + /** + * Whether more spend alerts are available when paginating. + * + * @throws OpenAIInvalidDataException 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 hasMore(): Boolean = hasMore.getRequired("has_more") + + /** + * The ID of the last spend alert in this page. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun lastId(): Optional = lastId.getOptional("last_id") + + /** + * Always `list`. + * + * Expected to always return the following: + * ```java + * JsonValue.from("list") + * ``` + * + * However, this method can be useful for debugging and logging (e.g. if the server responded + * with an unexpected value). + */ + @JsonProperty("object") @ExcludeMissing fun _object_(): JsonValue = object_ + + /** + * 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 + + /** + * Returns the raw JSON value of [firstId]. + * + * Unlike [firstId], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("first_id") @ExcludeMissing fun _firstId(): JsonField = firstId + + /** + * Returns the raw JSON value of [hasMore]. + * + * Unlike [hasMore], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("has_more") @ExcludeMissing fun _hasMore(): JsonField = hasMore + + /** + * Returns the raw JSON value of [lastId]. + * + * Unlike [lastId], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("last_id") @ExcludeMissing fun _lastId(): JsonField = lastId + + @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 [SpendAlertListPageResponse]. + * + * The following fields are required: + * ```java + * .data() + * .firstId() + * .hasMore() + * .lastId() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [SpendAlertListPageResponse]. */ + class Builder internal constructor() { + + private var data: JsonField>? = null + private var firstId: JsonField? = null + private var hasMore: JsonField? = null + private var lastId: JsonField? = null + private var object_: JsonValue = JsonValue.from("list") + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(spendAlertListPageResponse: SpendAlertListPageResponse) = apply { + data = spendAlertListPageResponse.data.map { it.toMutableList() } + firstId = spendAlertListPageResponse.firstId + hasMore = spendAlertListPageResponse.hasMore + lastId = spendAlertListPageResponse.lastId + object_ = spendAlertListPageResponse.object_ + additionalProperties = spendAlertListPageResponse.additionalProperties.toMutableMap() + } + + /** Spend alerts returned in the current page. */ + fun data(data: List) = data(JsonField.of(data)) + + /** + * Sets [Builder.data] to an arbitrary JSON value. + * + * You should usually call [Builder.data] with a well-typed `List` 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.map { it.toMutableList() } + } + + /** + * Adds a single [ProjectSpendAlert] to [Builder.data]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addData(data: ProjectSpendAlert) = apply { + this.data = + (this.data ?: JsonField.of(mutableListOf())).also { + checkKnown("data", it).add(data) + } + } + + /** The ID of the first spend alert in this page. */ + fun firstId(firstId: String?) = firstId(JsonField.ofNullable(firstId)) + + /** Alias for calling [Builder.firstId] with `firstId.orElse(null)`. */ + fun firstId(firstId: Optional) = firstId(firstId.getOrNull()) + + /** + * Sets [Builder.firstId] to an arbitrary JSON value. + * + * You should usually call [Builder.firstId] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun firstId(firstId: JsonField) = apply { this.firstId = firstId } + + /** Whether more spend alerts are available when paginating. */ + fun hasMore(hasMore: Boolean) = hasMore(JsonField.of(hasMore)) + + /** + * Sets [Builder.hasMore] to an arbitrary JSON value. + * + * You should usually call [Builder.hasMore] with a well-typed [Boolean] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun hasMore(hasMore: JsonField) = apply { this.hasMore = hasMore } + + /** The ID of the last spend alert in this page. */ + fun lastId(lastId: String?) = lastId(JsonField.ofNullable(lastId)) + + /** Alias for calling [Builder.lastId] with `lastId.orElse(null)`. */ + fun lastId(lastId: Optional) = lastId(lastId.getOrNull()) + + /** + * Sets [Builder.lastId] to an arbitrary JSON value. + * + * You should usually call [Builder.lastId] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun lastId(lastId: JsonField) = apply { this.lastId = lastId } + + /** + * Sets the field to an arbitrary JSON value. + * + * It is usually unnecessary to call this method because the field defaults to the + * following: + * ```java + * JsonValue.from("list") + * ``` + * + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun object_(object_: JsonValue) = apply { this.object_ = object_ } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [SpendAlertListPageResponse]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .data() + * .firstId() + * .hasMore() + * .lastId() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): SpendAlertListPageResponse = + SpendAlertListPageResponse( + checkRequired("data", data).map { it.toImmutable() }, + checkRequired("firstId", firstId), + checkRequired("hasMore", hasMore), + checkRequired("lastId", lastId), + object_, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected types recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing fields. + * + * @throws OpenAIInvalidDataException if any value type in this object doesn't match its + * expected type. + */ + fun validate(): SpendAlertListPageResponse = apply { + if (validated) { + return@apply + } + + data().forEach { it.validate() } + firstId() + hasMore() + lastId() + _object_().let { + if (it != JsonValue.from("list")) { + throw OpenAIInvalidDataException("'object_' is invalid, received $it") + } + } + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OpenAIInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (data.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + + (if (firstId.asKnown().isPresent) 1 else 0) + + (if (hasMore.asKnown().isPresent) 1 else 0) + + (if (lastId.asKnown().isPresent) 1 else 0) + + object_.let { if (it == JsonValue.from("list")) 1 else 0 } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is SpendAlertListPageResponse && + data == other.data && + firstId == other.firstId && + hasMore == other.hasMore && + lastId == other.lastId && + object_ == other.object_ && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(data, firstId, hasMore, lastId, object_, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "SpendAlertListPageResponse{data=$data, firstId=$firstId, hasMore=$hasMore, lastId=$lastId, object_=$object_, additionalProperties=$additionalProperties}" +} diff --git a/openai-java-core/src/main/kotlin/com/openai/models/admin/organization/projects/spendalerts/SpendAlertListParams.kt b/openai-java-core/src/main/kotlin/com/openai/models/admin/organization/projects/spendalerts/SpendAlertListParams.kt new file mode 100644 index 000000000..f8b140cd6 --- /dev/null +++ b/openai-java-core/src/main/kotlin/com/openai/models/admin/organization/projects/spendalerts/SpendAlertListParams.kt @@ -0,0 +1,425 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.models.admin.organization.projects.spendalerts + +import com.fasterxml.jackson.annotation.JsonCreator +import com.openai.core.Enum +import com.openai.core.JsonField +import com.openai.core.Params +import com.openai.core.http.Headers +import com.openai.core.http.QueryParams +import com.openai.errors.OpenAIInvalidDataException +import java.util.Objects +import java.util.Optional +import kotlin.jvm.optionals.getOrNull + +/** Lists project spend alerts. */ +class SpendAlertListParams +private constructor( + private val projectId: String?, + private val after: String?, + private val before: String?, + private val limit: Long?, + private val order: Order?, + private val additionalHeaders: Headers, + private val additionalQueryParams: QueryParams, +) : Params { + + fun projectId(): Optional = Optional.ofNullable(projectId) + + /** + * Cursor for pagination. Provide the ID of the last spend alert from the previous response to + * fetch the next page. + */ + fun after(): Optional = Optional.ofNullable(after) + + /** + * Cursor for pagination. Provide the ID of the first spend alert from the previous response to + * fetch the previous page. + */ + fun before(): Optional = Optional.ofNullable(before) + + /** A limit on the number of spend alerts to return. Defaults to 20. */ + fun limit(): Optional = Optional.ofNullable(limit) + + /** Sort order for the returned spend alerts. */ + fun order(): Optional = Optional.ofNullable(order) + + /** Additional headers to send with the request. */ + fun _additionalHeaders(): Headers = additionalHeaders + + /** Additional query param to send with the request. */ + fun _additionalQueryParams(): QueryParams = additionalQueryParams + + fun toBuilder() = Builder().from(this) + + companion object { + + @JvmStatic fun none(): SpendAlertListParams = builder().build() + + /** Returns a mutable builder for constructing an instance of [SpendAlertListParams]. */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [SpendAlertListParams]. */ + class Builder internal constructor() { + + private var projectId: String? = null + private var after: String? = null + private var before: String? = null + private var limit: Long? = null + private var order: Order? = null + private var additionalHeaders: Headers.Builder = Headers.builder() + private var additionalQueryParams: QueryParams.Builder = QueryParams.builder() + + @JvmSynthetic + internal fun from(spendAlertListParams: SpendAlertListParams) = apply { + projectId = spendAlertListParams.projectId + after = spendAlertListParams.after + before = spendAlertListParams.before + limit = spendAlertListParams.limit + order = spendAlertListParams.order + additionalHeaders = spendAlertListParams.additionalHeaders.toBuilder() + additionalQueryParams = spendAlertListParams.additionalQueryParams.toBuilder() + } + + fun projectId(projectId: String?) = apply { this.projectId = projectId } + + /** Alias for calling [Builder.projectId] with `projectId.orElse(null)`. */ + fun projectId(projectId: Optional) = projectId(projectId.getOrNull()) + + /** + * Cursor for pagination. Provide the ID of the last spend alert from the previous response + * to fetch the next page. + */ + fun after(after: String?) = apply { this.after = after } + + /** Alias for calling [Builder.after] with `after.orElse(null)`. */ + fun after(after: Optional) = after(after.getOrNull()) + + /** + * Cursor for pagination. Provide the ID of the first spend alert from the previous response + * to fetch the previous page. + */ + fun before(before: String?) = apply { this.before = before } + + /** Alias for calling [Builder.before] with `before.orElse(null)`. */ + fun before(before: Optional) = before(before.getOrNull()) + + /** A limit on the number of spend alerts to return. Defaults to 20. */ + fun limit(limit: Long?) = apply { this.limit = 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()) + + /** Sort order for the returned spend alerts. */ + fun order(order: Order?) = apply { this.order = order } + + /** Alias for calling [Builder.order] with `order.orElse(null)`. */ + fun order(order: Optional) = order(order.getOrNull()) + + 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 [SpendAlertListParams]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): SpendAlertListParams = + SpendAlertListParams( + projectId, + after, + before, + limit, + order, + additionalHeaders.build(), + additionalQueryParams.build(), + ) + } + + fun _pathParam(index: Int): String = + when (index) { + 0 -> projectId ?: "" + else -> "" + } + + override fun _headers(): Headers = additionalHeaders + + override fun _queryParams(): QueryParams = + QueryParams.builder() + .apply { + after?.let { put("after", it) } + before?.let { put("before", it) } + limit?.let { put("limit", it.toString()) } + order?.let { put("order", it.toString()) } + putAll(additionalQueryParams) + } + .build() + + /** Sort order for the returned spend alerts. */ + class Order @JsonCreator private constructor(private val value: JsonField) : Enum { + + /** + * Returns this class instance's raw value. + * + * This is usually only useful if this instance was deserialized from data that doesn't + * match any known member, and you want to know that value. For example, if the SDK is on an + * older version than the API, then the API may respond with new members that the SDK is + * unaware of. + */ + @com.fasterxml.jackson.annotation.JsonValue fun _value(): JsonField = value + + companion object { + + @JvmField val ASC = of("asc") + + @JvmField val DESC = of("desc") + + @JvmStatic fun of(value: String) = Order(JsonField.of(value)) + } + + /** An enum containing [Order]'s known values. */ + enum class Known { + ASC, + DESC, + } + + /** + * An enum containing [Order]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [Order] can contain an unknown value in a couple of cases: + * - It was deserialized from data that doesn't match any known member. For example, if the + * SDK is on an older version than the API, then the API may respond with new members that + * the SDK is unaware of. + * - It was constructed with an arbitrary value using the [of] method. + */ + enum class Value { + ASC, + DESC, + /** An enum member indicating that [Order] was instantiated with an unknown value. */ + _UNKNOWN, + } + + /** + * Returns an enum member corresponding to this class instance's value, or [Value._UNKNOWN] + * if the class was instantiated with an unknown value. + * + * Use the [known] method instead if you're certain the value is always known or if you want + * to throw for the unknown case. + */ + fun value(): Value = + when (this) { + ASC -> Value.ASC + DESC -> Value.DESC + else -> Value._UNKNOWN + } + + /** + * Returns an enum member corresponding to this class instance's value. + * + * Use the [value] method instead if you're uncertain the value is always known and don't + * want to throw for the unknown case. + * + * @throws OpenAIInvalidDataException if this class instance's value is a not a known + * member. + */ + fun known(): Known = + when (this) { + ASC -> Known.ASC + DESC -> Known.DESC + else -> throw OpenAIInvalidDataException("Unknown Order: $value") + } + + /** + * Returns this class instance's primitive wire representation. + * + * This differs from the [toString] method because that method is primarily for debugging + * and generally doesn't throw. + * + * @throws OpenAIInvalidDataException if this class instance's value does not have the + * expected primitive type. + */ + fun asString(): String = + _value().asString().orElseThrow { OpenAIInvalidDataException("Value is not a String") } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing fields. + * + * @throws OpenAIInvalidDataException if any value type in this object doesn't match its + * expected type. + */ + fun validate(): Order = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OpenAIInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Order && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is SpendAlertListParams && + projectId == other.projectId && + after == other.after && + before == other.before && + limit == other.limit && + order == other.order && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams + } + + override fun hashCode(): Int = + Objects.hash( + projectId, + after, + before, + limit, + order, + additionalHeaders, + additionalQueryParams, + ) + + override fun toString() = + "SpendAlertListParams{projectId=$projectId, after=$after, before=$before, limit=$limit, order=$order, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" +} diff --git a/openai-java-core/src/main/kotlin/com/openai/models/admin/organization/projects/spendalerts/SpendAlertUpdateParams.kt b/openai-java-core/src/main/kotlin/com/openai/models/admin/organization/projects/spendalerts/SpendAlertUpdateParams.kt new file mode 100644 index 000000000..e95d4a270 --- /dev/null +++ b/openai-java-core/src/main/kotlin/com/openai/models/admin/organization/projects/spendalerts/SpendAlertUpdateParams.kt @@ -0,0 +1,1239 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.models.admin.organization.projects.spendalerts + +import com.fasterxml.jackson.annotation.JsonAnyGetter +import com.fasterxml.jackson.annotation.JsonAnySetter +import com.fasterxml.jackson.annotation.JsonCreator +import com.fasterxml.jackson.annotation.JsonProperty +import com.openai.core.Enum +import com.openai.core.ExcludeMissing +import com.openai.core.JsonField +import com.openai.core.JsonMissing +import com.openai.core.JsonValue +import com.openai.core.Params +import com.openai.core.checkKnown +import com.openai.core.checkRequired +import com.openai.core.http.Headers +import com.openai.core.http.QueryParams +import com.openai.core.toImmutable +import com.openai.errors.OpenAIInvalidDataException +import java.util.Collections +import java.util.Objects +import java.util.Optional +import kotlin.jvm.optionals.getOrNull + +/** Updates a project spend alert. */ +class SpendAlertUpdateParams +private constructor( + private val projectId: String, + private val alertId: String?, + private val body: Body, + private val additionalHeaders: Headers, + private val additionalQueryParams: QueryParams, +) : Params { + + fun projectId(): String = projectId + + fun alertId(): Optional = Optional.ofNullable(alertId) + + /** + * The currency for the threshold amount. + * + * @throws OpenAIInvalidDataException 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 currency(): Currency = body.currency() + + /** + * The time interval for evaluating spend against the threshold. + * + * @throws OpenAIInvalidDataException 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 interval(): Interval = body.interval() + + /** + * Email notification settings for a spend alert. + * + * @throws OpenAIInvalidDataException 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 notificationChannel(): NotificationChannel = body.notificationChannel() + + /** + * The alert threshold amount, in cents. + * + * @throws OpenAIInvalidDataException 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 thresholdAmount(): Long = body.thresholdAmount() + + /** + * Returns the raw JSON value of [currency]. + * + * Unlike [currency], this method doesn't throw if the JSON field has an unexpected type. + */ + fun _currency(): JsonField = body._currency() + + /** + * Returns the raw JSON value of [interval]. + * + * Unlike [interval], this method doesn't throw if the JSON field has an unexpected type. + */ + fun _interval(): JsonField = body._interval() + + /** + * Returns the raw JSON value of [notificationChannel]. + * + * Unlike [notificationChannel], this method doesn't throw if the JSON field has an unexpected + * type. + */ + fun _notificationChannel(): JsonField = body._notificationChannel() + + /** + * Returns the raw JSON value of [thresholdAmount]. + * + * Unlike [thresholdAmount], this method doesn't throw if the JSON field has an unexpected type. + */ + fun _thresholdAmount(): JsonField = body._thresholdAmount() + + fun _additionalBodyProperties(): Map = body._additionalProperties() + + /** Additional headers to send with the request. */ + fun _additionalHeaders(): Headers = additionalHeaders + + /** Additional query param to send with the request. */ + fun _additionalQueryParams(): QueryParams = additionalQueryParams + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of [SpendAlertUpdateParams]. + * + * The following fields are required: + * ```java + * .projectId() + * .currency() + * .interval() + * .notificationChannel() + * .thresholdAmount() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [SpendAlertUpdateParams]. */ + class Builder internal constructor() { + + private var projectId: String? = null + private var alertId: 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(spendAlertUpdateParams: SpendAlertUpdateParams) = apply { + projectId = spendAlertUpdateParams.projectId + alertId = spendAlertUpdateParams.alertId + body = spendAlertUpdateParams.body.toBuilder() + additionalHeaders = spendAlertUpdateParams.additionalHeaders.toBuilder() + additionalQueryParams = spendAlertUpdateParams.additionalQueryParams.toBuilder() + } + + fun projectId(projectId: String) = apply { this.projectId = projectId } + + fun alertId(alertId: String?) = apply { this.alertId = alertId } + + /** Alias for calling [Builder.alertId] with `alertId.orElse(null)`. */ + fun alertId(alertId: Optional) = alertId(alertId.getOrNull()) + + /** + * Sets the entire request body. + * + * This is generally only useful if you are already constructing the body separately. + * Otherwise, it's more convenient to use the top-level setters instead: + * - [currency] + * - [interval] + * - [notificationChannel] + * - [thresholdAmount] + */ + fun body(body: Body) = apply { this.body = body.toBuilder() } + + /** The currency for the threshold amount. */ + fun currency(currency: Currency) = apply { body.currency(currency) } + + /** + * Sets [Builder.currency] to an arbitrary JSON value. + * + * You should usually call [Builder.currency] with a well-typed [Currency] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun currency(currency: JsonField) = apply { body.currency(currency) } + + /** The time interval for evaluating spend against the threshold. */ + fun interval(interval: Interval) = apply { body.interval(interval) } + + /** + * Sets [Builder.interval] to an arbitrary JSON value. + * + * You should usually call [Builder.interval] with a well-typed [Interval] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun interval(interval: JsonField) = apply { body.interval(interval) } + + /** Email notification settings for a spend alert. */ + fun notificationChannel(notificationChannel: NotificationChannel) = apply { + body.notificationChannel(notificationChannel) + } + + /** + * Sets [Builder.notificationChannel] to an arbitrary JSON value. + * + * You should usually call [Builder.notificationChannel] with a well-typed + * [NotificationChannel] value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun notificationChannel(notificationChannel: JsonField) = apply { + body.notificationChannel(notificationChannel) + } + + /** The alert threshold amount, in cents. */ + fun thresholdAmount(thresholdAmount: Long) = apply { body.thresholdAmount(thresholdAmount) } + + /** + * Sets [Builder.thresholdAmount] to an arbitrary JSON value. + * + * You should usually call [Builder.thresholdAmount] with a well-typed [Long] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun thresholdAmount(thresholdAmount: JsonField) = apply { + body.thresholdAmount(thresholdAmount) + } + + 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 [SpendAlertUpdateParams]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .projectId() + * .currency() + * .interval() + * .notificationChannel() + * .thresholdAmount() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): SpendAlertUpdateParams = + SpendAlertUpdateParams( + checkRequired("projectId", projectId), + alertId, + body.build(), + additionalHeaders.build(), + additionalQueryParams.build(), + ) + } + + fun _body(): Body = body + + fun _pathParam(index: Int): String = + when (index) { + 0 -> projectId + 1 -> alertId ?: "" + else -> "" + } + + override fun _headers(): Headers = additionalHeaders + + override fun _queryParams(): QueryParams = additionalQueryParams + + /** Parameters for creating or updating a spend alert. */ + class Body + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val currency: JsonField, + private val interval: JsonField, + private val notificationChannel: JsonField, + private val thresholdAmount: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("currency") + @ExcludeMissing + currency: JsonField = JsonMissing.of(), + @JsonProperty("interval") + @ExcludeMissing + interval: JsonField = JsonMissing.of(), + @JsonProperty("notification_channel") + @ExcludeMissing + notificationChannel: JsonField = JsonMissing.of(), + @JsonProperty("threshold_amount") + @ExcludeMissing + thresholdAmount: JsonField = JsonMissing.of(), + ) : this(currency, interval, notificationChannel, thresholdAmount, mutableMapOf()) + + /** + * The currency for the threshold amount. + * + * @throws OpenAIInvalidDataException 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 currency(): Currency = currency.getRequired("currency") + + /** + * The time interval for evaluating spend against the threshold. + * + * @throws OpenAIInvalidDataException 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 interval(): Interval = interval.getRequired("interval") + + /** + * Email notification settings for a spend alert. + * + * @throws OpenAIInvalidDataException 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 notificationChannel(): NotificationChannel = + notificationChannel.getRequired("notification_channel") + + /** + * The alert threshold amount, in cents. + * + * @throws OpenAIInvalidDataException 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 thresholdAmount(): Long = thresholdAmount.getRequired("threshold_amount") + + /** + * Returns the raw JSON value of [currency]. + * + * Unlike [currency], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("currency") @ExcludeMissing fun _currency(): JsonField = currency + + /** + * Returns the raw JSON value of [interval]. + * + * Unlike [interval], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("interval") @ExcludeMissing fun _interval(): JsonField = interval + + /** + * Returns the raw JSON value of [notificationChannel]. + * + * Unlike [notificationChannel], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("notification_channel") + @ExcludeMissing + fun _notificationChannel(): JsonField = notificationChannel + + /** + * Returns the raw JSON value of [thresholdAmount]. + * + * Unlike [thresholdAmount], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("threshold_amount") + @ExcludeMissing + fun _thresholdAmount(): JsonField = thresholdAmount + + @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 + * .currency() + * .interval() + * .notificationChannel() + * .thresholdAmount() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [Body]. */ + class Builder internal constructor() { + + private var currency: JsonField? = null + private var interval: JsonField? = null + private var notificationChannel: JsonField? = null + private var thresholdAmount: JsonField? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(body: Body) = apply { + currency = body.currency + interval = body.interval + notificationChannel = body.notificationChannel + thresholdAmount = body.thresholdAmount + additionalProperties = body.additionalProperties.toMutableMap() + } + + /** The currency for the threshold amount. */ + fun currency(currency: Currency) = currency(JsonField.of(currency)) + + /** + * Sets [Builder.currency] to an arbitrary JSON value. + * + * You should usually call [Builder.currency] with a well-typed [Currency] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun currency(currency: JsonField) = apply { this.currency = currency } + + /** The time interval for evaluating spend against the threshold. */ + fun interval(interval: Interval) = interval(JsonField.of(interval)) + + /** + * Sets [Builder.interval] to an arbitrary JSON value. + * + * You should usually call [Builder.interval] with a well-typed [Interval] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun interval(interval: JsonField) = apply { this.interval = interval } + + /** Email notification settings for a spend alert. */ + fun notificationChannel(notificationChannel: NotificationChannel) = + notificationChannel(JsonField.of(notificationChannel)) + + /** + * Sets [Builder.notificationChannel] to an arbitrary JSON value. + * + * You should usually call [Builder.notificationChannel] with a well-typed + * [NotificationChannel] value instead. This method is primarily for setting the field + * to an undocumented or not yet supported value. + */ + fun notificationChannel(notificationChannel: JsonField) = apply { + this.notificationChannel = notificationChannel + } + + /** The alert threshold amount, in cents. */ + fun thresholdAmount(thresholdAmount: Long) = + thresholdAmount(JsonField.of(thresholdAmount)) + + /** + * Sets [Builder.thresholdAmount] to an arbitrary JSON value. + * + * You should usually call [Builder.thresholdAmount] with a well-typed [Long] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun thresholdAmount(thresholdAmount: JsonField) = apply { + this.thresholdAmount = thresholdAmount + } + + 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 + * .currency() + * .interval() + * .notificationChannel() + * .thresholdAmount() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): Body = + Body( + checkRequired("currency", currency), + checkRequired("interval", interval), + checkRequired("notificationChannel", notificationChannel), + checkRequired("thresholdAmount", thresholdAmount), + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing fields. + * + * @throws OpenAIInvalidDataException if any value type in this object doesn't match its + * expected type. + */ + fun validate(): Body = apply { + if (validated) { + return@apply + } + + currency().validate() + interval().validate() + notificationChannel().validate() + thresholdAmount() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OpenAIInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (currency.asKnown().getOrNull()?.validity() ?: 0) + + (interval.asKnown().getOrNull()?.validity() ?: 0) + + (notificationChannel.asKnown().getOrNull()?.validity() ?: 0) + + (if (thresholdAmount.asKnown().isPresent) 1 else 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Body && + currency == other.currency && + interval == other.interval && + notificationChannel == other.notificationChannel && + thresholdAmount == other.thresholdAmount && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + currency, + interval, + notificationChannel, + thresholdAmount, + additionalProperties, + ) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Body{currency=$currency, interval=$interval, notificationChannel=$notificationChannel, thresholdAmount=$thresholdAmount, additionalProperties=$additionalProperties}" + } + + /** The currency for the threshold amount. */ + class Currency @JsonCreator private constructor(private val value: JsonField) : Enum { + + /** + * Returns this class instance's raw value. + * + * This is usually only useful if this instance was deserialized from data that doesn't + * match any known member, and you want to know that value. For example, if the SDK is on an + * older version than the API, then the API may respond with new members that the SDK is + * unaware of. + */ + @com.fasterxml.jackson.annotation.JsonValue fun _value(): JsonField = value + + companion object { + + @JvmField val USD = of("USD") + + @JvmStatic fun of(value: String) = Currency(JsonField.of(value)) + } + + /** An enum containing [Currency]'s known values. */ + enum class Known { + USD + } + + /** + * An enum containing [Currency]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [Currency] can contain an unknown value in a couple of cases: + * - It was deserialized from data that doesn't match any known member. For example, if the + * SDK is on an older version than the API, then the API may respond with new members that + * the SDK is unaware of. + * - It was constructed with an arbitrary value using the [of] method. + */ + enum class Value { + USD, + /** An enum member indicating that [Currency] was instantiated with an unknown value. */ + _UNKNOWN, + } + + /** + * Returns an enum member corresponding to this class instance's value, or [Value._UNKNOWN] + * if the class was instantiated with an unknown value. + * + * Use the [known] method instead if you're certain the value is always known or if you want + * to throw for the unknown case. + */ + fun value(): Value = + when (this) { + USD -> Value.USD + else -> Value._UNKNOWN + } + + /** + * Returns an enum member corresponding to this class instance's value. + * + * Use the [value] method instead if you're uncertain the value is always known and don't + * want to throw for the unknown case. + * + * @throws OpenAIInvalidDataException if this class instance's value is a not a known + * member. + */ + fun known(): Known = + when (this) { + USD -> Known.USD + else -> throw OpenAIInvalidDataException("Unknown Currency: $value") + } + + /** + * Returns this class instance's primitive wire representation. + * + * This differs from the [toString] method because that method is primarily for debugging + * and generally doesn't throw. + * + * @throws OpenAIInvalidDataException if this class instance's value does not have the + * expected primitive type. + */ + fun asString(): String = + _value().asString().orElseThrow { OpenAIInvalidDataException("Value is not a String") } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing fields. + * + * @throws OpenAIInvalidDataException if any value type in this object doesn't match its + * expected type. + */ + fun validate(): Currency = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OpenAIInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Currency && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + /** The time interval for evaluating spend against the threshold. */ + class Interval @JsonCreator private constructor(private val value: JsonField) : Enum { + + /** + * Returns this class instance's raw value. + * + * This is usually only useful if this instance was deserialized from data that doesn't + * match any known member, and you want to know that value. For example, if the SDK is on an + * older version than the API, then the API may respond with new members that the SDK is + * unaware of. + */ + @com.fasterxml.jackson.annotation.JsonValue fun _value(): JsonField = value + + companion object { + + @JvmField val MONTH = of("month") + + @JvmStatic fun of(value: String) = Interval(JsonField.of(value)) + } + + /** An enum containing [Interval]'s known values. */ + enum class Known { + MONTH + } + + /** + * An enum containing [Interval]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [Interval] can contain an unknown value in a couple of cases: + * - It was deserialized from data that doesn't match any known member. For example, if the + * SDK is on an older version than the API, then the API may respond with new members that + * the SDK is unaware of. + * - It was constructed with an arbitrary value using the [of] method. + */ + enum class Value { + MONTH, + /** An enum member indicating that [Interval] was instantiated with an unknown value. */ + _UNKNOWN, + } + + /** + * Returns an enum member corresponding to this class instance's value, or [Value._UNKNOWN] + * if the class was instantiated with an unknown value. + * + * Use the [known] method instead if you're certain the value is always known or if you want + * to throw for the unknown case. + */ + fun value(): Value = + when (this) { + MONTH -> Value.MONTH + else -> Value._UNKNOWN + } + + /** + * Returns an enum member corresponding to this class instance's value. + * + * Use the [value] method instead if you're uncertain the value is always known and don't + * want to throw for the unknown case. + * + * @throws OpenAIInvalidDataException if this class instance's value is a not a known + * member. + */ + fun known(): Known = + when (this) { + MONTH -> Known.MONTH + else -> throw OpenAIInvalidDataException("Unknown Interval: $value") + } + + /** + * Returns this class instance's primitive wire representation. + * + * This differs from the [toString] method because that method is primarily for debugging + * and generally doesn't throw. + * + * @throws OpenAIInvalidDataException if this class instance's value does not have the + * expected primitive type. + */ + fun asString(): String = + _value().asString().orElseThrow { OpenAIInvalidDataException("Value is not a String") } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing fields. + * + * @throws OpenAIInvalidDataException if any value type in this object doesn't match its + * expected type. + */ + fun validate(): Interval = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OpenAIInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Interval && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + /** Email notification settings for a spend alert. */ + class NotificationChannel + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val recipients: JsonField>, + private val type: JsonValue, + private val subjectPrefix: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("recipients") + @ExcludeMissing + recipients: JsonField> = JsonMissing.of(), + @JsonProperty("type") @ExcludeMissing type: JsonValue = JsonMissing.of(), + @JsonProperty("subject_prefix") + @ExcludeMissing + subjectPrefix: JsonField = JsonMissing.of(), + ) : this(recipients, type, subjectPrefix, mutableMapOf()) + + /** + * Email addresses that receive the spend alert notification. + * + * @throws OpenAIInvalidDataException 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 recipients(): List = recipients.getRequired("recipients") + + /** + * The notification channel type. Currently only `email` is supported. + * + * Expected to always return the following: + * ```java + * JsonValue.from("email") + * ``` + * + * However, this method can be useful for debugging and logging (e.g. if the server + * responded with an unexpected value). + */ + @JsonProperty("type") @ExcludeMissing fun _type(): JsonValue = type + + /** + * Optional subject prefix for alert emails. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun subjectPrefix(): Optional = subjectPrefix.getOptional("subject_prefix") + + /** + * Returns the raw JSON value of [recipients]. + * + * Unlike [recipients], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("recipients") + @ExcludeMissing + fun _recipients(): JsonField> = recipients + + /** + * Returns the raw JSON value of [subjectPrefix]. + * + * Unlike [subjectPrefix], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("subject_prefix") + @ExcludeMissing + fun _subjectPrefix(): JsonField = subjectPrefix + + @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 [NotificationChannel]. + * + * The following fields are required: + * ```java + * .recipients() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [NotificationChannel]. */ + class Builder internal constructor() { + + private var recipients: JsonField>? = null + private var type: JsonValue = JsonValue.from("email") + private var subjectPrefix: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(notificationChannel: NotificationChannel) = apply { + recipients = notificationChannel.recipients.map { it.toMutableList() } + type = notificationChannel.type + subjectPrefix = notificationChannel.subjectPrefix + additionalProperties = notificationChannel.additionalProperties.toMutableMap() + } + + /** Email addresses that receive the spend alert notification. */ + fun recipients(recipients: List) = recipients(JsonField.of(recipients)) + + /** + * Sets [Builder.recipients] to an arbitrary JSON value. + * + * You should usually call [Builder.recipients] with a well-typed `List` value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun recipients(recipients: JsonField>) = apply { + this.recipients = recipients.map { it.toMutableList() } + } + + /** + * Adds a single [String] to [recipients]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addRecipient(recipient: String) = apply { + recipients = + (recipients ?: JsonField.of(mutableListOf())).also { + checkKnown("recipients", it).add(recipient) + } + } + + /** + * Sets the field to an arbitrary JSON value. + * + * It is usually unnecessary to call this method because the field defaults to the + * following: + * ```java + * JsonValue.from("email") + * ``` + * + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun type(type: JsonValue) = apply { this.type = type } + + /** Optional subject prefix for alert emails. */ + fun subjectPrefix(subjectPrefix: String?) = + subjectPrefix(JsonField.ofNullable(subjectPrefix)) + + /** Alias for calling [Builder.subjectPrefix] with `subjectPrefix.orElse(null)`. */ + fun subjectPrefix(subjectPrefix: Optional) = + subjectPrefix(subjectPrefix.getOrNull()) + + /** + * Sets [Builder.subjectPrefix] to an arbitrary JSON value. + * + * You should usually call [Builder.subjectPrefix] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun subjectPrefix(subjectPrefix: JsonField) = apply { + this.subjectPrefix = subjectPrefix + } + + 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 [NotificationChannel]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .recipients() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): NotificationChannel = + NotificationChannel( + checkRequired("recipients", recipients).map { it.toImmutable() }, + type, + subjectPrefix, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing fields. + * + * @throws OpenAIInvalidDataException if any value type in this object doesn't match its + * expected type. + */ + fun validate(): NotificationChannel = apply { + if (validated) { + return@apply + } + + recipients() + _type().let { + if (it != JsonValue.from("email")) { + throw OpenAIInvalidDataException("'type' is invalid, received $it") + } + } + subjectPrefix() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OpenAIInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (recipients.asKnown().getOrNull()?.size ?: 0) + + type.let { if (it == JsonValue.from("email")) 1 else 0 } + + (if (subjectPrefix.asKnown().isPresent) 1 else 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is NotificationChannel && + recipients == other.recipients && + type == other.type && + subjectPrefix == other.subjectPrefix && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(recipients, type, subjectPrefix, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "NotificationChannel{recipients=$recipients, type=$type, subjectPrefix=$subjectPrefix, additionalProperties=$additionalProperties}" + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is SpendAlertUpdateParams && + projectId == other.projectId && + alertId == other.alertId && + body == other.body && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams + } + + override fun hashCode(): Int = + Objects.hash(projectId, alertId, body, additionalHeaders, additionalQueryParams) + + override fun toString() = + "SpendAlertUpdateParams{projectId=$projectId, alertId=$alertId, body=$body, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" +} diff --git a/openai-java-core/src/main/kotlin/com/openai/models/admin/organization/projects/users/roles/RoleListResponse.kt b/openai-java-core/src/main/kotlin/com/openai/models/admin/organization/projects/users/roles/RoleListResponse.kt index 096b63fec..4dcd76291 100644 --- a/openai-java-core/src/main/kotlin/com/openai/models/admin/organization/projects/users/roles/RoleListResponse.kt +++ b/openai-java-core/src/main/kotlin/com/openai/models/admin/organization/projects/users/roles/RoleListResponse.kt @@ -24,6 +24,7 @@ class RoleListResponse @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val id: JsonField, + private val assignmentSources: JsonField>, private val createdAt: JsonField, private val createdBy: JsonField, private val createdByUserObj: JsonField, @@ -40,6 +41,9 @@ private constructor( @JsonCreator private constructor( @JsonProperty("id") @ExcludeMissing id: JsonField = JsonMissing.of(), + @JsonProperty("assignment_sources") + @ExcludeMissing + assignmentSources: JsonField> = JsonMissing.of(), @JsonProperty("created_at") @ExcludeMissing createdAt: JsonField = JsonMissing.of(), @JsonProperty("created_by") @ExcludeMissing createdBy: JsonField = JsonMissing.of(), @JsonProperty("created_by_user_obj") @@ -62,6 +66,7 @@ private constructor( @JsonProperty("updated_at") @ExcludeMissing updatedAt: JsonField = JsonMissing.of(), ) : this( id, + assignmentSources, createdAt, createdBy, createdByUserObj, @@ -83,6 +88,15 @@ private constructor( */ fun id(): String = id.getRequired("id") + /** + * Principals from which the role assignment is inherited, when available. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun assignmentSources(): Optional> = + assignmentSources.getOptional("assignment_sources") + /** * When the role was created. * @@ -171,6 +185,16 @@ private constructor( */ @JsonProperty("id") @ExcludeMissing fun _id(): JsonField = id + /** + * Returns the raw JSON value of [assignmentSources]. + * + * Unlike [assignmentSources], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("assignment_sources") + @ExcludeMissing + fun _assignmentSources(): JsonField> = assignmentSources + /** * Returns the raw JSON value of [createdAt]. * @@ -270,6 +294,7 @@ private constructor( * The following fields are required: * ```java * .id() + * .assignmentSources() * .createdAt() * .createdBy() * .createdByUserObj() @@ -289,6 +314,7 @@ private constructor( class Builder internal constructor() { private var id: JsonField? = null + private var assignmentSources: JsonField>? = null private var createdAt: JsonField? = null private var createdBy: JsonField? = null private var createdByUserObj: JsonField? = null @@ -304,6 +330,7 @@ private constructor( @JvmSynthetic internal fun from(roleListResponse: RoleListResponse) = apply { id = roleListResponse.id + assignmentSources = roleListResponse.assignmentSources.map { it.toMutableList() } createdAt = roleListResponse.createdAt createdBy = roleListResponse.createdBy createdByUserObj = roleListResponse.createdByUserObj @@ -328,6 +355,37 @@ private constructor( */ fun id(id: JsonField) = apply { this.id = id } + /** Principals from which the role assignment is inherited, when available. */ + fun assignmentSources(assignmentSources: List?) = + assignmentSources(JsonField.ofNullable(assignmentSources)) + + /** Alias for calling [Builder.assignmentSources] with `assignmentSources.orElse(null)`. */ + fun assignmentSources(assignmentSources: Optional>) = + assignmentSources(assignmentSources.getOrNull()) + + /** + * Sets [Builder.assignmentSources] to an arbitrary JSON value. + * + * You should usually call [Builder.assignmentSources] with a well-typed + * `List` value instead. This method is primarily for setting the field to + * an undocumented or not yet supported value. + */ + fun assignmentSources(assignmentSources: JsonField>) = apply { + this.assignmentSources = assignmentSources.map { it.toMutableList() } + } + + /** + * Adds a single [AssignmentSource] to [assignmentSources]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addAssignmentSource(assignmentSource: AssignmentSource) = apply { + assignmentSources = + (assignmentSources ?: JsonField.of(mutableListOf())).also { + checkKnown("assignmentSources", it).add(assignmentSource) + } + } + /** When the role was created. */ fun createdAt(createdAt: Long?) = createdAt(JsonField.ofNullable(createdAt)) @@ -526,6 +584,7 @@ private constructor( * The following fields are required: * ```java * .id() + * .assignmentSources() * .createdAt() * .createdBy() * .createdByUserObj() @@ -543,6 +602,7 @@ private constructor( fun build(): RoleListResponse = RoleListResponse( checkRequired("id", id), + checkRequired("assignmentSources", assignmentSources).map { it.toImmutable() }, checkRequired("createdAt", createdAt), checkRequired("createdBy", createdBy), checkRequired("createdByUserObj", createdByUserObj), @@ -573,6 +633,7 @@ private constructor( } id() + assignmentSources().ifPresent { it.forEach { it.validate() } } createdAt() createdBy() createdByUserObj().ifPresent { it.validate() } @@ -602,6 +663,7 @@ private constructor( @JvmSynthetic internal fun validity(): Int = (if (id.asKnown().isPresent) 1 else 0) + + (assignmentSources.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + (if (createdAt.asKnown().isPresent) 1 else 0) + (if (createdBy.asKnown().isPresent) 1 else 0) + (createdByUserObj.asKnown().getOrNull()?.validity() ?: 0) + @@ -613,6 +675,222 @@ private constructor( (if (resourceType.asKnown().isPresent) 1 else 0) + (if (updatedAt.asKnown().isPresent) 1 else 0) + class AssignmentSource + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val principalId: JsonField, + private val principalType: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("principal_id") + @ExcludeMissing + principalId: JsonField = JsonMissing.of(), + @JsonProperty("principal_type") + @ExcludeMissing + principalType: JsonField = JsonMissing.of(), + ) : this(principalId, principalType, mutableMapOf()) + + /** + * @throws OpenAIInvalidDataException 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 principalId(): String = principalId.getRequired("principal_id") + + /** + * @throws OpenAIInvalidDataException 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 principalType(): String = principalType.getRequired("principal_type") + + /** + * Returns the raw JSON value of [principalId]. + * + * Unlike [principalId], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("principal_id") + @ExcludeMissing + fun _principalId(): JsonField = principalId + + /** + * Returns the raw JSON value of [principalType]. + * + * Unlike [principalType], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("principal_type") + @ExcludeMissing + fun _principalType(): JsonField = principalType + + @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 [AssignmentSource]. + * + * The following fields are required: + * ```java + * .principalId() + * .principalType() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [AssignmentSource]. */ + class Builder internal constructor() { + + private var principalId: JsonField? = null + private var principalType: JsonField? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(assignmentSource: AssignmentSource) = apply { + principalId = assignmentSource.principalId + principalType = assignmentSource.principalType + additionalProperties = assignmentSource.additionalProperties.toMutableMap() + } + + fun principalId(principalId: String) = principalId(JsonField.of(principalId)) + + /** + * Sets [Builder.principalId] to an arbitrary JSON value. + * + * You should usually call [Builder.principalId] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun principalId(principalId: JsonField) = apply { + this.principalId = principalId + } + + fun principalType(principalType: String) = principalType(JsonField.of(principalType)) + + /** + * Sets [Builder.principalType] to an arbitrary JSON value. + * + * You should usually call [Builder.principalType] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun principalType(principalType: JsonField) = apply { + this.principalType = principalType + } + + 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 [AssignmentSource]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .principalId() + * .principalType() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): AssignmentSource = + AssignmentSource( + checkRequired("principalId", principalId), + checkRequired("principalType", principalType), + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing fields. + * + * @throws OpenAIInvalidDataException if any value type in this object doesn't match its + * expected type. + */ + fun validate(): AssignmentSource = apply { + if (validated) { + return@apply + } + + principalId() + principalType() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OpenAIInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (if (principalId.asKnown().isPresent) 1 else 0) + + (if (principalType.asKnown().isPresent) 1 else 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is AssignmentSource && + principalId == other.principalId && + principalType == other.principalType && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(principalId, principalType, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "AssignmentSource{principalId=$principalId, principalType=$principalType, additionalProperties=$additionalProperties}" + } + /** User details for the actor that created the role, when available. */ class CreatedByUserObj @JsonCreator @@ -838,6 +1116,7 @@ private constructor( return other is RoleListResponse && id == other.id && + assignmentSources == other.assignmentSources && createdAt == other.createdAt && createdBy == other.createdBy && createdByUserObj == other.createdByUserObj && @@ -854,6 +1133,7 @@ private constructor( private val hashCode: Int by lazy { Objects.hash( id, + assignmentSources, createdAt, createdBy, createdByUserObj, @@ -871,5 +1151,5 @@ private constructor( override fun hashCode(): Int = hashCode override fun toString() = - "RoleListResponse{id=$id, createdAt=$createdAt, createdBy=$createdBy, createdByUserObj=$createdByUserObj, description=$description, metadata=$metadata, name=$name, permissions=$permissions, predefinedRole=$predefinedRole, resourceType=$resourceType, updatedAt=$updatedAt, additionalProperties=$additionalProperties}" + "RoleListResponse{id=$id, assignmentSources=$assignmentSources, createdAt=$createdAt, createdBy=$createdBy, createdByUserObj=$createdByUserObj, description=$description, metadata=$metadata, name=$name, permissions=$permissions, predefinedRole=$predefinedRole, resourceType=$resourceType, updatedAt=$updatedAt, additionalProperties=$additionalProperties}" } diff --git a/openai-java-core/src/main/kotlin/com/openai/models/admin/organization/projects/users/roles/RoleRetrieveParams.kt b/openai-java-core/src/main/kotlin/com/openai/models/admin/organization/projects/users/roles/RoleRetrieveParams.kt new file mode 100644 index 000000000..d7ebda086 --- /dev/null +++ b/openai-java-core/src/main/kotlin/com/openai/models/admin/organization/projects/users/roles/RoleRetrieveParams.kt @@ -0,0 +1,229 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.models.admin.organization.projects.users.roles + +import com.openai.core.Params +import com.openai.core.checkRequired +import com.openai.core.http.Headers +import com.openai.core.http.QueryParams +import java.util.Objects +import java.util.Optional +import kotlin.jvm.optionals.getOrNull + +/** Retrieves a project role assigned to a user. */ +class RoleRetrieveParams +private constructor( + private val projectId: String, + private val userId: String, + private val roleId: String?, + private val additionalHeaders: Headers, + private val additionalQueryParams: QueryParams, +) : Params { + + fun projectId(): String = projectId + + fun userId(): String = userId + + fun roleId(): Optional = Optional.ofNullable(roleId) + + /** Additional headers to send with the request. */ + fun _additionalHeaders(): Headers = additionalHeaders + + /** Additional query param to send with the request. */ + fun _additionalQueryParams(): QueryParams = additionalQueryParams + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of [RoleRetrieveParams]. + * + * The following fields are required: + * ```java + * .projectId() + * .userId() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [RoleRetrieveParams]. */ + class Builder internal constructor() { + + private var projectId: String? = null + private var userId: String? = null + private var roleId: String? = null + private var additionalHeaders: Headers.Builder = Headers.builder() + private var additionalQueryParams: QueryParams.Builder = QueryParams.builder() + + @JvmSynthetic + internal fun from(roleRetrieveParams: RoleRetrieveParams) = apply { + projectId = roleRetrieveParams.projectId + userId = roleRetrieveParams.userId + roleId = roleRetrieveParams.roleId + additionalHeaders = roleRetrieveParams.additionalHeaders.toBuilder() + additionalQueryParams = roleRetrieveParams.additionalQueryParams.toBuilder() + } + + fun projectId(projectId: String) = apply { this.projectId = projectId } + + fun userId(userId: String) = apply { this.userId = userId } + + fun roleId(roleId: String?) = apply { this.roleId = roleId } + + /** Alias for calling [Builder.roleId] with `roleId.orElse(null)`. */ + fun roleId(roleId: Optional) = roleId(roleId.getOrNull()) + + 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 [RoleRetrieveParams]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .projectId() + * .userId() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): RoleRetrieveParams = + RoleRetrieveParams( + checkRequired("projectId", projectId), + checkRequired("userId", userId), + roleId, + additionalHeaders.build(), + additionalQueryParams.build(), + ) + } + + fun _pathParam(index: Int): String = + when (index) { + 0 -> projectId + 1 -> userId + 2 -> roleId ?: "" + else -> "" + } + + override fun _headers(): Headers = additionalHeaders + + override fun _queryParams(): QueryParams = additionalQueryParams + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is RoleRetrieveParams && + projectId == other.projectId && + userId == other.userId && + roleId == other.roleId && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams + } + + override fun hashCode(): Int = + Objects.hash(projectId, userId, roleId, additionalHeaders, additionalQueryParams) + + override fun toString() = + "RoleRetrieveParams{projectId=$projectId, userId=$userId, roleId=$roleId, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" +} diff --git a/openai-java-core/src/main/kotlin/com/openai/models/admin/organization/projects/users/roles/RoleRetrieveResponse.kt b/openai-java-core/src/main/kotlin/com/openai/models/admin/organization/projects/users/roles/RoleRetrieveResponse.kt new file mode 100644 index 000000000..c49e1f801 --- /dev/null +++ b/openai-java-core/src/main/kotlin/com/openai/models/admin/organization/projects/users/roles/RoleRetrieveResponse.kt @@ -0,0 +1,1155 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.models.admin.organization.projects.users.roles + +import com.fasterxml.jackson.annotation.JsonAnyGetter +import com.fasterxml.jackson.annotation.JsonAnySetter +import com.fasterxml.jackson.annotation.JsonCreator +import com.fasterxml.jackson.annotation.JsonProperty +import com.openai.core.ExcludeMissing +import com.openai.core.JsonField +import com.openai.core.JsonMissing +import com.openai.core.JsonValue +import com.openai.core.checkKnown +import com.openai.core.checkRequired +import com.openai.core.toImmutable +import com.openai.errors.OpenAIInvalidDataException +import java.util.Collections +import java.util.Objects +import java.util.Optional +import kotlin.jvm.optionals.getOrNull + +/** Detailed information about a role assignment entry returned when listing assignments. */ +class RoleRetrieveResponse +@JsonCreator(mode = JsonCreator.Mode.DISABLED) +private constructor( + private val id: JsonField, + private val assignmentSources: JsonField>, + private val createdAt: JsonField, + private val createdBy: JsonField, + private val createdByUserObj: JsonField, + private val description: JsonField, + private val metadata: JsonField, + private val name: JsonField, + private val permissions: JsonField>, + private val predefinedRole: JsonField, + private val resourceType: JsonField, + private val updatedAt: JsonField, + private val additionalProperties: MutableMap, +) { + + @JsonCreator + private constructor( + @JsonProperty("id") @ExcludeMissing id: JsonField = JsonMissing.of(), + @JsonProperty("assignment_sources") + @ExcludeMissing + assignmentSources: JsonField> = JsonMissing.of(), + @JsonProperty("created_at") @ExcludeMissing createdAt: JsonField = JsonMissing.of(), + @JsonProperty("created_by") @ExcludeMissing createdBy: JsonField = JsonMissing.of(), + @JsonProperty("created_by_user_obj") + @ExcludeMissing + createdByUserObj: 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("permissions") + @ExcludeMissing + permissions: JsonField> = JsonMissing.of(), + @JsonProperty("predefined_role") + @ExcludeMissing + predefinedRole: JsonField = JsonMissing.of(), + @JsonProperty("resource_type") + @ExcludeMissing + resourceType: JsonField = JsonMissing.of(), + @JsonProperty("updated_at") @ExcludeMissing updatedAt: JsonField = JsonMissing.of(), + ) : this( + id, + assignmentSources, + createdAt, + createdBy, + createdByUserObj, + description, + metadata, + name, + permissions, + predefinedRole, + resourceType, + updatedAt, + mutableMapOf(), + ) + + /** + * Identifier for the role. + * + * @throws OpenAIInvalidDataException 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 id(): String = id.getRequired("id") + + /** + * Principals from which the role assignment is inherited, when available. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun assignmentSources(): Optional> = + assignmentSources.getOptional("assignment_sources") + + /** + * When the role was created. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun createdAt(): Optional = createdAt.getOptional("created_at") + + /** + * Identifier of the actor who created the role. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun createdBy(): Optional = createdBy.getOptional("created_by") + + /** + * User details for the actor that created the role, when available. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun createdByUserObj(): Optional = + createdByUserObj.getOptional("created_by_user_obj") + + /** + * Description of the role. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun description(): Optional = description.getOptional("description") + + /** + * Arbitrary metadata stored on the role. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun metadata(): Optional = metadata.getOptional("metadata") + + /** + * Name of the role. + * + * @throws OpenAIInvalidDataException 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") + + /** + * Permissions associated with the role. + * + * @throws OpenAIInvalidDataException 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 permissions(): List = permissions.getRequired("permissions") + + /** + * Whether the role is predefined by OpenAI. + * + * @throws OpenAIInvalidDataException 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 predefinedRole(): Boolean = predefinedRole.getRequired("predefined_role") + + /** + * Resource type the role applies to. + * + * @throws OpenAIInvalidDataException 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 resourceType(): String = resourceType.getRequired("resource_type") + + /** + * When the role was last updated. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun updatedAt(): Optional = updatedAt.getOptional("updated_at") + + /** + * Returns the raw JSON value of [id]. + * + * Unlike [id], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("id") @ExcludeMissing fun _id(): JsonField = id + + /** + * Returns the raw JSON value of [assignmentSources]. + * + * Unlike [assignmentSources], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("assignment_sources") + @ExcludeMissing + fun _assignmentSources(): JsonField> = assignmentSources + + /** + * Returns the raw JSON value of [createdAt]. + * + * Unlike [createdAt], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("created_at") @ExcludeMissing fun _createdAt(): JsonField = createdAt + + /** + * Returns the raw JSON value of [createdBy]. + * + * Unlike [createdBy], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("created_by") @ExcludeMissing fun _createdBy(): JsonField = createdBy + + /** + * Returns the raw JSON value of [createdByUserObj]. + * + * Unlike [createdByUserObj], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("created_by_user_obj") + @ExcludeMissing + fun _createdByUserObj(): JsonField = createdByUserObj + + /** + * 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 + + /** + * Returns the raw JSON value of [permissions]. + * + * Unlike [permissions], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("permissions") + @ExcludeMissing + fun _permissions(): JsonField> = permissions + + /** + * Returns the raw JSON value of [predefinedRole]. + * + * Unlike [predefinedRole], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("predefined_role") + @ExcludeMissing + fun _predefinedRole(): JsonField = predefinedRole + + /** + * Returns the raw JSON value of [resourceType]. + * + * Unlike [resourceType], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("resource_type") + @ExcludeMissing + fun _resourceType(): JsonField = resourceType + + /** + * Returns the raw JSON value of [updatedAt]. + * + * Unlike [updatedAt], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("updated_at") @ExcludeMissing fun _updatedAt(): JsonField = updatedAt + + @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 [RoleRetrieveResponse]. + * + * The following fields are required: + * ```java + * .id() + * .assignmentSources() + * .createdAt() + * .createdBy() + * .createdByUserObj() + * .description() + * .metadata() + * .name() + * .permissions() + * .predefinedRole() + * .resourceType() + * .updatedAt() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [RoleRetrieveResponse]. */ + class Builder internal constructor() { + + private var id: JsonField? = null + private var assignmentSources: JsonField>? = null + private var createdAt: JsonField? = null + private var createdBy: JsonField? = null + private var createdByUserObj: JsonField? = null + private var description: JsonField? = null + private var metadata: JsonField? = null + private var name: JsonField? = null + private var permissions: JsonField>? = null + private var predefinedRole: JsonField? = null + private var resourceType: JsonField? = null + private var updatedAt: JsonField? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(roleRetrieveResponse: RoleRetrieveResponse) = apply { + id = roleRetrieveResponse.id + assignmentSources = roleRetrieveResponse.assignmentSources.map { it.toMutableList() } + createdAt = roleRetrieveResponse.createdAt + createdBy = roleRetrieveResponse.createdBy + createdByUserObj = roleRetrieveResponse.createdByUserObj + description = roleRetrieveResponse.description + metadata = roleRetrieveResponse.metadata + name = roleRetrieveResponse.name + permissions = roleRetrieveResponse.permissions.map { it.toMutableList() } + predefinedRole = roleRetrieveResponse.predefinedRole + resourceType = roleRetrieveResponse.resourceType + updatedAt = roleRetrieveResponse.updatedAt + additionalProperties = roleRetrieveResponse.additionalProperties.toMutableMap() + } + + /** Identifier for the role. */ + fun id(id: String) = id(JsonField.of(id)) + + /** + * Sets [Builder.id] to an arbitrary JSON value. + * + * You should usually call [Builder.id] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun id(id: JsonField) = apply { this.id = id } + + /** Principals from which the role assignment is inherited, when available. */ + fun assignmentSources(assignmentSources: List?) = + assignmentSources(JsonField.ofNullable(assignmentSources)) + + /** Alias for calling [Builder.assignmentSources] with `assignmentSources.orElse(null)`. */ + fun assignmentSources(assignmentSources: Optional>) = + assignmentSources(assignmentSources.getOrNull()) + + /** + * Sets [Builder.assignmentSources] to an arbitrary JSON value. + * + * You should usually call [Builder.assignmentSources] with a well-typed + * `List` value instead. This method is primarily for setting the field to + * an undocumented or not yet supported value. + */ + fun assignmentSources(assignmentSources: JsonField>) = apply { + this.assignmentSources = assignmentSources.map { it.toMutableList() } + } + + /** + * Adds a single [AssignmentSource] to [assignmentSources]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addAssignmentSource(assignmentSource: AssignmentSource) = apply { + assignmentSources = + (assignmentSources ?: JsonField.of(mutableListOf())).also { + checkKnown("assignmentSources", it).add(assignmentSource) + } + } + + /** When the role was created. */ + fun createdAt(createdAt: Long?) = createdAt(JsonField.ofNullable(createdAt)) + + /** + * Alias for [Builder.createdAt]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun createdAt(createdAt: Long) = createdAt(createdAt as Long?) + + /** Alias for calling [Builder.createdAt] with `createdAt.orElse(null)`. */ + fun createdAt(createdAt: Optional) = createdAt(createdAt.getOrNull()) + + /** + * Sets [Builder.createdAt] to an arbitrary JSON value. + * + * You should usually call [Builder.createdAt] with a well-typed [Long] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun createdAt(createdAt: JsonField) = apply { this.createdAt = createdAt } + + /** Identifier of the actor who created the role. */ + fun createdBy(createdBy: String?) = createdBy(JsonField.ofNullable(createdBy)) + + /** Alias for calling [Builder.createdBy] with `createdBy.orElse(null)`. */ + fun createdBy(createdBy: Optional) = createdBy(createdBy.getOrNull()) + + /** + * Sets [Builder.createdBy] to an arbitrary JSON value. + * + * You should usually call [Builder.createdBy] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun createdBy(createdBy: JsonField) = apply { this.createdBy = createdBy } + + /** User details for the actor that created the role, when available. */ + fun createdByUserObj(createdByUserObj: CreatedByUserObj?) = + createdByUserObj(JsonField.ofNullable(createdByUserObj)) + + /** Alias for calling [Builder.createdByUserObj] with `createdByUserObj.orElse(null)`. */ + fun createdByUserObj(createdByUserObj: Optional) = + createdByUserObj(createdByUserObj.getOrNull()) + + /** + * Sets [Builder.createdByUserObj] to an arbitrary JSON value. + * + * You should usually call [Builder.createdByUserObj] with a well-typed [CreatedByUserObj] + * value instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun createdByUserObj(createdByUserObj: JsonField) = apply { + this.createdByUserObj = createdByUserObj + } + + /** 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 } + + /** Arbitrary metadata stored on the role. */ + 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 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 } + + /** Permissions associated with the role. */ + fun permissions(permissions: List) = permissions(JsonField.of(permissions)) + + /** + * Sets [Builder.permissions] to an arbitrary JSON value. + * + * You should usually call [Builder.permissions] with a well-typed `List` value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun permissions(permissions: JsonField>) = apply { + this.permissions = permissions.map { it.toMutableList() } + } + + /** + * Adds a single [String] to [permissions]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addPermission(permission: String) = apply { + permissions = + (permissions ?: JsonField.of(mutableListOf())).also { + checkKnown("permissions", it).add(permission) + } + } + + /** Whether the role is predefined by OpenAI. */ + fun predefinedRole(predefinedRole: Boolean) = predefinedRole(JsonField.of(predefinedRole)) + + /** + * Sets [Builder.predefinedRole] to an arbitrary JSON value. + * + * You should usually call [Builder.predefinedRole] with a well-typed [Boolean] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun predefinedRole(predefinedRole: JsonField) = apply { + this.predefinedRole = predefinedRole + } + + /** Resource type the role applies to. */ + fun resourceType(resourceType: String) = resourceType(JsonField.of(resourceType)) + + /** + * Sets [Builder.resourceType] to an arbitrary JSON value. + * + * You should usually call [Builder.resourceType] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun resourceType(resourceType: JsonField) = apply { + this.resourceType = resourceType + } + + /** When the role was last updated. */ + fun updatedAt(updatedAt: Long?) = updatedAt(JsonField.ofNullable(updatedAt)) + + /** + * Alias for [Builder.updatedAt]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun updatedAt(updatedAt: Long) = updatedAt(updatedAt as Long?) + + /** Alias for calling [Builder.updatedAt] with `updatedAt.orElse(null)`. */ + fun updatedAt(updatedAt: Optional) = updatedAt(updatedAt.getOrNull()) + + /** + * Sets [Builder.updatedAt] to an arbitrary JSON value. + * + * You should usually call [Builder.updatedAt] with a well-typed [Long] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun updatedAt(updatedAt: JsonField) = apply { this.updatedAt = updatedAt } + + 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 [RoleRetrieveResponse]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .id() + * .assignmentSources() + * .createdAt() + * .createdBy() + * .createdByUserObj() + * .description() + * .metadata() + * .name() + * .permissions() + * .predefinedRole() + * .resourceType() + * .updatedAt() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): RoleRetrieveResponse = + RoleRetrieveResponse( + checkRequired("id", id), + checkRequired("assignmentSources", assignmentSources).map { it.toImmutable() }, + checkRequired("createdAt", createdAt), + checkRequired("createdBy", createdBy), + checkRequired("createdByUserObj", createdByUserObj), + checkRequired("description", description), + checkRequired("metadata", metadata), + checkRequired("name", name), + checkRequired("permissions", permissions).map { it.toImmutable() }, + checkRequired("predefinedRole", predefinedRole), + checkRequired("resourceType", resourceType), + checkRequired("updatedAt", updatedAt), + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected types recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing fields. + * + * @throws OpenAIInvalidDataException if any value type in this object doesn't match its + * expected type. + */ + fun validate(): RoleRetrieveResponse = apply { + if (validated) { + return@apply + } + + id() + assignmentSources().ifPresent { it.forEach { it.validate() } } + createdAt() + createdBy() + createdByUserObj().ifPresent { it.validate() } + description() + metadata().ifPresent { it.validate() } + name() + permissions() + predefinedRole() + resourceType() + updatedAt() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OpenAIInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (if (id.asKnown().isPresent) 1 else 0) + + (assignmentSources.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + + (if (createdAt.asKnown().isPresent) 1 else 0) + + (if (createdBy.asKnown().isPresent) 1 else 0) + + (createdByUserObj.asKnown().getOrNull()?.validity() ?: 0) + + (if (description.asKnown().isPresent) 1 else 0) + + (metadata.asKnown().getOrNull()?.validity() ?: 0) + + (if (name.asKnown().isPresent) 1 else 0) + + (permissions.asKnown().getOrNull()?.size ?: 0) + + (if (predefinedRole.asKnown().isPresent) 1 else 0) + + (if (resourceType.asKnown().isPresent) 1 else 0) + + (if (updatedAt.asKnown().isPresent) 1 else 0) + + class AssignmentSource + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val principalId: JsonField, + private val principalType: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("principal_id") + @ExcludeMissing + principalId: JsonField = JsonMissing.of(), + @JsonProperty("principal_type") + @ExcludeMissing + principalType: JsonField = JsonMissing.of(), + ) : this(principalId, principalType, mutableMapOf()) + + /** + * @throws OpenAIInvalidDataException 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 principalId(): String = principalId.getRequired("principal_id") + + /** + * @throws OpenAIInvalidDataException 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 principalType(): String = principalType.getRequired("principal_type") + + /** + * Returns the raw JSON value of [principalId]. + * + * Unlike [principalId], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("principal_id") + @ExcludeMissing + fun _principalId(): JsonField = principalId + + /** + * Returns the raw JSON value of [principalType]. + * + * Unlike [principalType], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("principal_type") + @ExcludeMissing + fun _principalType(): JsonField = principalType + + @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 [AssignmentSource]. + * + * The following fields are required: + * ```java + * .principalId() + * .principalType() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [AssignmentSource]. */ + class Builder internal constructor() { + + private var principalId: JsonField? = null + private var principalType: JsonField? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(assignmentSource: AssignmentSource) = apply { + principalId = assignmentSource.principalId + principalType = assignmentSource.principalType + additionalProperties = assignmentSource.additionalProperties.toMutableMap() + } + + fun principalId(principalId: String) = principalId(JsonField.of(principalId)) + + /** + * Sets [Builder.principalId] to an arbitrary JSON value. + * + * You should usually call [Builder.principalId] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun principalId(principalId: JsonField) = apply { + this.principalId = principalId + } + + fun principalType(principalType: String) = principalType(JsonField.of(principalType)) + + /** + * Sets [Builder.principalType] to an arbitrary JSON value. + * + * You should usually call [Builder.principalType] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun principalType(principalType: JsonField) = apply { + this.principalType = principalType + } + + 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 [AssignmentSource]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .principalId() + * .principalType() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): AssignmentSource = + AssignmentSource( + checkRequired("principalId", principalId), + checkRequired("principalType", principalType), + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing fields. + * + * @throws OpenAIInvalidDataException if any value type in this object doesn't match its + * expected type. + */ + fun validate(): AssignmentSource = apply { + if (validated) { + return@apply + } + + principalId() + principalType() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OpenAIInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (if (principalId.asKnown().isPresent) 1 else 0) + + (if (principalType.asKnown().isPresent) 1 else 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is AssignmentSource && + principalId == other.principalId && + principalType == other.principalType && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(principalId, principalType, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "AssignmentSource{principalId=$principalId, principalType=$principalType, additionalProperties=$additionalProperties}" + } + + /** User details for the actor that created the role, when available. */ + class CreatedByUserObj + @JsonCreator + private constructor( + @com.fasterxml.jackson.annotation.JsonValue + private val additionalProperties: Map + ) { + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = additionalProperties + + fun toBuilder() = Builder().from(this) + + companion object { + + /** Returns a mutable builder for constructing an instance of [CreatedByUserObj]. */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [CreatedByUserObj]. */ + class Builder internal constructor() { + + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(createdByUserObj: CreatedByUserObj) = apply { + additionalProperties = createdByUserObj.additionalProperties.toMutableMap() + } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [CreatedByUserObj]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): CreatedByUserObj = CreatedByUserObj(additionalProperties.toImmutable()) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing fields. + * + * @throws OpenAIInvalidDataException if any value type in this object doesn't match its + * expected type. + */ + fun validate(): CreatedByUserObj = apply { + if (validated) { + return@apply + } + + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OpenAIInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + additionalProperties.count { (_, value) -> !value.isNull() && !value.isMissing() } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is CreatedByUserObj && additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = "CreatedByUserObj{additionalProperties=$additionalProperties}" + } + + /** Arbitrary metadata stored on the role. */ + class Metadata + @JsonCreator + private constructor( + @com.fasterxml.jackson.annotation.JsonValue + private val additionalProperties: Map + ) { + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = additionalProperties + + fun toBuilder() = Builder().from(this) + + companion object { + + /** Returns a mutable builder for constructing an instance of [Metadata]. */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [Metadata]. */ + class Builder internal constructor() { + + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(metadata: Metadata) = apply { + additionalProperties = metadata.additionalProperties.toMutableMap() + } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [Metadata]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): Metadata = Metadata(additionalProperties.toImmutable()) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing fields. + * + * @throws OpenAIInvalidDataException if any value type in this object doesn't match its + * expected type. + */ + fun validate(): Metadata = apply { + if (validated) { + return@apply + } + + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OpenAIInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + additionalProperties.count { (_, value) -> !value.isNull() && !value.isMissing() } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Metadata && additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = "Metadata{additionalProperties=$additionalProperties}" + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is RoleRetrieveResponse && + id == other.id && + assignmentSources == other.assignmentSources && + createdAt == other.createdAt && + createdBy == other.createdBy && + createdByUserObj == other.createdByUserObj && + description == other.description && + metadata == other.metadata && + name == other.name && + permissions == other.permissions && + predefinedRole == other.predefinedRole && + resourceType == other.resourceType && + updatedAt == other.updatedAt && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + id, + assignmentSources, + createdAt, + createdBy, + createdByUserObj, + description, + metadata, + name, + permissions, + predefinedRole, + resourceType, + updatedAt, + additionalProperties, + ) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "RoleRetrieveResponse{id=$id, assignmentSources=$assignmentSources, createdAt=$createdAt, createdBy=$createdBy, createdByUserObj=$createdByUserObj, description=$description, metadata=$metadata, name=$name, permissions=$permissions, predefinedRole=$predefinedRole, resourceType=$resourceType, updatedAt=$updatedAt, additionalProperties=$additionalProperties}" +} diff --git a/openai-java-core/src/main/kotlin/com/openai/models/admin/organization/roles/RoleRetrieveParams.kt b/openai-java-core/src/main/kotlin/com/openai/models/admin/organization/roles/RoleRetrieveParams.kt new file mode 100644 index 000000000..8c7baba07 --- /dev/null +++ b/openai-java-core/src/main/kotlin/com/openai/models/admin/organization/roles/RoleRetrieveParams.kt @@ -0,0 +1,189 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.models.admin.organization.roles + +import com.openai.core.Params +import com.openai.core.http.Headers +import com.openai.core.http.QueryParams +import java.util.Objects +import java.util.Optional +import kotlin.jvm.optionals.getOrNull + +/** Retrieves an organization role. */ +class RoleRetrieveParams +private constructor( + private val roleId: String?, + private val additionalHeaders: Headers, + private val additionalQueryParams: QueryParams, +) : Params { + + fun roleId(): Optional = Optional.ofNullable(roleId) + + /** Additional headers to send with the request. */ + fun _additionalHeaders(): Headers = additionalHeaders + + /** Additional query param to send with the request. */ + fun _additionalQueryParams(): QueryParams = additionalQueryParams + + fun toBuilder() = Builder().from(this) + + companion object { + + @JvmStatic fun none(): RoleRetrieveParams = builder().build() + + /** Returns a mutable builder for constructing an instance of [RoleRetrieveParams]. */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [RoleRetrieveParams]. */ + class Builder internal constructor() { + + private var roleId: String? = null + private var additionalHeaders: Headers.Builder = Headers.builder() + private var additionalQueryParams: QueryParams.Builder = QueryParams.builder() + + @JvmSynthetic + internal fun from(roleRetrieveParams: RoleRetrieveParams) = apply { + roleId = roleRetrieveParams.roleId + additionalHeaders = roleRetrieveParams.additionalHeaders.toBuilder() + additionalQueryParams = roleRetrieveParams.additionalQueryParams.toBuilder() + } + + fun roleId(roleId: String?) = apply { this.roleId = roleId } + + /** Alias for calling [Builder.roleId] with `roleId.orElse(null)`. */ + fun roleId(roleId: Optional) = roleId(roleId.getOrNull()) + + 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 [RoleRetrieveParams]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): RoleRetrieveParams = + RoleRetrieveParams(roleId, additionalHeaders.build(), additionalQueryParams.build()) + } + + 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 + } + + return other is RoleRetrieveParams && + roleId == other.roleId && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams + } + + override fun hashCode(): Int = Objects.hash(roleId, additionalHeaders, additionalQueryParams) + + override fun toString() = + "RoleRetrieveParams{roleId=$roleId, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" +} diff --git a/openai-java-core/src/main/kotlin/com/openai/models/admin/organization/spendalerts/OrganizationSpendAlert.kt b/openai-java-core/src/main/kotlin/com/openai/models/admin/organization/spendalerts/OrganizationSpendAlert.kt new file mode 100644 index 000000000..4c0d5cc3a --- /dev/null +++ b/openai-java-core/src/main/kotlin/com/openai/models/admin/organization/spendalerts/OrganizationSpendAlert.kt @@ -0,0 +1,936 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.models.admin.organization.spendalerts + +import com.fasterxml.jackson.annotation.JsonAnyGetter +import com.fasterxml.jackson.annotation.JsonAnySetter +import com.fasterxml.jackson.annotation.JsonCreator +import com.fasterxml.jackson.annotation.JsonProperty +import com.openai.core.Enum +import com.openai.core.ExcludeMissing +import com.openai.core.JsonField +import com.openai.core.JsonMissing +import com.openai.core.JsonValue +import com.openai.core.checkKnown +import com.openai.core.checkRequired +import com.openai.core.toImmutable +import com.openai.errors.OpenAIInvalidDataException +import java.util.Collections +import java.util.Objects +import java.util.Optional +import kotlin.jvm.optionals.getOrNull + +/** Represents a spend alert configured at the organization level. */ +class OrganizationSpendAlert +@JsonCreator(mode = JsonCreator.Mode.DISABLED) +private constructor( + private val id: JsonField, + private val currency: JsonField, + private val interval: JsonField, + private val notificationChannel: JsonField, + private val object_: JsonValue, + private val thresholdAmount: JsonField, + private val additionalProperties: MutableMap, +) { + + @JsonCreator + private constructor( + @JsonProperty("id") @ExcludeMissing id: JsonField = JsonMissing.of(), + @JsonProperty("currency") @ExcludeMissing currency: JsonField = JsonMissing.of(), + @JsonProperty("interval") @ExcludeMissing interval: JsonField = JsonMissing.of(), + @JsonProperty("notification_channel") + @ExcludeMissing + notificationChannel: JsonField = JsonMissing.of(), + @JsonProperty("object") @ExcludeMissing object_: JsonValue = JsonMissing.of(), + @JsonProperty("threshold_amount") + @ExcludeMissing + thresholdAmount: JsonField = JsonMissing.of(), + ) : this(id, currency, interval, notificationChannel, object_, thresholdAmount, mutableMapOf()) + + /** + * The identifier, which can be referenced in API endpoints. + * + * @throws OpenAIInvalidDataException 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 id(): String = id.getRequired("id") + + /** + * The currency for the threshold amount. + * + * @throws OpenAIInvalidDataException 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 currency(): Currency = currency.getRequired("currency") + + /** + * The time interval for evaluating spend against the threshold. + * + * @throws OpenAIInvalidDataException 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 interval(): Interval = interval.getRequired("interval") + + /** + * Email notification settings for a spend alert. + * + * @throws OpenAIInvalidDataException 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 notificationChannel(): NotificationChannel = + notificationChannel.getRequired("notification_channel") + + /** + * The object type, which is always `organization.spend_alert`. + * + * Expected to always return the following: + * ```java + * JsonValue.from("organization.spend_alert") + * ``` + * + * However, this method can be useful for debugging and logging (e.g. if the server responded + * with an unexpected value). + */ + @JsonProperty("object") @ExcludeMissing fun _object_(): JsonValue = object_ + + /** + * The alert threshold amount, in cents. + * + * @throws OpenAIInvalidDataException 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 thresholdAmount(): Long = thresholdAmount.getRequired("threshold_amount") + + /** + * Returns the raw JSON value of [id]. + * + * Unlike [id], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("id") @ExcludeMissing fun _id(): JsonField = id + + /** + * Returns the raw JSON value of [currency]. + * + * Unlike [currency], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("currency") @ExcludeMissing fun _currency(): JsonField = currency + + /** + * Returns the raw JSON value of [interval]. + * + * Unlike [interval], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("interval") @ExcludeMissing fun _interval(): JsonField = interval + + /** + * Returns the raw JSON value of [notificationChannel]. + * + * Unlike [notificationChannel], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("notification_channel") + @ExcludeMissing + fun _notificationChannel(): JsonField = notificationChannel + + /** + * Returns the raw JSON value of [thresholdAmount]. + * + * Unlike [thresholdAmount], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("threshold_amount") + @ExcludeMissing + fun _thresholdAmount(): JsonField = thresholdAmount + + @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 [OrganizationSpendAlert]. + * + * The following fields are required: + * ```java + * .id() + * .currency() + * .interval() + * .notificationChannel() + * .thresholdAmount() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [OrganizationSpendAlert]. */ + class Builder internal constructor() { + + private var id: JsonField? = null + private var currency: JsonField? = null + private var interval: JsonField? = null + private var notificationChannel: JsonField? = null + private var object_: JsonValue = JsonValue.from("organization.spend_alert") + private var thresholdAmount: JsonField? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(organizationSpendAlert: OrganizationSpendAlert) = apply { + id = organizationSpendAlert.id + currency = organizationSpendAlert.currency + interval = organizationSpendAlert.interval + notificationChannel = organizationSpendAlert.notificationChannel + object_ = organizationSpendAlert.object_ + thresholdAmount = organizationSpendAlert.thresholdAmount + additionalProperties = organizationSpendAlert.additionalProperties.toMutableMap() + } + + /** The identifier, which can be referenced in API endpoints. */ + fun id(id: String) = id(JsonField.of(id)) + + /** + * Sets [Builder.id] to an arbitrary JSON value. + * + * You should usually call [Builder.id] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun id(id: JsonField) = apply { this.id = id } + + /** The currency for the threshold amount. */ + fun currency(currency: Currency) = currency(JsonField.of(currency)) + + /** + * Sets [Builder.currency] to an arbitrary JSON value. + * + * You should usually call [Builder.currency] with a well-typed [Currency] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun currency(currency: JsonField) = apply { this.currency = currency } + + /** The time interval for evaluating spend against the threshold. */ + fun interval(interval: Interval) = interval(JsonField.of(interval)) + + /** + * Sets [Builder.interval] to an arbitrary JSON value. + * + * You should usually call [Builder.interval] with a well-typed [Interval] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun interval(interval: JsonField) = apply { this.interval = interval } + + /** Email notification settings for a spend alert. */ + fun notificationChannel(notificationChannel: NotificationChannel) = + notificationChannel(JsonField.of(notificationChannel)) + + /** + * Sets [Builder.notificationChannel] to an arbitrary JSON value. + * + * You should usually call [Builder.notificationChannel] with a well-typed + * [NotificationChannel] value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun notificationChannel(notificationChannel: JsonField) = apply { + this.notificationChannel = notificationChannel + } + + /** + * Sets the field to an arbitrary JSON value. + * + * It is usually unnecessary to call this method because the field defaults to the + * following: + * ```java + * JsonValue.from("organization.spend_alert") + * ``` + * + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun object_(object_: JsonValue) = apply { this.object_ = object_ } + + /** The alert threshold amount, in cents. */ + fun thresholdAmount(thresholdAmount: Long) = thresholdAmount(JsonField.of(thresholdAmount)) + + /** + * Sets [Builder.thresholdAmount] to an arbitrary JSON value. + * + * You should usually call [Builder.thresholdAmount] with a well-typed [Long] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun thresholdAmount(thresholdAmount: JsonField) = apply { + this.thresholdAmount = thresholdAmount + } + + 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 [OrganizationSpendAlert]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .id() + * .currency() + * .interval() + * .notificationChannel() + * .thresholdAmount() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): OrganizationSpendAlert = + OrganizationSpendAlert( + checkRequired("id", id), + checkRequired("currency", currency), + checkRequired("interval", interval), + checkRequired("notificationChannel", notificationChannel), + object_, + checkRequired("thresholdAmount", thresholdAmount), + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected types recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing fields. + * + * @throws OpenAIInvalidDataException if any value type in this object doesn't match its + * expected type. + */ + fun validate(): OrganizationSpendAlert = apply { + if (validated) { + return@apply + } + + id() + currency().validate() + interval().validate() + notificationChannel().validate() + _object_().let { + if (it != JsonValue.from("organization.spend_alert")) { + throw OpenAIInvalidDataException("'object_' is invalid, received $it") + } + } + thresholdAmount() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OpenAIInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (if (id.asKnown().isPresent) 1 else 0) + + (currency.asKnown().getOrNull()?.validity() ?: 0) + + (interval.asKnown().getOrNull()?.validity() ?: 0) + + (notificationChannel.asKnown().getOrNull()?.validity() ?: 0) + + object_.let { if (it == JsonValue.from("organization.spend_alert")) 1 else 0 } + + (if (thresholdAmount.asKnown().isPresent) 1 else 0) + + /** The currency for the threshold amount. */ + class Currency @JsonCreator private constructor(private val value: JsonField) : Enum { + + /** + * Returns this class instance's raw value. + * + * This is usually only useful if this instance was deserialized from data that doesn't + * match any known member, and you want to know that value. For example, if the SDK is on an + * older version than the API, then the API may respond with new members that the SDK is + * unaware of. + */ + @com.fasterxml.jackson.annotation.JsonValue fun _value(): JsonField = value + + companion object { + + @JvmField val USD = of("USD") + + @JvmStatic fun of(value: String) = Currency(JsonField.of(value)) + } + + /** An enum containing [Currency]'s known values. */ + enum class Known { + USD + } + + /** + * An enum containing [Currency]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [Currency] can contain an unknown value in a couple of cases: + * - It was deserialized from data that doesn't match any known member. For example, if the + * SDK is on an older version than the API, then the API may respond with new members that + * the SDK is unaware of. + * - It was constructed with an arbitrary value using the [of] method. + */ + enum class Value { + USD, + /** An enum member indicating that [Currency] was instantiated with an unknown value. */ + _UNKNOWN, + } + + /** + * Returns an enum member corresponding to this class instance's value, or [Value._UNKNOWN] + * if the class was instantiated with an unknown value. + * + * Use the [known] method instead if you're certain the value is always known or if you want + * to throw for the unknown case. + */ + fun value(): Value = + when (this) { + USD -> Value.USD + else -> Value._UNKNOWN + } + + /** + * Returns an enum member corresponding to this class instance's value. + * + * Use the [value] method instead if you're uncertain the value is always known and don't + * want to throw for the unknown case. + * + * @throws OpenAIInvalidDataException if this class instance's value is a not a known + * member. + */ + fun known(): Known = + when (this) { + USD -> Known.USD + else -> throw OpenAIInvalidDataException("Unknown Currency: $value") + } + + /** + * Returns this class instance's primitive wire representation. + * + * This differs from the [toString] method because that method is primarily for debugging + * and generally doesn't throw. + * + * @throws OpenAIInvalidDataException if this class instance's value does not have the + * expected primitive type. + */ + fun asString(): String = + _value().asString().orElseThrow { OpenAIInvalidDataException("Value is not a String") } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing fields. + * + * @throws OpenAIInvalidDataException if any value type in this object doesn't match its + * expected type. + */ + fun validate(): Currency = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OpenAIInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Currency && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + /** The time interval for evaluating spend against the threshold. */ + class Interval @JsonCreator private constructor(private val value: JsonField) : Enum { + + /** + * Returns this class instance's raw value. + * + * This is usually only useful if this instance was deserialized from data that doesn't + * match any known member, and you want to know that value. For example, if the SDK is on an + * older version than the API, then the API may respond with new members that the SDK is + * unaware of. + */ + @com.fasterxml.jackson.annotation.JsonValue fun _value(): JsonField = value + + companion object { + + @JvmField val MONTH = of("month") + + @JvmStatic fun of(value: String) = Interval(JsonField.of(value)) + } + + /** An enum containing [Interval]'s known values. */ + enum class Known { + MONTH + } + + /** + * An enum containing [Interval]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [Interval] can contain an unknown value in a couple of cases: + * - It was deserialized from data that doesn't match any known member. For example, if the + * SDK is on an older version than the API, then the API may respond with new members that + * the SDK is unaware of. + * - It was constructed with an arbitrary value using the [of] method. + */ + enum class Value { + MONTH, + /** An enum member indicating that [Interval] was instantiated with an unknown value. */ + _UNKNOWN, + } + + /** + * Returns an enum member corresponding to this class instance's value, or [Value._UNKNOWN] + * if the class was instantiated with an unknown value. + * + * Use the [known] method instead if you're certain the value is always known or if you want + * to throw for the unknown case. + */ + fun value(): Value = + when (this) { + MONTH -> Value.MONTH + else -> Value._UNKNOWN + } + + /** + * Returns an enum member corresponding to this class instance's value. + * + * Use the [value] method instead if you're uncertain the value is always known and don't + * want to throw for the unknown case. + * + * @throws OpenAIInvalidDataException if this class instance's value is a not a known + * member. + */ + fun known(): Known = + when (this) { + MONTH -> Known.MONTH + else -> throw OpenAIInvalidDataException("Unknown Interval: $value") + } + + /** + * Returns this class instance's primitive wire representation. + * + * This differs from the [toString] method because that method is primarily for debugging + * and generally doesn't throw. + * + * @throws OpenAIInvalidDataException if this class instance's value does not have the + * expected primitive type. + */ + fun asString(): String = + _value().asString().orElseThrow { OpenAIInvalidDataException("Value is not a String") } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing fields. + * + * @throws OpenAIInvalidDataException if any value type in this object doesn't match its + * expected type. + */ + fun validate(): Interval = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OpenAIInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Interval && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + /** Email notification settings for a spend alert. */ + class NotificationChannel + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val recipients: JsonField>, + private val type: JsonValue, + private val subjectPrefix: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("recipients") + @ExcludeMissing + recipients: JsonField> = JsonMissing.of(), + @JsonProperty("type") @ExcludeMissing type: JsonValue = JsonMissing.of(), + @JsonProperty("subject_prefix") + @ExcludeMissing + subjectPrefix: JsonField = JsonMissing.of(), + ) : this(recipients, type, subjectPrefix, mutableMapOf()) + + /** + * Email addresses that receive the spend alert notification. + * + * @throws OpenAIInvalidDataException 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 recipients(): List = recipients.getRequired("recipients") + + /** + * The notification channel type. Currently only `email` is supported. + * + * Expected to always return the following: + * ```java + * JsonValue.from("email") + * ``` + * + * However, this method can be useful for debugging and logging (e.g. if the server + * responded with an unexpected value). + */ + @JsonProperty("type") @ExcludeMissing fun _type(): JsonValue = type + + /** + * Optional subject prefix for alert emails. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun subjectPrefix(): Optional = subjectPrefix.getOptional("subject_prefix") + + /** + * Returns the raw JSON value of [recipients]. + * + * Unlike [recipients], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("recipients") + @ExcludeMissing + fun _recipients(): JsonField> = recipients + + /** + * Returns the raw JSON value of [subjectPrefix]. + * + * Unlike [subjectPrefix], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("subject_prefix") + @ExcludeMissing + fun _subjectPrefix(): JsonField = subjectPrefix + + @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 [NotificationChannel]. + * + * The following fields are required: + * ```java + * .recipients() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [NotificationChannel]. */ + class Builder internal constructor() { + + private var recipients: JsonField>? = null + private var type: JsonValue = JsonValue.from("email") + private var subjectPrefix: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(notificationChannel: NotificationChannel) = apply { + recipients = notificationChannel.recipients.map { it.toMutableList() } + type = notificationChannel.type + subjectPrefix = notificationChannel.subjectPrefix + additionalProperties = notificationChannel.additionalProperties.toMutableMap() + } + + /** Email addresses that receive the spend alert notification. */ + fun recipients(recipients: List) = recipients(JsonField.of(recipients)) + + /** + * Sets [Builder.recipients] to an arbitrary JSON value. + * + * You should usually call [Builder.recipients] with a well-typed `List` value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun recipients(recipients: JsonField>) = apply { + this.recipients = recipients.map { it.toMutableList() } + } + + /** + * Adds a single [String] to [recipients]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addRecipient(recipient: String) = apply { + recipients = + (recipients ?: JsonField.of(mutableListOf())).also { + checkKnown("recipients", it).add(recipient) + } + } + + /** + * Sets the field to an arbitrary JSON value. + * + * It is usually unnecessary to call this method because the field defaults to the + * following: + * ```java + * JsonValue.from("email") + * ``` + * + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun type(type: JsonValue) = apply { this.type = type } + + /** Optional subject prefix for alert emails. */ + fun subjectPrefix(subjectPrefix: String?) = + subjectPrefix(JsonField.ofNullable(subjectPrefix)) + + /** Alias for calling [Builder.subjectPrefix] with `subjectPrefix.orElse(null)`. */ + fun subjectPrefix(subjectPrefix: Optional) = + subjectPrefix(subjectPrefix.getOrNull()) + + /** + * Sets [Builder.subjectPrefix] to an arbitrary JSON value. + * + * You should usually call [Builder.subjectPrefix] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun subjectPrefix(subjectPrefix: JsonField) = apply { + this.subjectPrefix = subjectPrefix + } + + 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 [NotificationChannel]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .recipients() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): NotificationChannel = + NotificationChannel( + checkRequired("recipients", recipients).map { it.toImmutable() }, + type, + subjectPrefix, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing fields. + * + * @throws OpenAIInvalidDataException if any value type in this object doesn't match its + * expected type. + */ + fun validate(): NotificationChannel = apply { + if (validated) { + return@apply + } + + recipients() + _type().let { + if (it != JsonValue.from("email")) { + throw OpenAIInvalidDataException("'type' is invalid, received $it") + } + } + subjectPrefix() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OpenAIInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (recipients.asKnown().getOrNull()?.size ?: 0) + + type.let { if (it == JsonValue.from("email")) 1 else 0 } + + (if (subjectPrefix.asKnown().isPresent) 1 else 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is NotificationChannel && + recipients == other.recipients && + type == other.type && + subjectPrefix == other.subjectPrefix && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(recipients, type, subjectPrefix, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "NotificationChannel{recipients=$recipients, type=$type, subjectPrefix=$subjectPrefix, additionalProperties=$additionalProperties}" + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is OrganizationSpendAlert && + id == other.id && + currency == other.currency && + interval == other.interval && + notificationChannel == other.notificationChannel && + object_ == other.object_ && + thresholdAmount == other.thresholdAmount && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + id, + currency, + interval, + notificationChannel, + object_, + thresholdAmount, + additionalProperties, + ) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "OrganizationSpendAlert{id=$id, currency=$currency, interval=$interval, notificationChannel=$notificationChannel, object_=$object_, thresholdAmount=$thresholdAmount, additionalProperties=$additionalProperties}" +} diff --git a/openai-java-core/src/main/kotlin/com/openai/models/admin/organization/spendalerts/OrganizationSpendAlertDeleted.kt b/openai-java-core/src/main/kotlin/com/openai/models/admin/organization/spendalerts/OrganizationSpendAlertDeleted.kt new file mode 100644 index 000000000..d8ec0995b --- /dev/null +++ b/openai-java-core/src/main/kotlin/com/openai/models/admin/organization/spendalerts/OrganizationSpendAlertDeleted.kt @@ -0,0 +1,260 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.models.admin.organization.spendalerts + +import com.fasterxml.jackson.annotation.JsonAnyGetter +import com.fasterxml.jackson.annotation.JsonAnySetter +import com.fasterxml.jackson.annotation.JsonCreator +import com.fasterxml.jackson.annotation.JsonProperty +import com.openai.core.ExcludeMissing +import com.openai.core.JsonField +import com.openai.core.JsonMissing +import com.openai.core.JsonValue +import com.openai.core.checkRequired +import com.openai.errors.OpenAIInvalidDataException +import java.util.Collections +import java.util.Objects + +/** Confirmation payload returned after deleting an organization spend alert. */ +class OrganizationSpendAlertDeleted +@JsonCreator(mode = JsonCreator.Mode.DISABLED) +private constructor( + private val id: JsonField, + private val deleted: JsonField, + private val object_: JsonValue, + private val additionalProperties: MutableMap, +) { + + @JsonCreator + private constructor( + @JsonProperty("id") @ExcludeMissing id: JsonField = JsonMissing.of(), + @JsonProperty("deleted") @ExcludeMissing deleted: JsonField = JsonMissing.of(), + @JsonProperty("object") @ExcludeMissing object_: JsonValue = JsonMissing.of(), + ) : this(id, deleted, object_, mutableMapOf()) + + /** + * The deleted spend alert ID. + * + * @throws OpenAIInvalidDataException 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 id(): String = id.getRequired("id") + + /** + * Whether the spend alert was deleted. + * + * @throws OpenAIInvalidDataException 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 deleted(): Boolean = deleted.getRequired("deleted") + + /** + * Always `organization.spend_alert.deleted`. + * + * Expected to always return the following: + * ```java + * JsonValue.from("organization.spend_alert.deleted") + * ``` + * + * However, this method can be useful for debugging and logging (e.g. if the server responded + * with an unexpected value). + */ + @JsonProperty("object") @ExcludeMissing fun _object_(): JsonValue = object_ + + /** + * Returns the raw JSON value of [id]. + * + * Unlike [id], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("id") @ExcludeMissing fun _id(): JsonField = id + + /** + * Returns the raw JSON value of [deleted]. + * + * Unlike [deleted], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("deleted") @ExcludeMissing fun _deleted(): JsonField = deleted + + @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 + * [OrganizationSpendAlertDeleted]. + * + * The following fields are required: + * ```java + * .id() + * .deleted() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [OrganizationSpendAlertDeleted]. */ + class Builder internal constructor() { + + private var id: JsonField? = null + private var deleted: JsonField? = null + private var object_: JsonValue = JsonValue.from("organization.spend_alert.deleted") + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(organizationSpendAlertDeleted: OrganizationSpendAlertDeleted) = apply { + id = organizationSpendAlertDeleted.id + deleted = organizationSpendAlertDeleted.deleted + object_ = organizationSpendAlertDeleted.object_ + additionalProperties = organizationSpendAlertDeleted.additionalProperties.toMutableMap() + } + + /** The deleted spend alert ID. */ + fun id(id: String) = id(JsonField.of(id)) + + /** + * Sets [Builder.id] to an arbitrary JSON value. + * + * You should usually call [Builder.id] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun id(id: JsonField) = apply { this.id = id } + + /** Whether the spend alert was deleted. */ + fun deleted(deleted: Boolean) = deleted(JsonField.of(deleted)) + + /** + * Sets [Builder.deleted] to an arbitrary JSON value. + * + * You should usually call [Builder.deleted] with a well-typed [Boolean] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun deleted(deleted: JsonField) = apply { this.deleted = deleted } + + /** + * Sets the field to an arbitrary JSON value. + * + * It is usually unnecessary to call this method because the field defaults to the + * following: + * ```java + * JsonValue.from("organization.spend_alert.deleted") + * ``` + * + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun object_(object_: JsonValue) = apply { this.object_ = object_ } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [OrganizationSpendAlertDeleted]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .id() + * .deleted() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): OrganizationSpendAlertDeleted = + OrganizationSpendAlertDeleted( + checkRequired("id", id), + checkRequired("deleted", deleted), + object_, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected types recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing fields. + * + * @throws OpenAIInvalidDataException if any value type in this object doesn't match its + * expected type. + */ + fun validate(): OrganizationSpendAlertDeleted = apply { + if (validated) { + return@apply + } + + id() + deleted() + _object_().let { + if (it != JsonValue.from("organization.spend_alert.deleted")) { + throw OpenAIInvalidDataException("'object_' is invalid, received $it") + } + } + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OpenAIInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (if (id.asKnown().isPresent) 1 else 0) + + (if (deleted.asKnown().isPresent) 1 else 0) + + object_.let { if (it == JsonValue.from("organization.spend_alert.deleted")) 1 else 0 } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is OrganizationSpendAlertDeleted && + id == other.id && + deleted == other.deleted && + object_ == other.object_ && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(id, deleted, object_, additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "OrganizationSpendAlertDeleted{id=$id, deleted=$deleted, object_=$object_, additionalProperties=$additionalProperties}" +} diff --git a/openai-java-core/src/main/kotlin/com/openai/models/admin/organization/spendalerts/SpendAlertCreateParams.kt b/openai-java-core/src/main/kotlin/com/openai/models/admin/organization/spendalerts/SpendAlertCreateParams.kt new file mode 100644 index 000000000..42eae9230 --- /dev/null +++ b/openai-java-core/src/main/kotlin/com/openai/models/admin/organization/spendalerts/SpendAlertCreateParams.kt @@ -0,0 +1,1208 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.models.admin.organization.spendalerts + +import com.fasterxml.jackson.annotation.JsonAnyGetter +import com.fasterxml.jackson.annotation.JsonAnySetter +import com.fasterxml.jackson.annotation.JsonCreator +import com.fasterxml.jackson.annotation.JsonProperty +import com.openai.core.Enum +import com.openai.core.ExcludeMissing +import com.openai.core.JsonField +import com.openai.core.JsonMissing +import com.openai.core.JsonValue +import com.openai.core.Params +import com.openai.core.checkKnown +import com.openai.core.checkRequired +import com.openai.core.http.Headers +import com.openai.core.http.QueryParams +import com.openai.core.toImmutable +import com.openai.errors.OpenAIInvalidDataException +import java.util.Collections +import java.util.Objects +import java.util.Optional +import kotlin.jvm.optionals.getOrNull + +/** Creates an organization spend alert. */ +class SpendAlertCreateParams +private constructor( + private val body: Body, + private val additionalHeaders: Headers, + private val additionalQueryParams: QueryParams, +) : Params { + + /** + * The currency for the threshold amount. + * + * @throws OpenAIInvalidDataException 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 currency(): Currency = body.currency() + + /** + * The time interval for evaluating spend against the threshold. + * + * @throws OpenAIInvalidDataException 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 interval(): Interval = body.interval() + + /** + * Email notification settings for a spend alert. + * + * @throws OpenAIInvalidDataException 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 notificationChannel(): NotificationChannel = body.notificationChannel() + + /** + * The alert threshold amount, in cents. + * + * @throws OpenAIInvalidDataException 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 thresholdAmount(): Long = body.thresholdAmount() + + /** + * Returns the raw JSON value of [currency]. + * + * Unlike [currency], this method doesn't throw if the JSON field has an unexpected type. + */ + fun _currency(): JsonField = body._currency() + + /** + * Returns the raw JSON value of [interval]. + * + * Unlike [interval], this method doesn't throw if the JSON field has an unexpected type. + */ + fun _interval(): JsonField = body._interval() + + /** + * Returns the raw JSON value of [notificationChannel]. + * + * Unlike [notificationChannel], this method doesn't throw if the JSON field has an unexpected + * type. + */ + fun _notificationChannel(): JsonField = body._notificationChannel() + + /** + * Returns the raw JSON value of [thresholdAmount]. + * + * Unlike [thresholdAmount], this method doesn't throw if the JSON field has an unexpected type. + */ + fun _thresholdAmount(): JsonField = body._thresholdAmount() + + fun _additionalBodyProperties(): Map = body._additionalProperties() + + /** Additional headers to send with the request. */ + fun _additionalHeaders(): Headers = additionalHeaders + + /** Additional query param to send with the request. */ + fun _additionalQueryParams(): QueryParams = additionalQueryParams + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of [SpendAlertCreateParams]. + * + * The following fields are required: + * ```java + * .currency() + * .interval() + * .notificationChannel() + * .thresholdAmount() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [SpendAlertCreateParams]. */ + 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(spendAlertCreateParams: SpendAlertCreateParams) = apply { + body = spendAlertCreateParams.body.toBuilder() + additionalHeaders = spendAlertCreateParams.additionalHeaders.toBuilder() + additionalQueryParams = spendAlertCreateParams.additionalQueryParams.toBuilder() + } + + /** + * Sets the entire request body. + * + * This is generally only useful if you are already constructing the body separately. + * Otherwise, it's more convenient to use the top-level setters instead: + * - [currency] + * - [interval] + * - [notificationChannel] + * - [thresholdAmount] + */ + fun body(body: Body) = apply { this.body = body.toBuilder() } + + /** The currency for the threshold amount. */ + fun currency(currency: Currency) = apply { body.currency(currency) } + + /** + * Sets [Builder.currency] to an arbitrary JSON value. + * + * You should usually call [Builder.currency] with a well-typed [Currency] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun currency(currency: JsonField) = apply { body.currency(currency) } + + /** The time interval for evaluating spend against the threshold. */ + fun interval(interval: Interval) = apply { body.interval(interval) } + + /** + * Sets [Builder.interval] to an arbitrary JSON value. + * + * You should usually call [Builder.interval] with a well-typed [Interval] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun interval(interval: JsonField) = apply { body.interval(interval) } + + /** Email notification settings for a spend alert. */ + fun notificationChannel(notificationChannel: NotificationChannel) = apply { + body.notificationChannel(notificationChannel) + } + + /** + * Sets [Builder.notificationChannel] to an arbitrary JSON value. + * + * You should usually call [Builder.notificationChannel] with a well-typed + * [NotificationChannel] value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun notificationChannel(notificationChannel: JsonField) = apply { + body.notificationChannel(notificationChannel) + } + + /** The alert threshold amount, in cents. */ + fun thresholdAmount(thresholdAmount: Long) = apply { body.thresholdAmount(thresholdAmount) } + + /** + * Sets [Builder.thresholdAmount] to an arbitrary JSON value. + * + * You should usually call [Builder.thresholdAmount] with a well-typed [Long] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun thresholdAmount(thresholdAmount: JsonField) = apply { + body.thresholdAmount(thresholdAmount) + } + + 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 [SpendAlertCreateParams]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .currency() + * .interval() + * .notificationChannel() + * .thresholdAmount() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): SpendAlertCreateParams = + SpendAlertCreateParams( + body.build(), + additionalHeaders.build(), + additionalQueryParams.build(), + ) + } + + fun _body(): Body = body + + override fun _headers(): Headers = additionalHeaders + + override fun _queryParams(): QueryParams = additionalQueryParams + + /** Parameters for creating or updating a spend alert. */ + class Body + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val currency: JsonField, + private val interval: JsonField, + private val notificationChannel: JsonField, + private val thresholdAmount: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("currency") + @ExcludeMissing + currency: JsonField = JsonMissing.of(), + @JsonProperty("interval") + @ExcludeMissing + interval: JsonField = JsonMissing.of(), + @JsonProperty("notification_channel") + @ExcludeMissing + notificationChannel: JsonField = JsonMissing.of(), + @JsonProperty("threshold_amount") + @ExcludeMissing + thresholdAmount: JsonField = JsonMissing.of(), + ) : this(currency, interval, notificationChannel, thresholdAmount, mutableMapOf()) + + /** + * The currency for the threshold amount. + * + * @throws OpenAIInvalidDataException 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 currency(): Currency = currency.getRequired("currency") + + /** + * The time interval for evaluating spend against the threshold. + * + * @throws OpenAIInvalidDataException 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 interval(): Interval = interval.getRequired("interval") + + /** + * Email notification settings for a spend alert. + * + * @throws OpenAIInvalidDataException 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 notificationChannel(): NotificationChannel = + notificationChannel.getRequired("notification_channel") + + /** + * The alert threshold amount, in cents. + * + * @throws OpenAIInvalidDataException 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 thresholdAmount(): Long = thresholdAmount.getRequired("threshold_amount") + + /** + * Returns the raw JSON value of [currency]. + * + * Unlike [currency], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("currency") @ExcludeMissing fun _currency(): JsonField = currency + + /** + * Returns the raw JSON value of [interval]. + * + * Unlike [interval], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("interval") @ExcludeMissing fun _interval(): JsonField = interval + + /** + * Returns the raw JSON value of [notificationChannel]. + * + * Unlike [notificationChannel], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("notification_channel") + @ExcludeMissing + fun _notificationChannel(): JsonField = notificationChannel + + /** + * Returns the raw JSON value of [thresholdAmount]. + * + * Unlike [thresholdAmount], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("threshold_amount") + @ExcludeMissing + fun _thresholdAmount(): JsonField = thresholdAmount + + @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 + * .currency() + * .interval() + * .notificationChannel() + * .thresholdAmount() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [Body]. */ + class Builder internal constructor() { + + private var currency: JsonField? = null + private var interval: JsonField? = null + private var notificationChannel: JsonField? = null + private var thresholdAmount: JsonField? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(body: Body) = apply { + currency = body.currency + interval = body.interval + notificationChannel = body.notificationChannel + thresholdAmount = body.thresholdAmount + additionalProperties = body.additionalProperties.toMutableMap() + } + + /** The currency for the threshold amount. */ + fun currency(currency: Currency) = currency(JsonField.of(currency)) + + /** + * Sets [Builder.currency] to an arbitrary JSON value. + * + * You should usually call [Builder.currency] with a well-typed [Currency] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun currency(currency: JsonField) = apply { this.currency = currency } + + /** The time interval for evaluating spend against the threshold. */ + fun interval(interval: Interval) = interval(JsonField.of(interval)) + + /** + * Sets [Builder.interval] to an arbitrary JSON value. + * + * You should usually call [Builder.interval] with a well-typed [Interval] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun interval(interval: JsonField) = apply { this.interval = interval } + + /** Email notification settings for a spend alert. */ + fun notificationChannel(notificationChannel: NotificationChannel) = + notificationChannel(JsonField.of(notificationChannel)) + + /** + * Sets [Builder.notificationChannel] to an arbitrary JSON value. + * + * You should usually call [Builder.notificationChannel] with a well-typed + * [NotificationChannel] value instead. This method is primarily for setting the field + * to an undocumented or not yet supported value. + */ + fun notificationChannel(notificationChannel: JsonField) = apply { + this.notificationChannel = notificationChannel + } + + /** The alert threshold amount, in cents. */ + fun thresholdAmount(thresholdAmount: Long) = + thresholdAmount(JsonField.of(thresholdAmount)) + + /** + * Sets [Builder.thresholdAmount] to an arbitrary JSON value. + * + * You should usually call [Builder.thresholdAmount] with a well-typed [Long] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun thresholdAmount(thresholdAmount: JsonField) = apply { + this.thresholdAmount = thresholdAmount + } + + 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 + * .currency() + * .interval() + * .notificationChannel() + * .thresholdAmount() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): Body = + Body( + checkRequired("currency", currency), + checkRequired("interval", interval), + checkRequired("notificationChannel", notificationChannel), + checkRequired("thresholdAmount", thresholdAmount), + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing fields. + * + * @throws OpenAIInvalidDataException if any value type in this object doesn't match its + * expected type. + */ + fun validate(): Body = apply { + if (validated) { + return@apply + } + + currency().validate() + interval().validate() + notificationChannel().validate() + thresholdAmount() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OpenAIInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (currency.asKnown().getOrNull()?.validity() ?: 0) + + (interval.asKnown().getOrNull()?.validity() ?: 0) + + (notificationChannel.asKnown().getOrNull()?.validity() ?: 0) + + (if (thresholdAmount.asKnown().isPresent) 1 else 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Body && + currency == other.currency && + interval == other.interval && + notificationChannel == other.notificationChannel && + thresholdAmount == other.thresholdAmount && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + currency, + interval, + notificationChannel, + thresholdAmount, + additionalProperties, + ) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Body{currency=$currency, interval=$interval, notificationChannel=$notificationChannel, thresholdAmount=$thresholdAmount, additionalProperties=$additionalProperties}" + } + + /** The currency for the threshold amount. */ + class Currency @JsonCreator private constructor(private val value: JsonField) : Enum { + + /** + * Returns this class instance's raw value. + * + * This is usually only useful if this instance was deserialized from data that doesn't + * match any known member, and you want to know that value. For example, if the SDK is on an + * older version than the API, then the API may respond with new members that the SDK is + * unaware of. + */ + @com.fasterxml.jackson.annotation.JsonValue fun _value(): JsonField = value + + companion object { + + @JvmField val USD = of("USD") + + @JvmStatic fun of(value: String) = Currency(JsonField.of(value)) + } + + /** An enum containing [Currency]'s known values. */ + enum class Known { + USD + } + + /** + * An enum containing [Currency]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [Currency] can contain an unknown value in a couple of cases: + * - It was deserialized from data that doesn't match any known member. For example, if the + * SDK is on an older version than the API, then the API may respond with new members that + * the SDK is unaware of. + * - It was constructed with an arbitrary value using the [of] method. + */ + enum class Value { + USD, + /** An enum member indicating that [Currency] was instantiated with an unknown value. */ + _UNKNOWN, + } + + /** + * Returns an enum member corresponding to this class instance's value, or [Value._UNKNOWN] + * if the class was instantiated with an unknown value. + * + * Use the [known] method instead if you're certain the value is always known or if you want + * to throw for the unknown case. + */ + fun value(): Value = + when (this) { + USD -> Value.USD + else -> Value._UNKNOWN + } + + /** + * Returns an enum member corresponding to this class instance's value. + * + * Use the [value] method instead if you're uncertain the value is always known and don't + * want to throw for the unknown case. + * + * @throws OpenAIInvalidDataException if this class instance's value is a not a known + * member. + */ + fun known(): Known = + when (this) { + USD -> Known.USD + else -> throw OpenAIInvalidDataException("Unknown Currency: $value") + } + + /** + * Returns this class instance's primitive wire representation. + * + * This differs from the [toString] method because that method is primarily for debugging + * and generally doesn't throw. + * + * @throws OpenAIInvalidDataException if this class instance's value does not have the + * expected primitive type. + */ + fun asString(): String = + _value().asString().orElseThrow { OpenAIInvalidDataException("Value is not a String") } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing fields. + * + * @throws OpenAIInvalidDataException if any value type in this object doesn't match its + * expected type. + */ + fun validate(): Currency = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OpenAIInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Currency && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + /** The time interval for evaluating spend against the threshold. */ + class Interval @JsonCreator private constructor(private val value: JsonField) : Enum { + + /** + * Returns this class instance's raw value. + * + * This is usually only useful if this instance was deserialized from data that doesn't + * match any known member, and you want to know that value. For example, if the SDK is on an + * older version than the API, then the API may respond with new members that the SDK is + * unaware of. + */ + @com.fasterxml.jackson.annotation.JsonValue fun _value(): JsonField = value + + companion object { + + @JvmField val MONTH = of("month") + + @JvmStatic fun of(value: String) = Interval(JsonField.of(value)) + } + + /** An enum containing [Interval]'s known values. */ + enum class Known { + MONTH + } + + /** + * An enum containing [Interval]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [Interval] can contain an unknown value in a couple of cases: + * - It was deserialized from data that doesn't match any known member. For example, if the + * SDK is on an older version than the API, then the API may respond with new members that + * the SDK is unaware of. + * - It was constructed with an arbitrary value using the [of] method. + */ + enum class Value { + MONTH, + /** An enum member indicating that [Interval] was instantiated with an unknown value. */ + _UNKNOWN, + } + + /** + * Returns an enum member corresponding to this class instance's value, or [Value._UNKNOWN] + * if the class was instantiated with an unknown value. + * + * Use the [known] method instead if you're certain the value is always known or if you want + * to throw for the unknown case. + */ + fun value(): Value = + when (this) { + MONTH -> Value.MONTH + else -> Value._UNKNOWN + } + + /** + * Returns an enum member corresponding to this class instance's value. + * + * Use the [value] method instead if you're uncertain the value is always known and don't + * want to throw for the unknown case. + * + * @throws OpenAIInvalidDataException if this class instance's value is a not a known + * member. + */ + fun known(): Known = + when (this) { + MONTH -> Known.MONTH + else -> throw OpenAIInvalidDataException("Unknown Interval: $value") + } + + /** + * Returns this class instance's primitive wire representation. + * + * This differs from the [toString] method because that method is primarily for debugging + * and generally doesn't throw. + * + * @throws OpenAIInvalidDataException if this class instance's value does not have the + * expected primitive type. + */ + fun asString(): String = + _value().asString().orElseThrow { OpenAIInvalidDataException("Value is not a String") } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing fields. + * + * @throws OpenAIInvalidDataException if any value type in this object doesn't match its + * expected type. + */ + fun validate(): Interval = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OpenAIInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Interval && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + /** Email notification settings for a spend alert. */ + class NotificationChannel + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val recipients: JsonField>, + private val type: JsonValue, + private val subjectPrefix: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("recipients") + @ExcludeMissing + recipients: JsonField> = JsonMissing.of(), + @JsonProperty("type") @ExcludeMissing type: JsonValue = JsonMissing.of(), + @JsonProperty("subject_prefix") + @ExcludeMissing + subjectPrefix: JsonField = JsonMissing.of(), + ) : this(recipients, type, subjectPrefix, mutableMapOf()) + + /** + * Email addresses that receive the spend alert notification. + * + * @throws OpenAIInvalidDataException 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 recipients(): List = recipients.getRequired("recipients") + + /** + * The notification channel type. Currently only `email` is supported. + * + * Expected to always return the following: + * ```java + * JsonValue.from("email") + * ``` + * + * However, this method can be useful for debugging and logging (e.g. if the server + * responded with an unexpected value). + */ + @JsonProperty("type") @ExcludeMissing fun _type(): JsonValue = type + + /** + * Optional subject prefix for alert emails. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun subjectPrefix(): Optional = subjectPrefix.getOptional("subject_prefix") + + /** + * Returns the raw JSON value of [recipients]. + * + * Unlike [recipients], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("recipients") + @ExcludeMissing + fun _recipients(): JsonField> = recipients + + /** + * Returns the raw JSON value of [subjectPrefix]. + * + * Unlike [subjectPrefix], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("subject_prefix") + @ExcludeMissing + fun _subjectPrefix(): JsonField = subjectPrefix + + @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 [NotificationChannel]. + * + * The following fields are required: + * ```java + * .recipients() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [NotificationChannel]. */ + class Builder internal constructor() { + + private var recipients: JsonField>? = null + private var type: JsonValue = JsonValue.from("email") + private var subjectPrefix: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(notificationChannel: NotificationChannel) = apply { + recipients = notificationChannel.recipients.map { it.toMutableList() } + type = notificationChannel.type + subjectPrefix = notificationChannel.subjectPrefix + additionalProperties = notificationChannel.additionalProperties.toMutableMap() + } + + /** Email addresses that receive the spend alert notification. */ + fun recipients(recipients: List) = recipients(JsonField.of(recipients)) + + /** + * Sets [Builder.recipients] to an arbitrary JSON value. + * + * You should usually call [Builder.recipients] with a well-typed `List` value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun recipients(recipients: JsonField>) = apply { + this.recipients = recipients.map { it.toMutableList() } + } + + /** + * Adds a single [String] to [recipients]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addRecipient(recipient: String) = apply { + recipients = + (recipients ?: JsonField.of(mutableListOf())).also { + checkKnown("recipients", it).add(recipient) + } + } + + /** + * Sets the field to an arbitrary JSON value. + * + * It is usually unnecessary to call this method because the field defaults to the + * following: + * ```java + * JsonValue.from("email") + * ``` + * + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun type(type: JsonValue) = apply { this.type = type } + + /** Optional subject prefix for alert emails. */ + fun subjectPrefix(subjectPrefix: String?) = + subjectPrefix(JsonField.ofNullable(subjectPrefix)) + + /** Alias for calling [Builder.subjectPrefix] with `subjectPrefix.orElse(null)`. */ + fun subjectPrefix(subjectPrefix: Optional) = + subjectPrefix(subjectPrefix.getOrNull()) + + /** + * Sets [Builder.subjectPrefix] to an arbitrary JSON value. + * + * You should usually call [Builder.subjectPrefix] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun subjectPrefix(subjectPrefix: JsonField) = apply { + this.subjectPrefix = subjectPrefix + } + + 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 [NotificationChannel]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .recipients() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): NotificationChannel = + NotificationChannel( + checkRequired("recipients", recipients).map { it.toImmutable() }, + type, + subjectPrefix, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing fields. + * + * @throws OpenAIInvalidDataException if any value type in this object doesn't match its + * expected type. + */ + fun validate(): NotificationChannel = apply { + if (validated) { + return@apply + } + + recipients() + _type().let { + if (it != JsonValue.from("email")) { + throw OpenAIInvalidDataException("'type' is invalid, received $it") + } + } + subjectPrefix() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OpenAIInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (recipients.asKnown().getOrNull()?.size ?: 0) + + type.let { if (it == JsonValue.from("email")) 1 else 0 } + + (if (subjectPrefix.asKnown().isPresent) 1 else 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is NotificationChannel && + recipients == other.recipients && + type == other.type && + subjectPrefix == other.subjectPrefix && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(recipients, type, subjectPrefix, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "NotificationChannel{recipients=$recipients, type=$type, subjectPrefix=$subjectPrefix, additionalProperties=$additionalProperties}" + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is SpendAlertCreateParams && + body == other.body && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams + } + + override fun hashCode(): Int = Objects.hash(body, additionalHeaders, additionalQueryParams) + + override fun toString() = + "SpendAlertCreateParams{body=$body, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" +} diff --git a/openai-java-core/src/main/kotlin/com/openai/models/admin/organization/spendalerts/SpendAlertDeleteParams.kt b/openai-java-core/src/main/kotlin/com/openai/models/admin/organization/spendalerts/SpendAlertDeleteParams.kt new file mode 100644 index 000000000..b36280f57 --- /dev/null +++ b/openai-java-core/src/main/kotlin/com/openai/models/admin/organization/spendalerts/SpendAlertDeleteParams.kt @@ -0,0 +1,230 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.models.admin.organization.spendalerts + +import com.openai.core.JsonValue +import com.openai.core.Params +import com.openai.core.http.Headers +import com.openai.core.http.QueryParams +import com.openai.core.toImmutable +import java.util.Objects +import java.util.Optional +import kotlin.jvm.optionals.getOrNull + +/** Deletes an organization spend alert. */ +class SpendAlertDeleteParams +private constructor( + private val alertId: String?, + private val additionalHeaders: Headers, + private val additionalQueryParams: QueryParams, + private val additionalBodyProperties: Map, +) : Params { + + fun alertId(): Optional = Optional.ofNullable(alertId) + + /** Additional body properties to send with the request. */ + fun _additionalBodyProperties(): Map = additionalBodyProperties + + /** Additional headers to send with the request. */ + fun _additionalHeaders(): Headers = additionalHeaders + + /** Additional query param to send with the request. */ + fun _additionalQueryParams(): QueryParams = additionalQueryParams + + fun toBuilder() = Builder().from(this) + + companion object { + + @JvmStatic fun none(): SpendAlertDeleteParams = builder().build() + + /** Returns a mutable builder for constructing an instance of [SpendAlertDeleteParams]. */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [SpendAlertDeleteParams]. */ + class Builder internal constructor() { + + private var alertId: String? = null + private var additionalHeaders: Headers.Builder = Headers.builder() + private var additionalQueryParams: QueryParams.Builder = QueryParams.builder() + private var additionalBodyProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(spendAlertDeleteParams: SpendAlertDeleteParams) = apply { + alertId = spendAlertDeleteParams.alertId + additionalHeaders = spendAlertDeleteParams.additionalHeaders.toBuilder() + additionalQueryParams = spendAlertDeleteParams.additionalQueryParams.toBuilder() + additionalBodyProperties = + spendAlertDeleteParams.additionalBodyProperties.toMutableMap() + } + + fun alertId(alertId: String?) = apply { this.alertId = alertId } + + /** Alias for calling [Builder.alertId] with `alertId.orElse(null)`. */ + fun alertId(alertId: Optional) = alertId(alertId.getOrNull()) + + 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) + } + + fun additionalBodyProperties(additionalBodyProperties: Map) = apply { + this.additionalBodyProperties.clear() + putAllAdditionalBodyProperties(additionalBodyProperties) + } + + fun putAdditionalBodyProperty(key: String, value: JsonValue) = apply { + additionalBodyProperties.put(key, value) + } + + fun putAllAdditionalBodyProperties(additionalBodyProperties: Map) = + apply { + this.additionalBodyProperties.putAll(additionalBodyProperties) + } + + fun removeAdditionalBodyProperty(key: String) = apply { + additionalBodyProperties.remove(key) + } + + fun removeAllAdditionalBodyProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalBodyProperty) + } + + /** + * Returns an immutable instance of [SpendAlertDeleteParams]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): SpendAlertDeleteParams = + SpendAlertDeleteParams( + alertId, + additionalHeaders.build(), + additionalQueryParams.build(), + additionalBodyProperties.toImmutable(), + ) + } + + fun _body(): Optional> = + Optional.ofNullable(additionalBodyProperties.ifEmpty { null }) + + fun _pathParam(index: Int): String = + when (index) { + 0 -> alertId ?: "" + else -> "" + } + + override fun _headers(): Headers = additionalHeaders + + override fun _queryParams(): QueryParams = additionalQueryParams + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is SpendAlertDeleteParams && + alertId == other.alertId && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams && + additionalBodyProperties == other.additionalBodyProperties + } + + override fun hashCode(): Int = + Objects.hash(alertId, additionalHeaders, additionalQueryParams, additionalBodyProperties) + + override fun toString() = + "SpendAlertDeleteParams{alertId=$alertId, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams, additionalBodyProperties=$additionalBodyProperties}" +} diff --git a/openai-java-core/src/main/kotlin/com/openai/models/admin/organization/spendalerts/SpendAlertListPage.kt b/openai-java-core/src/main/kotlin/com/openai/models/admin/organization/spendalerts/SpendAlertListPage.kt new file mode 100644 index 000000000..534f41fcb --- /dev/null +++ b/openai-java-core/src/main/kotlin/com/openai/models/admin/organization/spendalerts/SpendAlertListPage.kt @@ -0,0 +1,139 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.models.admin.organization.spendalerts + +import com.openai.core.AutoPager +import com.openai.core.Page +import com.openai.core.checkRequired +import com.openai.services.blocking.admin.organization.SpendAlertService +import java.util.Objects +import java.util.Optional +import kotlin.jvm.optionals.getOrNull + +/** @see SpendAlertService.list */ +class SpendAlertListPage +private constructor( + private val service: SpendAlertService, + private val params: SpendAlertListParams, + private val response: SpendAlertListPageResponse, +) : Page { + + /** + * Delegates to [SpendAlertListPageResponse], but gracefully handles missing data. + * + * @see SpendAlertListPageResponse.data + */ + fun data(): List = + response._data().getOptional("data").getOrNull() ?: emptyList() + + /** + * Delegates to [SpendAlertListPageResponse], but gracefully handles missing data. + * + * @see SpendAlertListPageResponse.hasMore + */ + fun hasMore(): Optional = response._hasMore().getOptional("has_more") + + /** + * Delegates to [SpendAlertListPageResponse], but gracefully handles missing data. + * + * @see SpendAlertListPageResponse.lastId + */ + fun lastId(): Optional = response._lastId().getOptional("last_id") + + override fun items(): List = data() + + override fun hasNextPage(): Boolean = items().isNotEmpty() && lastId().isPresent + + fun nextPageParams(): SpendAlertListParams { + val nextCursor = + lastId().getOrNull() ?: throw IllegalStateException("Cannot construct next page params") + return params.toBuilder().after(nextCursor).build() + } + + override fun nextPage(): SpendAlertListPage = service.list(nextPageParams()) + + fun autoPager(): AutoPager = AutoPager.from(this) + + /** The parameters that were used to request this page. */ + fun params(): SpendAlertListParams = params + + /** The response that this page was parsed from. */ + fun response(): SpendAlertListPageResponse = response + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of [SpendAlertListPage]. + * + * The following fields are required: + * ```java + * .service() + * .params() + * .response() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [SpendAlertListPage]. */ + class Builder internal constructor() { + + private var service: SpendAlertService? = null + private var params: SpendAlertListParams? = null + private var response: SpendAlertListPageResponse? = null + + @JvmSynthetic + internal fun from(spendAlertListPage: SpendAlertListPage) = apply { + service = spendAlertListPage.service + params = spendAlertListPage.params + response = spendAlertListPage.response + } + + fun service(service: SpendAlertService) = apply { this.service = service } + + /** The parameters that were used to request this page. */ + fun params(params: SpendAlertListParams) = apply { this.params = params } + + /** The response that this page was parsed from. */ + fun response(response: SpendAlertListPageResponse) = apply { this.response = response } + + /** + * Returns an immutable instance of [SpendAlertListPage]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .service() + * .params() + * .response() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): SpendAlertListPage = + SpendAlertListPage( + checkRequired("service", service), + checkRequired("params", params), + checkRequired("response", response), + ) + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is SpendAlertListPage && + service == other.service && + params == other.params && + response == other.response + } + + override fun hashCode(): Int = Objects.hash(service, params, response) + + override fun toString() = + "SpendAlertListPage{service=$service, params=$params, response=$response}" +} diff --git a/openai-java-core/src/main/kotlin/com/openai/models/admin/organization/spendalerts/SpendAlertListPageAsync.kt b/openai-java-core/src/main/kotlin/com/openai/models/admin/organization/spendalerts/SpendAlertListPageAsync.kt new file mode 100644 index 000000000..2cf860763 --- /dev/null +++ b/openai-java-core/src/main/kotlin/com/openai/models/admin/organization/spendalerts/SpendAlertListPageAsync.kt @@ -0,0 +1,154 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.models.admin.organization.spendalerts + +import com.openai.core.AutoPagerAsync +import com.openai.core.PageAsync +import com.openai.core.checkRequired +import com.openai.services.async.admin.organization.SpendAlertServiceAsync +import java.util.Objects +import java.util.Optional +import java.util.concurrent.CompletableFuture +import java.util.concurrent.Executor +import kotlin.jvm.optionals.getOrNull + +/** @see SpendAlertServiceAsync.list */ +class SpendAlertListPageAsync +private constructor( + private val service: SpendAlertServiceAsync, + private val streamHandlerExecutor: Executor, + private val params: SpendAlertListParams, + private val response: SpendAlertListPageResponse, +) : PageAsync { + + /** + * Delegates to [SpendAlertListPageResponse], but gracefully handles missing data. + * + * @see SpendAlertListPageResponse.data + */ + fun data(): List = + response._data().getOptional("data").getOrNull() ?: emptyList() + + /** + * Delegates to [SpendAlertListPageResponse], but gracefully handles missing data. + * + * @see SpendAlertListPageResponse.hasMore + */ + fun hasMore(): Optional = response._hasMore().getOptional("has_more") + + /** + * Delegates to [SpendAlertListPageResponse], but gracefully handles missing data. + * + * @see SpendAlertListPageResponse.lastId + */ + fun lastId(): Optional = response._lastId().getOptional("last_id") + + override fun items(): List = data() + + override fun hasNextPage(): Boolean = items().isNotEmpty() && lastId().isPresent + + fun nextPageParams(): SpendAlertListParams { + val nextCursor = + lastId().getOrNull() ?: throw IllegalStateException("Cannot construct next page params") + return params.toBuilder().after(nextCursor).build() + } + + override fun nextPage(): CompletableFuture = + service.list(nextPageParams()) + + fun autoPager(): AutoPagerAsync = + AutoPagerAsync.from(this, streamHandlerExecutor) + + /** The parameters that were used to request this page. */ + fun params(): SpendAlertListParams = params + + /** The response that this page was parsed from. */ + fun response(): SpendAlertListPageResponse = response + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of [SpendAlertListPageAsync]. + * + * The following fields are required: + * ```java + * .service() + * .streamHandlerExecutor() + * .params() + * .response() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [SpendAlertListPageAsync]. */ + class Builder internal constructor() { + + private var service: SpendAlertServiceAsync? = null + private var streamHandlerExecutor: Executor? = null + private var params: SpendAlertListParams? = null + private var response: SpendAlertListPageResponse? = null + + @JvmSynthetic + internal fun from(spendAlertListPageAsync: SpendAlertListPageAsync) = apply { + service = spendAlertListPageAsync.service + streamHandlerExecutor = spendAlertListPageAsync.streamHandlerExecutor + params = spendAlertListPageAsync.params + response = spendAlertListPageAsync.response + } + + fun service(service: SpendAlertServiceAsync) = apply { this.service = service } + + fun streamHandlerExecutor(streamHandlerExecutor: Executor) = apply { + this.streamHandlerExecutor = streamHandlerExecutor + } + + /** The parameters that were used to request this page. */ + fun params(params: SpendAlertListParams) = apply { this.params = params } + + /** The response that this page was parsed from. */ + fun response(response: SpendAlertListPageResponse) = apply { this.response = response } + + /** + * Returns an immutable instance of [SpendAlertListPageAsync]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .service() + * .streamHandlerExecutor() + * .params() + * .response() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): SpendAlertListPageAsync = + SpendAlertListPageAsync( + checkRequired("service", service), + checkRequired("streamHandlerExecutor", streamHandlerExecutor), + checkRequired("params", params), + checkRequired("response", response), + ) + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is SpendAlertListPageAsync && + service == other.service && + streamHandlerExecutor == other.streamHandlerExecutor && + params == other.params && + response == other.response + } + + override fun hashCode(): Int = Objects.hash(service, streamHandlerExecutor, params, response) + + override fun toString() = + "SpendAlertListPageAsync{service=$service, streamHandlerExecutor=$streamHandlerExecutor, params=$params, response=$response}" +} diff --git a/openai-java-core/src/main/kotlin/com/openai/models/admin/organization/spendalerts/SpendAlertListPageResponse.kt b/openai-java-core/src/main/kotlin/com/openai/models/admin/organization/spendalerts/SpendAlertListPageResponse.kt new file mode 100644 index 000000000..475eb2412 --- /dev/null +++ b/openai-java-core/src/main/kotlin/com/openai/models/admin/organization/spendalerts/SpendAlertListPageResponse.kt @@ -0,0 +1,362 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.models.admin.organization.spendalerts + +import com.fasterxml.jackson.annotation.JsonAnyGetter +import com.fasterxml.jackson.annotation.JsonAnySetter +import com.fasterxml.jackson.annotation.JsonCreator +import com.fasterxml.jackson.annotation.JsonProperty +import com.openai.core.ExcludeMissing +import com.openai.core.JsonField +import com.openai.core.JsonMissing +import com.openai.core.JsonValue +import com.openai.core.checkKnown +import com.openai.core.checkRequired +import com.openai.core.toImmutable +import com.openai.errors.OpenAIInvalidDataException +import java.util.Collections +import java.util.Objects +import java.util.Optional +import kotlin.jvm.optionals.getOrNull + +/** Paginated list of organization spend alerts. */ +class SpendAlertListPageResponse +@JsonCreator(mode = JsonCreator.Mode.DISABLED) +private constructor( + private val data: JsonField>, + private val firstId: JsonField, + private val hasMore: JsonField, + private val lastId: JsonField, + private val object_: JsonValue, + private val additionalProperties: MutableMap, +) { + + @JsonCreator + private constructor( + @JsonProperty("data") + @ExcludeMissing + data: JsonField> = JsonMissing.of(), + @JsonProperty("first_id") @ExcludeMissing firstId: JsonField = JsonMissing.of(), + @JsonProperty("has_more") @ExcludeMissing hasMore: JsonField = JsonMissing.of(), + @JsonProperty("last_id") @ExcludeMissing lastId: JsonField = JsonMissing.of(), + @JsonProperty("object") @ExcludeMissing object_: JsonValue = JsonMissing.of(), + ) : this(data, firstId, hasMore, lastId, object_, mutableMapOf()) + + /** + * Spend alerts returned in the current page. + * + * @throws OpenAIInvalidDataException 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(): List = data.getRequired("data") + + /** + * The ID of the first spend alert in this page. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun firstId(): Optional = firstId.getOptional("first_id") + + /** + * Whether more spend alerts are available when paginating. + * + * @throws OpenAIInvalidDataException 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 hasMore(): Boolean = hasMore.getRequired("has_more") + + /** + * The ID of the last spend alert in this page. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun lastId(): Optional = lastId.getOptional("last_id") + + /** + * Always `list`. + * + * Expected to always return the following: + * ```java + * JsonValue.from("list") + * ``` + * + * However, this method can be useful for debugging and logging (e.g. if the server responded + * with an unexpected value). + */ + @JsonProperty("object") @ExcludeMissing fun _object_(): JsonValue = object_ + + /** + * 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 + + /** + * Returns the raw JSON value of [firstId]. + * + * Unlike [firstId], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("first_id") @ExcludeMissing fun _firstId(): JsonField = firstId + + /** + * Returns the raw JSON value of [hasMore]. + * + * Unlike [hasMore], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("has_more") @ExcludeMissing fun _hasMore(): JsonField = hasMore + + /** + * Returns the raw JSON value of [lastId]. + * + * Unlike [lastId], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("last_id") @ExcludeMissing fun _lastId(): JsonField = lastId + + @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 [SpendAlertListPageResponse]. + * + * The following fields are required: + * ```java + * .data() + * .firstId() + * .hasMore() + * .lastId() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [SpendAlertListPageResponse]. */ + class Builder internal constructor() { + + private var data: JsonField>? = null + private var firstId: JsonField? = null + private var hasMore: JsonField? = null + private var lastId: JsonField? = null + private var object_: JsonValue = JsonValue.from("list") + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(spendAlertListPageResponse: SpendAlertListPageResponse) = apply { + data = spendAlertListPageResponse.data.map { it.toMutableList() } + firstId = spendAlertListPageResponse.firstId + hasMore = spendAlertListPageResponse.hasMore + lastId = spendAlertListPageResponse.lastId + object_ = spendAlertListPageResponse.object_ + additionalProperties = spendAlertListPageResponse.additionalProperties.toMutableMap() + } + + /** Spend alerts returned in the current page. */ + fun data(data: List) = data(JsonField.of(data)) + + /** + * Sets [Builder.data] to an arbitrary JSON value. + * + * You should usually call [Builder.data] with a well-typed `List` + * 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.map { it.toMutableList() } + } + + /** + * Adds a single [OrganizationSpendAlert] to [Builder.data]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addData(data: OrganizationSpendAlert) = apply { + this.data = + (this.data ?: JsonField.of(mutableListOf())).also { + checkKnown("data", it).add(data) + } + } + + /** The ID of the first spend alert in this page. */ + fun firstId(firstId: String?) = firstId(JsonField.ofNullable(firstId)) + + /** Alias for calling [Builder.firstId] with `firstId.orElse(null)`. */ + fun firstId(firstId: Optional) = firstId(firstId.getOrNull()) + + /** + * Sets [Builder.firstId] to an arbitrary JSON value. + * + * You should usually call [Builder.firstId] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun firstId(firstId: JsonField) = apply { this.firstId = firstId } + + /** Whether more spend alerts are available when paginating. */ + fun hasMore(hasMore: Boolean) = hasMore(JsonField.of(hasMore)) + + /** + * Sets [Builder.hasMore] to an arbitrary JSON value. + * + * You should usually call [Builder.hasMore] with a well-typed [Boolean] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun hasMore(hasMore: JsonField) = apply { this.hasMore = hasMore } + + /** The ID of the last spend alert in this page. */ + fun lastId(lastId: String?) = lastId(JsonField.ofNullable(lastId)) + + /** Alias for calling [Builder.lastId] with `lastId.orElse(null)`. */ + fun lastId(lastId: Optional) = lastId(lastId.getOrNull()) + + /** + * Sets [Builder.lastId] to an arbitrary JSON value. + * + * You should usually call [Builder.lastId] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun lastId(lastId: JsonField) = apply { this.lastId = lastId } + + /** + * Sets the field to an arbitrary JSON value. + * + * It is usually unnecessary to call this method because the field defaults to the + * following: + * ```java + * JsonValue.from("list") + * ``` + * + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun object_(object_: JsonValue) = apply { this.object_ = object_ } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [SpendAlertListPageResponse]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .data() + * .firstId() + * .hasMore() + * .lastId() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): SpendAlertListPageResponse = + SpendAlertListPageResponse( + checkRequired("data", data).map { it.toImmutable() }, + checkRequired("firstId", firstId), + checkRequired("hasMore", hasMore), + checkRequired("lastId", lastId), + object_, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected types recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing fields. + * + * @throws OpenAIInvalidDataException if any value type in this object doesn't match its + * expected type. + */ + fun validate(): SpendAlertListPageResponse = apply { + if (validated) { + return@apply + } + + data().forEach { it.validate() } + firstId() + hasMore() + lastId() + _object_().let { + if (it != JsonValue.from("list")) { + throw OpenAIInvalidDataException("'object_' is invalid, received $it") + } + } + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OpenAIInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (data.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + + (if (firstId.asKnown().isPresent) 1 else 0) + + (if (hasMore.asKnown().isPresent) 1 else 0) + + (if (lastId.asKnown().isPresent) 1 else 0) + + object_.let { if (it == JsonValue.from("list")) 1 else 0 } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is SpendAlertListPageResponse && + data == other.data && + firstId == other.firstId && + hasMore == other.hasMore && + lastId == other.lastId && + object_ == other.object_ && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(data, firstId, hasMore, lastId, object_, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "SpendAlertListPageResponse{data=$data, firstId=$firstId, hasMore=$hasMore, lastId=$lastId, object_=$object_, additionalProperties=$additionalProperties}" +} diff --git a/openai-java-core/src/main/kotlin/com/openai/models/admin/organization/spendalerts/SpendAlertListParams.kt b/openai-java-core/src/main/kotlin/com/openai/models/admin/organization/spendalerts/SpendAlertListParams.kt new file mode 100644 index 000000000..3b331634c --- /dev/null +++ b/openai-java-core/src/main/kotlin/com/openai/models/admin/organization/spendalerts/SpendAlertListParams.kt @@ -0,0 +1,399 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.models.admin.organization.spendalerts + +import com.fasterxml.jackson.annotation.JsonCreator +import com.openai.core.Enum +import com.openai.core.JsonField +import com.openai.core.Params +import com.openai.core.http.Headers +import com.openai.core.http.QueryParams +import com.openai.errors.OpenAIInvalidDataException +import java.util.Objects +import java.util.Optional +import kotlin.jvm.optionals.getOrNull + +/** Lists organization spend alerts. */ +class SpendAlertListParams +private constructor( + private val after: String?, + private val before: String?, + private val limit: Long?, + private val order: Order?, + private val additionalHeaders: Headers, + private val additionalQueryParams: QueryParams, +) : Params { + + /** + * Cursor for pagination. Provide the ID of the last spend alert from the previous response to + * fetch the next page. + */ + fun after(): Optional = Optional.ofNullable(after) + + /** + * Cursor for pagination. Provide the ID of the first spend alert from the previous response to + * fetch the previous page. + */ + fun before(): Optional = Optional.ofNullable(before) + + /** A limit on the number of spend alerts to return. Defaults to 20. */ + fun limit(): Optional = Optional.ofNullable(limit) + + /** Sort order for the returned spend alerts. */ + fun order(): Optional = Optional.ofNullable(order) + + /** Additional headers to send with the request. */ + fun _additionalHeaders(): Headers = additionalHeaders + + /** Additional query param to send with the request. */ + fun _additionalQueryParams(): QueryParams = additionalQueryParams + + fun toBuilder() = Builder().from(this) + + companion object { + + @JvmStatic fun none(): SpendAlertListParams = builder().build() + + /** Returns a mutable builder for constructing an instance of [SpendAlertListParams]. */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [SpendAlertListParams]. */ + class Builder internal constructor() { + + private var after: String? = null + private var before: String? = null + private var limit: Long? = null + private var order: Order? = null + private var additionalHeaders: Headers.Builder = Headers.builder() + private var additionalQueryParams: QueryParams.Builder = QueryParams.builder() + + @JvmSynthetic + internal fun from(spendAlertListParams: SpendAlertListParams) = apply { + after = spendAlertListParams.after + before = spendAlertListParams.before + limit = spendAlertListParams.limit + order = spendAlertListParams.order + additionalHeaders = spendAlertListParams.additionalHeaders.toBuilder() + additionalQueryParams = spendAlertListParams.additionalQueryParams.toBuilder() + } + + /** + * Cursor for pagination. Provide the ID of the last spend alert from the previous response + * to fetch the next page. + */ + fun after(after: String?) = apply { this.after = after } + + /** Alias for calling [Builder.after] with `after.orElse(null)`. */ + fun after(after: Optional) = after(after.getOrNull()) + + /** + * Cursor for pagination. Provide the ID of the first spend alert from the previous response + * to fetch the previous page. + */ + fun before(before: String?) = apply { this.before = before } + + /** Alias for calling [Builder.before] with `before.orElse(null)`. */ + fun before(before: Optional) = before(before.getOrNull()) + + /** A limit on the number of spend alerts to return. Defaults to 20. */ + fun limit(limit: Long?) = apply { this.limit = 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()) + + /** Sort order for the returned spend alerts. */ + fun order(order: Order?) = apply { this.order = order } + + /** Alias for calling [Builder.order] with `order.orElse(null)`. */ + fun order(order: Optional) = order(order.getOrNull()) + + 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 [SpendAlertListParams]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): SpendAlertListParams = + SpendAlertListParams( + after, + before, + limit, + order, + additionalHeaders.build(), + additionalQueryParams.build(), + ) + } + + override fun _headers(): Headers = additionalHeaders + + override fun _queryParams(): QueryParams = + QueryParams.builder() + .apply { + after?.let { put("after", it) } + before?.let { put("before", it) } + limit?.let { put("limit", it.toString()) } + order?.let { put("order", it.toString()) } + putAll(additionalQueryParams) + } + .build() + + /** Sort order for the returned spend alerts. */ + class Order @JsonCreator private constructor(private val value: JsonField) : Enum { + + /** + * Returns this class instance's raw value. + * + * This is usually only useful if this instance was deserialized from data that doesn't + * match any known member, and you want to know that value. For example, if the SDK is on an + * older version than the API, then the API may respond with new members that the SDK is + * unaware of. + */ + @com.fasterxml.jackson.annotation.JsonValue fun _value(): JsonField = value + + companion object { + + @JvmField val ASC = of("asc") + + @JvmField val DESC = of("desc") + + @JvmStatic fun of(value: String) = Order(JsonField.of(value)) + } + + /** An enum containing [Order]'s known values. */ + enum class Known { + ASC, + DESC, + } + + /** + * An enum containing [Order]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [Order] can contain an unknown value in a couple of cases: + * - It was deserialized from data that doesn't match any known member. For example, if the + * SDK is on an older version than the API, then the API may respond with new members that + * the SDK is unaware of. + * - It was constructed with an arbitrary value using the [of] method. + */ + enum class Value { + ASC, + DESC, + /** An enum member indicating that [Order] was instantiated with an unknown value. */ + _UNKNOWN, + } + + /** + * Returns an enum member corresponding to this class instance's value, or [Value._UNKNOWN] + * if the class was instantiated with an unknown value. + * + * Use the [known] method instead if you're certain the value is always known or if you want + * to throw for the unknown case. + */ + fun value(): Value = + when (this) { + ASC -> Value.ASC + DESC -> Value.DESC + else -> Value._UNKNOWN + } + + /** + * Returns an enum member corresponding to this class instance's value. + * + * Use the [value] method instead if you're uncertain the value is always known and don't + * want to throw for the unknown case. + * + * @throws OpenAIInvalidDataException if this class instance's value is a not a known + * member. + */ + fun known(): Known = + when (this) { + ASC -> Known.ASC + DESC -> Known.DESC + else -> throw OpenAIInvalidDataException("Unknown Order: $value") + } + + /** + * Returns this class instance's primitive wire representation. + * + * This differs from the [toString] method because that method is primarily for debugging + * and generally doesn't throw. + * + * @throws OpenAIInvalidDataException if this class instance's value does not have the + * expected primitive type. + */ + fun asString(): String = + _value().asString().orElseThrow { OpenAIInvalidDataException("Value is not a String") } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing fields. + * + * @throws OpenAIInvalidDataException if any value type in this object doesn't match its + * expected type. + */ + fun validate(): Order = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OpenAIInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Order && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is SpendAlertListParams && + after == other.after && + before == other.before && + limit == other.limit && + order == other.order && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams + } + + override fun hashCode(): Int = + Objects.hash(after, before, limit, order, additionalHeaders, additionalQueryParams) + + override fun toString() = + "SpendAlertListParams{after=$after, before=$before, limit=$limit, order=$order, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" +} diff --git a/openai-java-core/src/main/kotlin/com/openai/models/admin/organization/spendalerts/SpendAlertUpdateParams.kt b/openai-java-core/src/main/kotlin/com/openai/models/admin/organization/spendalerts/SpendAlertUpdateParams.kt new file mode 100644 index 000000000..c4b11a800 --- /dev/null +++ b/openai-java-core/src/main/kotlin/com/openai/models/admin/organization/spendalerts/SpendAlertUpdateParams.kt @@ -0,0 +1,1227 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.models.admin.organization.spendalerts + +import com.fasterxml.jackson.annotation.JsonAnyGetter +import com.fasterxml.jackson.annotation.JsonAnySetter +import com.fasterxml.jackson.annotation.JsonCreator +import com.fasterxml.jackson.annotation.JsonProperty +import com.openai.core.Enum +import com.openai.core.ExcludeMissing +import com.openai.core.JsonField +import com.openai.core.JsonMissing +import com.openai.core.JsonValue +import com.openai.core.Params +import com.openai.core.checkKnown +import com.openai.core.checkRequired +import com.openai.core.http.Headers +import com.openai.core.http.QueryParams +import com.openai.core.toImmutable +import com.openai.errors.OpenAIInvalidDataException +import java.util.Collections +import java.util.Objects +import java.util.Optional +import kotlin.jvm.optionals.getOrNull + +/** Updates an organization spend alert. */ +class SpendAlertUpdateParams +private constructor( + private val alertId: String?, + private val body: Body, + private val additionalHeaders: Headers, + private val additionalQueryParams: QueryParams, +) : Params { + + fun alertId(): Optional = Optional.ofNullable(alertId) + + /** + * The currency for the threshold amount. + * + * @throws OpenAIInvalidDataException 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 currency(): Currency = body.currency() + + /** + * The time interval for evaluating spend against the threshold. + * + * @throws OpenAIInvalidDataException 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 interval(): Interval = body.interval() + + /** + * Email notification settings for a spend alert. + * + * @throws OpenAIInvalidDataException 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 notificationChannel(): NotificationChannel = body.notificationChannel() + + /** + * The alert threshold amount, in cents. + * + * @throws OpenAIInvalidDataException 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 thresholdAmount(): Long = body.thresholdAmount() + + /** + * Returns the raw JSON value of [currency]. + * + * Unlike [currency], this method doesn't throw if the JSON field has an unexpected type. + */ + fun _currency(): JsonField = body._currency() + + /** + * Returns the raw JSON value of [interval]. + * + * Unlike [interval], this method doesn't throw if the JSON field has an unexpected type. + */ + fun _interval(): JsonField = body._interval() + + /** + * Returns the raw JSON value of [notificationChannel]. + * + * Unlike [notificationChannel], this method doesn't throw if the JSON field has an unexpected + * type. + */ + fun _notificationChannel(): JsonField = body._notificationChannel() + + /** + * Returns the raw JSON value of [thresholdAmount]. + * + * Unlike [thresholdAmount], this method doesn't throw if the JSON field has an unexpected type. + */ + fun _thresholdAmount(): JsonField = body._thresholdAmount() + + fun _additionalBodyProperties(): Map = body._additionalProperties() + + /** Additional headers to send with the request. */ + fun _additionalHeaders(): Headers = additionalHeaders + + /** Additional query param to send with the request. */ + fun _additionalQueryParams(): QueryParams = additionalQueryParams + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of [SpendAlertUpdateParams]. + * + * The following fields are required: + * ```java + * .currency() + * .interval() + * .notificationChannel() + * .thresholdAmount() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [SpendAlertUpdateParams]. */ + class Builder internal constructor() { + + private var alertId: 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(spendAlertUpdateParams: SpendAlertUpdateParams) = apply { + alertId = spendAlertUpdateParams.alertId + body = spendAlertUpdateParams.body.toBuilder() + additionalHeaders = spendAlertUpdateParams.additionalHeaders.toBuilder() + additionalQueryParams = spendAlertUpdateParams.additionalQueryParams.toBuilder() + } + + fun alertId(alertId: String?) = apply { this.alertId = alertId } + + /** Alias for calling [Builder.alertId] with `alertId.orElse(null)`. */ + fun alertId(alertId: Optional) = alertId(alertId.getOrNull()) + + /** + * Sets the entire request body. + * + * This is generally only useful if you are already constructing the body separately. + * Otherwise, it's more convenient to use the top-level setters instead: + * - [currency] + * - [interval] + * - [notificationChannel] + * - [thresholdAmount] + */ + fun body(body: Body) = apply { this.body = body.toBuilder() } + + /** The currency for the threshold amount. */ + fun currency(currency: Currency) = apply { body.currency(currency) } + + /** + * Sets [Builder.currency] to an arbitrary JSON value. + * + * You should usually call [Builder.currency] with a well-typed [Currency] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun currency(currency: JsonField) = apply { body.currency(currency) } + + /** The time interval for evaluating spend against the threshold. */ + fun interval(interval: Interval) = apply { body.interval(interval) } + + /** + * Sets [Builder.interval] to an arbitrary JSON value. + * + * You should usually call [Builder.interval] with a well-typed [Interval] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun interval(interval: JsonField) = apply { body.interval(interval) } + + /** Email notification settings for a spend alert. */ + fun notificationChannel(notificationChannel: NotificationChannel) = apply { + body.notificationChannel(notificationChannel) + } + + /** + * Sets [Builder.notificationChannel] to an arbitrary JSON value. + * + * You should usually call [Builder.notificationChannel] with a well-typed + * [NotificationChannel] value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun notificationChannel(notificationChannel: JsonField) = apply { + body.notificationChannel(notificationChannel) + } + + /** The alert threshold amount, in cents. */ + fun thresholdAmount(thresholdAmount: Long) = apply { body.thresholdAmount(thresholdAmount) } + + /** + * Sets [Builder.thresholdAmount] to an arbitrary JSON value. + * + * You should usually call [Builder.thresholdAmount] with a well-typed [Long] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun thresholdAmount(thresholdAmount: JsonField) = apply { + body.thresholdAmount(thresholdAmount) + } + + 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 [SpendAlertUpdateParams]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .currency() + * .interval() + * .notificationChannel() + * .thresholdAmount() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): SpendAlertUpdateParams = + SpendAlertUpdateParams( + alertId, + body.build(), + additionalHeaders.build(), + additionalQueryParams.build(), + ) + } + + fun _body(): Body = body + + fun _pathParam(index: Int): String = + when (index) { + 0 -> alertId ?: "" + else -> "" + } + + override fun _headers(): Headers = additionalHeaders + + override fun _queryParams(): QueryParams = additionalQueryParams + + /** Parameters for creating or updating a spend alert. */ + class Body + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val currency: JsonField, + private val interval: JsonField, + private val notificationChannel: JsonField, + private val thresholdAmount: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("currency") + @ExcludeMissing + currency: JsonField = JsonMissing.of(), + @JsonProperty("interval") + @ExcludeMissing + interval: JsonField = JsonMissing.of(), + @JsonProperty("notification_channel") + @ExcludeMissing + notificationChannel: JsonField = JsonMissing.of(), + @JsonProperty("threshold_amount") + @ExcludeMissing + thresholdAmount: JsonField = JsonMissing.of(), + ) : this(currency, interval, notificationChannel, thresholdAmount, mutableMapOf()) + + /** + * The currency for the threshold amount. + * + * @throws OpenAIInvalidDataException 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 currency(): Currency = currency.getRequired("currency") + + /** + * The time interval for evaluating spend against the threshold. + * + * @throws OpenAIInvalidDataException 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 interval(): Interval = interval.getRequired("interval") + + /** + * Email notification settings for a spend alert. + * + * @throws OpenAIInvalidDataException 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 notificationChannel(): NotificationChannel = + notificationChannel.getRequired("notification_channel") + + /** + * The alert threshold amount, in cents. + * + * @throws OpenAIInvalidDataException 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 thresholdAmount(): Long = thresholdAmount.getRequired("threshold_amount") + + /** + * Returns the raw JSON value of [currency]. + * + * Unlike [currency], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("currency") @ExcludeMissing fun _currency(): JsonField = currency + + /** + * Returns the raw JSON value of [interval]. + * + * Unlike [interval], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("interval") @ExcludeMissing fun _interval(): JsonField = interval + + /** + * Returns the raw JSON value of [notificationChannel]. + * + * Unlike [notificationChannel], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("notification_channel") + @ExcludeMissing + fun _notificationChannel(): JsonField = notificationChannel + + /** + * Returns the raw JSON value of [thresholdAmount]. + * + * Unlike [thresholdAmount], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("threshold_amount") + @ExcludeMissing + fun _thresholdAmount(): JsonField = thresholdAmount + + @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 + * .currency() + * .interval() + * .notificationChannel() + * .thresholdAmount() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [Body]. */ + class Builder internal constructor() { + + private var currency: JsonField? = null + private var interval: JsonField? = null + private var notificationChannel: JsonField? = null + private var thresholdAmount: JsonField? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(body: Body) = apply { + currency = body.currency + interval = body.interval + notificationChannel = body.notificationChannel + thresholdAmount = body.thresholdAmount + additionalProperties = body.additionalProperties.toMutableMap() + } + + /** The currency for the threshold amount. */ + fun currency(currency: Currency) = currency(JsonField.of(currency)) + + /** + * Sets [Builder.currency] to an arbitrary JSON value. + * + * You should usually call [Builder.currency] with a well-typed [Currency] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun currency(currency: JsonField) = apply { this.currency = currency } + + /** The time interval for evaluating spend against the threshold. */ + fun interval(interval: Interval) = interval(JsonField.of(interval)) + + /** + * Sets [Builder.interval] to an arbitrary JSON value. + * + * You should usually call [Builder.interval] with a well-typed [Interval] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun interval(interval: JsonField) = apply { this.interval = interval } + + /** Email notification settings for a spend alert. */ + fun notificationChannel(notificationChannel: NotificationChannel) = + notificationChannel(JsonField.of(notificationChannel)) + + /** + * Sets [Builder.notificationChannel] to an arbitrary JSON value. + * + * You should usually call [Builder.notificationChannel] with a well-typed + * [NotificationChannel] value instead. This method is primarily for setting the field + * to an undocumented or not yet supported value. + */ + fun notificationChannel(notificationChannel: JsonField) = apply { + this.notificationChannel = notificationChannel + } + + /** The alert threshold amount, in cents. */ + fun thresholdAmount(thresholdAmount: Long) = + thresholdAmount(JsonField.of(thresholdAmount)) + + /** + * Sets [Builder.thresholdAmount] to an arbitrary JSON value. + * + * You should usually call [Builder.thresholdAmount] with a well-typed [Long] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun thresholdAmount(thresholdAmount: JsonField) = apply { + this.thresholdAmount = thresholdAmount + } + + 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 + * .currency() + * .interval() + * .notificationChannel() + * .thresholdAmount() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): Body = + Body( + checkRequired("currency", currency), + checkRequired("interval", interval), + checkRequired("notificationChannel", notificationChannel), + checkRequired("thresholdAmount", thresholdAmount), + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing fields. + * + * @throws OpenAIInvalidDataException if any value type in this object doesn't match its + * expected type. + */ + fun validate(): Body = apply { + if (validated) { + return@apply + } + + currency().validate() + interval().validate() + notificationChannel().validate() + thresholdAmount() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OpenAIInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (currency.asKnown().getOrNull()?.validity() ?: 0) + + (interval.asKnown().getOrNull()?.validity() ?: 0) + + (notificationChannel.asKnown().getOrNull()?.validity() ?: 0) + + (if (thresholdAmount.asKnown().isPresent) 1 else 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Body && + currency == other.currency && + interval == other.interval && + notificationChannel == other.notificationChannel && + thresholdAmount == other.thresholdAmount && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + currency, + interval, + notificationChannel, + thresholdAmount, + additionalProperties, + ) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Body{currency=$currency, interval=$interval, notificationChannel=$notificationChannel, thresholdAmount=$thresholdAmount, additionalProperties=$additionalProperties}" + } + + /** The currency for the threshold amount. */ + class Currency @JsonCreator private constructor(private val value: JsonField) : Enum { + + /** + * Returns this class instance's raw value. + * + * This is usually only useful if this instance was deserialized from data that doesn't + * match any known member, and you want to know that value. For example, if the SDK is on an + * older version than the API, then the API may respond with new members that the SDK is + * unaware of. + */ + @com.fasterxml.jackson.annotation.JsonValue fun _value(): JsonField = value + + companion object { + + @JvmField val USD = of("USD") + + @JvmStatic fun of(value: String) = Currency(JsonField.of(value)) + } + + /** An enum containing [Currency]'s known values. */ + enum class Known { + USD + } + + /** + * An enum containing [Currency]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [Currency] can contain an unknown value in a couple of cases: + * - It was deserialized from data that doesn't match any known member. For example, if the + * SDK is on an older version than the API, then the API may respond with new members that + * the SDK is unaware of. + * - It was constructed with an arbitrary value using the [of] method. + */ + enum class Value { + USD, + /** An enum member indicating that [Currency] was instantiated with an unknown value. */ + _UNKNOWN, + } + + /** + * Returns an enum member corresponding to this class instance's value, or [Value._UNKNOWN] + * if the class was instantiated with an unknown value. + * + * Use the [known] method instead if you're certain the value is always known or if you want + * to throw for the unknown case. + */ + fun value(): Value = + when (this) { + USD -> Value.USD + else -> Value._UNKNOWN + } + + /** + * Returns an enum member corresponding to this class instance's value. + * + * Use the [value] method instead if you're uncertain the value is always known and don't + * want to throw for the unknown case. + * + * @throws OpenAIInvalidDataException if this class instance's value is a not a known + * member. + */ + fun known(): Known = + when (this) { + USD -> Known.USD + else -> throw OpenAIInvalidDataException("Unknown Currency: $value") + } + + /** + * Returns this class instance's primitive wire representation. + * + * This differs from the [toString] method because that method is primarily for debugging + * and generally doesn't throw. + * + * @throws OpenAIInvalidDataException if this class instance's value does not have the + * expected primitive type. + */ + fun asString(): String = + _value().asString().orElseThrow { OpenAIInvalidDataException("Value is not a String") } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing fields. + * + * @throws OpenAIInvalidDataException if any value type in this object doesn't match its + * expected type. + */ + fun validate(): Currency = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OpenAIInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Currency && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + /** The time interval for evaluating spend against the threshold. */ + class Interval @JsonCreator private constructor(private val value: JsonField) : Enum { + + /** + * Returns this class instance's raw value. + * + * This is usually only useful if this instance was deserialized from data that doesn't + * match any known member, and you want to know that value. For example, if the SDK is on an + * older version than the API, then the API may respond with new members that the SDK is + * unaware of. + */ + @com.fasterxml.jackson.annotation.JsonValue fun _value(): JsonField = value + + companion object { + + @JvmField val MONTH = of("month") + + @JvmStatic fun of(value: String) = Interval(JsonField.of(value)) + } + + /** An enum containing [Interval]'s known values. */ + enum class Known { + MONTH + } + + /** + * An enum containing [Interval]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [Interval] can contain an unknown value in a couple of cases: + * - It was deserialized from data that doesn't match any known member. For example, if the + * SDK is on an older version than the API, then the API may respond with new members that + * the SDK is unaware of. + * - It was constructed with an arbitrary value using the [of] method. + */ + enum class Value { + MONTH, + /** An enum member indicating that [Interval] was instantiated with an unknown value. */ + _UNKNOWN, + } + + /** + * Returns an enum member corresponding to this class instance's value, or [Value._UNKNOWN] + * if the class was instantiated with an unknown value. + * + * Use the [known] method instead if you're certain the value is always known or if you want + * to throw for the unknown case. + */ + fun value(): Value = + when (this) { + MONTH -> Value.MONTH + else -> Value._UNKNOWN + } + + /** + * Returns an enum member corresponding to this class instance's value. + * + * Use the [value] method instead if you're uncertain the value is always known and don't + * want to throw for the unknown case. + * + * @throws OpenAIInvalidDataException if this class instance's value is a not a known + * member. + */ + fun known(): Known = + when (this) { + MONTH -> Known.MONTH + else -> throw OpenAIInvalidDataException("Unknown Interval: $value") + } + + /** + * Returns this class instance's primitive wire representation. + * + * This differs from the [toString] method because that method is primarily for debugging + * and generally doesn't throw. + * + * @throws OpenAIInvalidDataException if this class instance's value does not have the + * expected primitive type. + */ + fun asString(): String = + _value().asString().orElseThrow { OpenAIInvalidDataException("Value is not a String") } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing fields. + * + * @throws OpenAIInvalidDataException if any value type in this object doesn't match its + * expected type. + */ + fun validate(): Interval = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OpenAIInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Interval && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + /** Email notification settings for a spend alert. */ + class NotificationChannel + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val recipients: JsonField>, + private val type: JsonValue, + private val subjectPrefix: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("recipients") + @ExcludeMissing + recipients: JsonField> = JsonMissing.of(), + @JsonProperty("type") @ExcludeMissing type: JsonValue = JsonMissing.of(), + @JsonProperty("subject_prefix") + @ExcludeMissing + subjectPrefix: JsonField = JsonMissing.of(), + ) : this(recipients, type, subjectPrefix, mutableMapOf()) + + /** + * Email addresses that receive the spend alert notification. + * + * @throws OpenAIInvalidDataException 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 recipients(): List = recipients.getRequired("recipients") + + /** + * The notification channel type. Currently only `email` is supported. + * + * Expected to always return the following: + * ```java + * JsonValue.from("email") + * ``` + * + * However, this method can be useful for debugging and logging (e.g. if the server + * responded with an unexpected value). + */ + @JsonProperty("type") @ExcludeMissing fun _type(): JsonValue = type + + /** + * Optional subject prefix for alert emails. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun subjectPrefix(): Optional = subjectPrefix.getOptional("subject_prefix") + + /** + * Returns the raw JSON value of [recipients]. + * + * Unlike [recipients], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("recipients") + @ExcludeMissing + fun _recipients(): JsonField> = recipients + + /** + * Returns the raw JSON value of [subjectPrefix]. + * + * Unlike [subjectPrefix], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("subject_prefix") + @ExcludeMissing + fun _subjectPrefix(): JsonField = subjectPrefix + + @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 [NotificationChannel]. + * + * The following fields are required: + * ```java + * .recipients() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [NotificationChannel]. */ + class Builder internal constructor() { + + private var recipients: JsonField>? = null + private var type: JsonValue = JsonValue.from("email") + private var subjectPrefix: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(notificationChannel: NotificationChannel) = apply { + recipients = notificationChannel.recipients.map { it.toMutableList() } + type = notificationChannel.type + subjectPrefix = notificationChannel.subjectPrefix + additionalProperties = notificationChannel.additionalProperties.toMutableMap() + } + + /** Email addresses that receive the spend alert notification. */ + fun recipients(recipients: List) = recipients(JsonField.of(recipients)) + + /** + * Sets [Builder.recipients] to an arbitrary JSON value. + * + * You should usually call [Builder.recipients] with a well-typed `List` value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun recipients(recipients: JsonField>) = apply { + this.recipients = recipients.map { it.toMutableList() } + } + + /** + * Adds a single [String] to [recipients]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addRecipient(recipient: String) = apply { + recipients = + (recipients ?: JsonField.of(mutableListOf())).also { + checkKnown("recipients", it).add(recipient) + } + } + + /** + * Sets the field to an arbitrary JSON value. + * + * It is usually unnecessary to call this method because the field defaults to the + * following: + * ```java + * JsonValue.from("email") + * ``` + * + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun type(type: JsonValue) = apply { this.type = type } + + /** Optional subject prefix for alert emails. */ + fun subjectPrefix(subjectPrefix: String?) = + subjectPrefix(JsonField.ofNullable(subjectPrefix)) + + /** Alias for calling [Builder.subjectPrefix] with `subjectPrefix.orElse(null)`. */ + fun subjectPrefix(subjectPrefix: Optional) = + subjectPrefix(subjectPrefix.getOrNull()) + + /** + * Sets [Builder.subjectPrefix] to an arbitrary JSON value. + * + * You should usually call [Builder.subjectPrefix] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun subjectPrefix(subjectPrefix: JsonField) = apply { + this.subjectPrefix = subjectPrefix + } + + 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 [NotificationChannel]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .recipients() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): NotificationChannel = + NotificationChannel( + checkRequired("recipients", recipients).map { it.toImmutable() }, + type, + subjectPrefix, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing fields. + * + * @throws OpenAIInvalidDataException if any value type in this object doesn't match its + * expected type. + */ + fun validate(): NotificationChannel = apply { + if (validated) { + return@apply + } + + recipients() + _type().let { + if (it != JsonValue.from("email")) { + throw OpenAIInvalidDataException("'type' is invalid, received $it") + } + } + subjectPrefix() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OpenAIInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (recipients.asKnown().getOrNull()?.size ?: 0) + + type.let { if (it == JsonValue.from("email")) 1 else 0 } + + (if (subjectPrefix.asKnown().isPresent) 1 else 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is NotificationChannel && + recipients == other.recipients && + type == other.type && + subjectPrefix == other.subjectPrefix && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(recipients, type, subjectPrefix, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "NotificationChannel{recipients=$recipients, type=$type, subjectPrefix=$subjectPrefix, additionalProperties=$additionalProperties}" + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is SpendAlertUpdateParams && + alertId == other.alertId && + body == other.body && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams + } + + override fun hashCode(): Int = + Objects.hash(alertId, body, additionalHeaders, additionalQueryParams) + + override fun toString() = + "SpendAlertUpdateParams{alertId=$alertId, body=$body, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" +} diff --git a/openai-java-core/src/main/kotlin/com/openai/models/admin/organization/users/roles/RoleListResponse.kt b/openai-java-core/src/main/kotlin/com/openai/models/admin/organization/users/roles/RoleListResponse.kt index 10c626e05..4cfea3661 100644 --- a/openai-java-core/src/main/kotlin/com/openai/models/admin/organization/users/roles/RoleListResponse.kt +++ b/openai-java-core/src/main/kotlin/com/openai/models/admin/organization/users/roles/RoleListResponse.kt @@ -24,6 +24,7 @@ class RoleListResponse @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val id: JsonField, + private val assignmentSources: JsonField>, private val createdAt: JsonField, private val createdBy: JsonField, private val createdByUserObj: JsonField, @@ -40,6 +41,9 @@ private constructor( @JsonCreator private constructor( @JsonProperty("id") @ExcludeMissing id: JsonField = JsonMissing.of(), + @JsonProperty("assignment_sources") + @ExcludeMissing + assignmentSources: JsonField> = JsonMissing.of(), @JsonProperty("created_at") @ExcludeMissing createdAt: JsonField = JsonMissing.of(), @JsonProperty("created_by") @ExcludeMissing createdBy: JsonField = JsonMissing.of(), @JsonProperty("created_by_user_obj") @@ -62,6 +66,7 @@ private constructor( @JsonProperty("updated_at") @ExcludeMissing updatedAt: JsonField = JsonMissing.of(), ) : this( id, + assignmentSources, createdAt, createdBy, createdByUserObj, @@ -83,6 +88,15 @@ private constructor( */ fun id(): String = id.getRequired("id") + /** + * Principals from which the role assignment is inherited, when available. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun assignmentSources(): Optional> = + assignmentSources.getOptional("assignment_sources") + /** * When the role was created. * @@ -171,6 +185,16 @@ private constructor( */ @JsonProperty("id") @ExcludeMissing fun _id(): JsonField = id + /** + * Returns the raw JSON value of [assignmentSources]. + * + * Unlike [assignmentSources], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("assignment_sources") + @ExcludeMissing + fun _assignmentSources(): JsonField> = assignmentSources + /** * Returns the raw JSON value of [createdAt]. * @@ -270,6 +294,7 @@ private constructor( * The following fields are required: * ```java * .id() + * .assignmentSources() * .createdAt() * .createdBy() * .createdByUserObj() @@ -289,6 +314,7 @@ private constructor( class Builder internal constructor() { private var id: JsonField? = null + private var assignmentSources: JsonField>? = null private var createdAt: JsonField? = null private var createdBy: JsonField? = null private var createdByUserObj: JsonField? = null @@ -304,6 +330,7 @@ private constructor( @JvmSynthetic internal fun from(roleListResponse: RoleListResponse) = apply { id = roleListResponse.id + assignmentSources = roleListResponse.assignmentSources.map { it.toMutableList() } createdAt = roleListResponse.createdAt createdBy = roleListResponse.createdBy createdByUserObj = roleListResponse.createdByUserObj @@ -328,6 +355,37 @@ private constructor( */ fun id(id: JsonField) = apply { this.id = id } + /** Principals from which the role assignment is inherited, when available. */ + fun assignmentSources(assignmentSources: List?) = + assignmentSources(JsonField.ofNullable(assignmentSources)) + + /** Alias for calling [Builder.assignmentSources] with `assignmentSources.orElse(null)`. */ + fun assignmentSources(assignmentSources: Optional>) = + assignmentSources(assignmentSources.getOrNull()) + + /** + * Sets [Builder.assignmentSources] to an arbitrary JSON value. + * + * You should usually call [Builder.assignmentSources] with a well-typed + * `List` value instead. This method is primarily for setting the field to + * an undocumented or not yet supported value. + */ + fun assignmentSources(assignmentSources: JsonField>) = apply { + this.assignmentSources = assignmentSources.map { it.toMutableList() } + } + + /** + * Adds a single [AssignmentSource] to [assignmentSources]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addAssignmentSource(assignmentSource: AssignmentSource) = apply { + assignmentSources = + (assignmentSources ?: JsonField.of(mutableListOf())).also { + checkKnown("assignmentSources", it).add(assignmentSource) + } + } + /** When the role was created. */ fun createdAt(createdAt: Long?) = createdAt(JsonField.ofNullable(createdAt)) @@ -526,6 +584,7 @@ private constructor( * The following fields are required: * ```java * .id() + * .assignmentSources() * .createdAt() * .createdBy() * .createdByUserObj() @@ -543,6 +602,7 @@ private constructor( fun build(): RoleListResponse = RoleListResponse( checkRequired("id", id), + checkRequired("assignmentSources", assignmentSources).map { it.toImmutable() }, checkRequired("createdAt", createdAt), checkRequired("createdBy", createdBy), checkRequired("createdByUserObj", createdByUserObj), @@ -573,6 +633,7 @@ private constructor( } id() + assignmentSources().ifPresent { it.forEach { it.validate() } } createdAt() createdBy() createdByUserObj().ifPresent { it.validate() } @@ -602,6 +663,7 @@ private constructor( @JvmSynthetic internal fun validity(): Int = (if (id.asKnown().isPresent) 1 else 0) + + (assignmentSources.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + (if (createdAt.asKnown().isPresent) 1 else 0) + (if (createdBy.asKnown().isPresent) 1 else 0) + (createdByUserObj.asKnown().getOrNull()?.validity() ?: 0) + @@ -613,6 +675,222 @@ private constructor( (if (resourceType.asKnown().isPresent) 1 else 0) + (if (updatedAt.asKnown().isPresent) 1 else 0) + class AssignmentSource + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val principalId: JsonField, + private val principalType: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("principal_id") + @ExcludeMissing + principalId: JsonField = JsonMissing.of(), + @JsonProperty("principal_type") + @ExcludeMissing + principalType: JsonField = JsonMissing.of(), + ) : this(principalId, principalType, mutableMapOf()) + + /** + * @throws OpenAIInvalidDataException 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 principalId(): String = principalId.getRequired("principal_id") + + /** + * @throws OpenAIInvalidDataException 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 principalType(): String = principalType.getRequired("principal_type") + + /** + * Returns the raw JSON value of [principalId]. + * + * Unlike [principalId], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("principal_id") + @ExcludeMissing + fun _principalId(): JsonField = principalId + + /** + * Returns the raw JSON value of [principalType]. + * + * Unlike [principalType], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("principal_type") + @ExcludeMissing + fun _principalType(): JsonField = principalType + + @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 [AssignmentSource]. + * + * The following fields are required: + * ```java + * .principalId() + * .principalType() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [AssignmentSource]. */ + class Builder internal constructor() { + + private var principalId: JsonField? = null + private var principalType: JsonField? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(assignmentSource: AssignmentSource) = apply { + principalId = assignmentSource.principalId + principalType = assignmentSource.principalType + additionalProperties = assignmentSource.additionalProperties.toMutableMap() + } + + fun principalId(principalId: String) = principalId(JsonField.of(principalId)) + + /** + * Sets [Builder.principalId] to an arbitrary JSON value. + * + * You should usually call [Builder.principalId] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun principalId(principalId: JsonField) = apply { + this.principalId = principalId + } + + fun principalType(principalType: String) = principalType(JsonField.of(principalType)) + + /** + * Sets [Builder.principalType] to an arbitrary JSON value. + * + * You should usually call [Builder.principalType] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun principalType(principalType: JsonField) = apply { + this.principalType = principalType + } + + 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 [AssignmentSource]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .principalId() + * .principalType() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): AssignmentSource = + AssignmentSource( + checkRequired("principalId", principalId), + checkRequired("principalType", principalType), + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing fields. + * + * @throws OpenAIInvalidDataException if any value type in this object doesn't match its + * expected type. + */ + fun validate(): AssignmentSource = apply { + if (validated) { + return@apply + } + + principalId() + principalType() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OpenAIInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (if (principalId.asKnown().isPresent) 1 else 0) + + (if (principalType.asKnown().isPresent) 1 else 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is AssignmentSource && + principalId == other.principalId && + principalType == other.principalType && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(principalId, principalType, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "AssignmentSource{principalId=$principalId, principalType=$principalType, additionalProperties=$additionalProperties}" + } + /** User details for the actor that created the role, when available. */ class CreatedByUserObj @JsonCreator @@ -838,6 +1116,7 @@ private constructor( return other is RoleListResponse && id == other.id && + assignmentSources == other.assignmentSources && createdAt == other.createdAt && createdBy == other.createdBy && createdByUserObj == other.createdByUserObj && @@ -854,6 +1133,7 @@ private constructor( private val hashCode: Int by lazy { Objects.hash( id, + assignmentSources, createdAt, createdBy, createdByUserObj, @@ -871,5 +1151,5 @@ private constructor( override fun hashCode(): Int = hashCode override fun toString() = - "RoleListResponse{id=$id, createdAt=$createdAt, createdBy=$createdBy, createdByUserObj=$createdByUserObj, description=$description, metadata=$metadata, name=$name, permissions=$permissions, predefinedRole=$predefinedRole, resourceType=$resourceType, updatedAt=$updatedAt, additionalProperties=$additionalProperties}" + "RoleListResponse{id=$id, assignmentSources=$assignmentSources, createdAt=$createdAt, createdBy=$createdBy, createdByUserObj=$createdByUserObj, description=$description, metadata=$metadata, name=$name, permissions=$permissions, predefinedRole=$predefinedRole, resourceType=$resourceType, updatedAt=$updatedAt, additionalProperties=$additionalProperties}" } diff --git a/openai-java-core/src/main/kotlin/com/openai/models/admin/organization/users/roles/RoleRetrieveParams.kt b/openai-java-core/src/main/kotlin/com/openai/models/admin/organization/users/roles/RoleRetrieveParams.kt new file mode 100644 index 000000000..87190d742 --- /dev/null +++ b/openai-java-core/src/main/kotlin/com/openai/models/admin/organization/users/roles/RoleRetrieveParams.kt @@ -0,0 +1,217 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.models.admin.organization.users.roles + +import com.openai.core.Params +import com.openai.core.checkRequired +import com.openai.core.http.Headers +import com.openai.core.http.QueryParams +import java.util.Objects +import java.util.Optional +import kotlin.jvm.optionals.getOrNull + +/** Retrieves an organization role assigned to a user. */ +class RoleRetrieveParams +private constructor( + private val userId: String, + private val roleId: String?, + private val additionalHeaders: Headers, + private val additionalQueryParams: QueryParams, +) : Params { + + fun userId(): String = userId + + fun roleId(): Optional = Optional.ofNullable(roleId) + + /** Additional headers to send with the request. */ + fun _additionalHeaders(): Headers = additionalHeaders + + /** Additional query param to send with the request. */ + fun _additionalQueryParams(): QueryParams = additionalQueryParams + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of [RoleRetrieveParams]. + * + * The following fields are required: + * ```java + * .userId() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [RoleRetrieveParams]. */ + class Builder internal constructor() { + + private var userId: String? = null + private var roleId: String? = null + private var additionalHeaders: Headers.Builder = Headers.builder() + private var additionalQueryParams: QueryParams.Builder = QueryParams.builder() + + @JvmSynthetic + internal fun from(roleRetrieveParams: RoleRetrieveParams) = apply { + userId = roleRetrieveParams.userId + roleId = roleRetrieveParams.roleId + additionalHeaders = roleRetrieveParams.additionalHeaders.toBuilder() + additionalQueryParams = roleRetrieveParams.additionalQueryParams.toBuilder() + } + + fun userId(userId: String) = apply { this.userId = userId } + + fun roleId(roleId: String?) = apply { this.roleId = roleId } + + /** Alias for calling [Builder.roleId] with `roleId.orElse(null)`. */ + fun roleId(roleId: Optional) = roleId(roleId.getOrNull()) + + 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 [RoleRetrieveParams]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .userId() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): RoleRetrieveParams = + RoleRetrieveParams( + checkRequired("userId", userId), + roleId, + additionalHeaders.build(), + additionalQueryParams.build(), + ) + } + + fun _pathParam(index: Int): String = + when (index) { + 0 -> userId + 1 -> roleId ?: "" + else -> "" + } + + override fun _headers(): Headers = additionalHeaders + + override fun _queryParams(): QueryParams = additionalQueryParams + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is RoleRetrieveParams && + userId == other.userId && + roleId == other.roleId && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams + } + + override fun hashCode(): Int = + Objects.hash(userId, roleId, additionalHeaders, additionalQueryParams) + + override fun toString() = + "RoleRetrieveParams{userId=$userId, roleId=$roleId, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" +} diff --git a/openai-java-core/src/main/kotlin/com/openai/models/admin/organization/users/roles/RoleRetrieveResponse.kt b/openai-java-core/src/main/kotlin/com/openai/models/admin/organization/users/roles/RoleRetrieveResponse.kt new file mode 100644 index 000000000..f618e3552 --- /dev/null +++ b/openai-java-core/src/main/kotlin/com/openai/models/admin/organization/users/roles/RoleRetrieveResponse.kt @@ -0,0 +1,1155 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.models.admin.organization.users.roles + +import com.fasterxml.jackson.annotation.JsonAnyGetter +import com.fasterxml.jackson.annotation.JsonAnySetter +import com.fasterxml.jackson.annotation.JsonCreator +import com.fasterxml.jackson.annotation.JsonProperty +import com.openai.core.ExcludeMissing +import com.openai.core.JsonField +import com.openai.core.JsonMissing +import com.openai.core.JsonValue +import com.openai.core.checkKnown +import com.openai.core.checkRequired +import com.openai.core.toImmutable +import com.openai.errors.OpenAIInvalidDataException +import java.util.Collections +import java.util.Objects +import java.util.Optional +import kotlin.jvm.optionals.getOrNull + +/** Detailed information about a role assignment entry returned when listing assignments. */ +class RoleRetrieveResponse +@JsonCreator(mode = JsonCreator.Mode.DISABLED) +private constructor( + private val id: JsonField, + private val assignmentSources: JsonField>, + private val createdAt: JsonField, + private val createdBy: JsonField, + private val createdByUserObj: JsonField, + private val description: JsonField, + private val metadata: JsonField, + private val name: JsonField, + private val permissions: JsonField>, + private val predefinedRole: JsonField, + private val resourceType: JsonField, + private val updatedAt: JsonField, + private val additionalProperties: MutableMap, +) { + + @JsonCreator + private constructor( + @JsonProperty("id") @ExcludeMissing id: JsonField = JsonMissing.of(), + @JsonProperty("assignment_sources") + @ExcludeMissing + assignmentSources: JsonField> = JsonMissing.of(), + @JsonProperty("created_at") @ExcludeMissing createdAt: JsonField = JsonMissing.of(), + @JsonProperty("created_by") @ExcludeMissing createdBy: JsonField = JsonMissing.of(), + @JsonProperty("created_by_user_obj") + @ExcludeMissing + createdByUserObj: 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("permissions") + @ExcludeMissing + permissions: JsonField> = JsonMissing.of(), + @JsonProperty("predefined_role") + @ExcludeMissing + predefinedRole: JsonField = JsonMissing.of(), + @JsonProperty("resource_type") + @ExcludeMissing + resourceType: JsonField = JsonMissing.of(), + @JsonProperty("updated_at") @ExcludeMissing updatedAt: JsonField = JsonMissing.of(), + ) : this( + id, + assignmentSources, + createdAt, + createdBy, + createdByUserObj, + description, + metadata, + name, + permissions, + predefinedRole, + resourceType, + updatedAt, + mutableMapOf(), + ) + + /** + * Identifier for the role. + * + * @throws OpenAIInvalidDataException 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 id(): String = id.getRequired("id") + + /** + * Principals from which the role assignment is inherited, when available. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun assignmentSources(): Optional> = + assignmentSources.getOptional("assignment_sources") + + /** + * When the role was created. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun createdAt(): Optional = createdAt.getOptional("created_at") + + /** + * Identifier of the actor who created the role. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun createdBy(): Optional = createdBy.getOptional("created_by") + + /** + * User details for the actor that created the role, when available. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun createdByUserObj(): Optional = + createdByUserObj.getOptional("created_by_user_obj") + + /** + * Description of the role. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun description(): Optional = description.getOptional("description") + + /** + * Arbitrary metadata stored on the role. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun metadata(): Optional = metadata.getOptional("metadata") + + /** + * Name of the role. + * + * @throws OpenAIInvalidDataException 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") + + /** + * Permissions associated with the role. + * + * @throws OpenAIInvalidDataException 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 permissions(): List = permissions.getRequired("permissions") + + /** + * Whether the role is predefined by OpenAI. + * + * @throws OpenAIInvalidDataException 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 predefinedRole(): Boolean = predefinedRole.getRequired("predefined_role") + + /** + * Resource type the role applies to. + * + * @throws OpenAIInvalidDataException 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 resourceType(): String = resourceType.getRequired("resource_type") + + /** + * When the role was last updated. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun updatedAt(): Optional = updatedAt.getOptional("updated_at") + + /** + * Returns the raw JSON value of [id]. + * + * Unlike [id], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("id") @ExcludeMissing fun _id(): JsonField = id + + /** + * Returns the raw JSON value of [assignmentSources]. + * + * Unlike [assignmentSources], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("assignment_sources") + @ExcludeMissing + fun _assignmentSources(): JsonField> = assignmentSources + + /** + * Returns the raw JSON value of [createdAt]. + * + * Unlike [createdAt], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("created_at") @ExcludeMissing fun _createdAt(): JsonField = createdAt + + /** + * Returns the raw JSON value of [createdBy]. + * + * Unlike [createdBy], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("created_by") @ExcludeMissing fun _createdBy(): JsonField = createdBy + + /** + * Returns the raw JSON value of [createdByUserObj]. + * + * Unlike [createdByUserObj], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("created_by_user_obj") + @ExcludeMissing + fun _createdByUserObj(): JsonField = createdByUserObj + + /** + * 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 + + /** + * Returns the raw JSON value of [permissions]. + * + * Unlike [permissions], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("permissions") + @ExcludeMissing + fun _permissions(): JsonField> = permissions + + /** + * Returns the raw JSON value of [predefinedRole]. + * + * Unlike [predefinedRole], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("predefined_role") + @ExcludeMissing + fun _predefinedRole(): JsonField = predefinedRole + + /** + * Returns the raw JSON value of [resourceType]. + * + * Unlike [resourceType], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("resource_type") + @ExcludeMissing + fun _resourceType(): JsonField = resourceType + + /** + * Returns the raw JSON value of [updatedAt]. + * + * Unlike [updatedAt], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("updated_at") @ExcludeMissing fun _updatedAt(): JsonField = updatedAt + + @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 [RoleRetrieveResponse]. + * + * The following fields are required: + * ```java + * .id() + * .assignmentSources() + * .createdAt() + * .createdBy() + * .createdByUserObj() + * .description() + * .metadata() + * .name() + * .permissions() + * .predefinedRole() + * .resourceType() + * .updatedAt() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [RoleRetrieveResponse]. */ + class Builder internal constructor() { + + private var id: JsonField? = null + private var assignmentSources: JsonField>? = null + private var createdAt: JsonField? = null + private var createdBy: JsonField? = null + private var createdByUserObj: JsonField? = null + private var description: JsonField? = null + private var metadata: JsonField? = null + private var name: JsonField? = null + private var permissions: JsonField>? = null + private var predefinedRole: JsonField? = null + private var resourceType: JsonField? = null + private var updatedAt: JsonField? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(roleRetrieveResponse: RoleRetrieveResponse) = apply { + id = roleRetrieveResponse.id + assignmentSources = roleRetrieveResponse.assignmentSources.map { it.toMutableList() } + createdAt = roleRetrieveResponse.createdAt + createdBy = roleRetrieveResponse.createdBy + createdByUserObj = roleRetrieveResponse.createdByUserObj + description = roleRetrieveResponse.description + metadata = roleRetrieveResponse.metadata + name = roleRetrieveResponse.name + permissions = roleRetrieveResponse.permissions.map { it.toMutableList() } + predefinedRole = roleRetrieveResponse.predefinedRole + resourceType = roleRetrieveResponse.resourceType + updatedAt = roleRetrieveResponse.updatedAt + additionalProperties = roleRetrieveResponse.additionalProperties.toMutableMap() + } + + /** Identifier for the role. */ + fun id(id: String) = id(JsonField.of(id)) + + /** + * Sets [Builder.id] to an arbitrary JSON value. + * + * You should usually call [Builder.id] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun id(id: JsonField) = apply { this.id = id } + + /** Principals from which the role assignment is inherited, when available. */ + fun assignmentSources(assignmentSources: List?) = + assignmentSources(JsonField.ofNullable(assignmentSources)) + + /** Alias for calling [Builder.assignmentSources] with `assignmentSources.orElse(null)`. */ + fun assignmentSources(assignmentSources: Optional>) = + assignmentSources(assignmentSources.getOrNull()) + + /** + * Sets [Builder.assignmentSources] to an arbitrary JSON value. + * + * You should usually call [Builder.assignmentSources] with a well-typed + * `List` value instead. This method is primarily for setting the field to + * an undocumented or not yet supported value. + */ + fun assignmentSources(assignmentSources: JsonField>) = apply { + this.assignmentSources = assignmentSources.map { it.toMutableList() } + } + + /** + * Adds a single [AssignmentSource] to [assignmentSources]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addAssignmentSource(assignmentSource: AssignmentSource) = apply { + assignmentSources = + (assignmentSources ?: JsonField.of(mutableListOf())).also { + checkKnown("assignmentSources", it).add(assignmentSource) + } + } + + /** When the role was created. */ + fun createdAt(createdAt: Long?) = createdAt(JsonField.ofNullable(createdAt)) + + /** + * Alias for [Builder.createdAt]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun createdAt(createdAt: Long) = createdAt(createdAt as Long?) + + /** Alias for calling [Builder.createdAt] with `createdAt.orElse(null)`. */ + fun createdAt(createdAt: Optional) = createdAt(createdAt.getOrNull()) + + /** + * Sets [Builder.createdAt] to an arbitrary JSON value. + * + * You should usually call [Builder.createdAt] with a well-typed [Long] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun createdAt(createdAt: JsonField) = apply { this.createdAt = createdAt } + + /** Identifier of the actor who created the role. */ + fun createdBy(createdBy: String?) = createdBy(JsonField.ofNullable(createdBy)) + + /** Alias for calling [Builder.createdBy] with `createdBy.orElse(null)`. */ + fun createdBy(createdBy: Optional) = createdBy(createdBy.getOrNull()) + + /** + * Sets [Builder.createdBy] to an arbitrary JSON value. + * + * You should usually call [Builder.createdBy] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun createdBy(createdBy: JsonField) = apply { this.createdBy = createdBy } + + /** User details for the actor that created the role, when available. */ + fun createdByUserObj(createdByUserObj: CreatedByUserObj?) = + createdByUserObj(JsonField.ofNullable(createdByUserObj)) + + /** Alias for calling [Builder.createdByUserObj] with `createdByUserObj.orElse(null)`. */ + fun createdByUserObj(createdByUserObj: Optional) = + createdByUserObj(createdByUserObj.getOrNull()) + + /** + * Sets [Builder.createdByUserObj] to an arbitrary JSON value. + * + * You should usually call [Builder.createdByUserObj] with a well-typed [CreatedByUserObj] + * value instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun createdByUserObj(createdByUserObj: JsonField) = apply { + this.createdByUserObj = createdByUserObj + } + + /** 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 } + + /** Arbitrary metadata stored on the role. */ + 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 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 } + + /** Permissions associated with the role. */ + fun permissions(permissions: List) = permissions(JsonField.of(permissions)) + + /** + * Sets [Builder.permissions] to an arbitrary JSON value. + * + * You should usually call [Builder.permissions] with a well-typed `List` value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun permissions(permissions: JsonField>) = apply { + this.permissions = permissions.map { it.toMutableList() } + } + + /** + * Adds a single [String] to [permissions]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addPermission(permission: String) = apply { + permissions = + (permissions ?: JsonField.of(mutableListOf())).also { + checkKnown("permissions", it).add(permission) + } + } + + /** Whether the role is predefined by OpenAI. */ + fun predefinedRole(predefinedRole: Boolean) = predefinedRole(JsonField.of(predefinedRole)) + + /** + * Sets [Builder.predefinedRole] to an arbitrary JSON value. + * + * You should usually call [Builder.predefinedRole] with a well-typed [Boolean] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun predefinedRole(predefinedRole: JsonField) = apply { + this.predefinedRole = predefinedRole + } + + /** Resource type the role applies to. */ + fun resourceType(resourceType: String) = resourceType(JsonField.of(resourceType)) + + /** + * Sets [Builder.resourceType] to an arbitrary JSON value. + * + * You should usually call [Builder.resourceType] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun resourceType(resourceType: JsonField) = apply { + this.resourceType = resourceType + } + + /** When the role was last updated. */ + fun updatedAt(updatedAt: Long?) = updatedAt(JsonField.ofNullable(updatedAt)) + + /** + * Alias for [Builder.updatedAt]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun updatedAt(updatedAt: Long) = updatedAt(updatedAt as Long?) + + /** Alias for calling [Builder.updatedAt] with `updatedAt.orElse(null)`. */ + fun updatedAt(updatedAt: Optional) = updatedAt(updatedAt.getOrNull()) + + /** + * Sets [Builder.updatedAt] to an arbitrary JSON value. + * + * You should usually call [Builder.updatedAt] with a well-typed [Long] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun updatedAt(updatedAt: JsonField) = apply { this.updatedAt = updatedAt } + + 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 [RoleRetrieveResponse]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .id() + * .assignmentSources() + * .createdAt() + * .createdBy() + * .createdByUserObj() + * .description() + * .metadata() + * .name() + * .permissions() + * .predefinedRole() + * .resourceType() + * .updatedAt() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): RoleRetrieveResponse = + RoleRetrieveResponse( + checkRequired("id", id), + checkRequired("assignmentSources", assignmentSources).map { it.toImmutable() }, + checkRequired("createdAt", createdAt), + checkRequired("createdBy", createdBy), + checkRequired("createdByUserObj", createdByUserObj), + checkRequired("description", description), + checkRequired("metadata", metadata), + checkRequired("name", name), + checkRequired("permissions", permissions).map { it.toImmutable() }, + checkRequired("predefinedRole", predefinedRole), + checkRequired("resourceType", resourceType), + checkRequired("updatedAt", updatedAt), + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected types recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing fields. + * + * @throws OpenAIInvalidDataException if any value type in this object doesn't match its + * expected type. + */ + fun validate(): RoleRetrieveResponse = apply { + if (validated) { + return@apply + } + + id() + assignmentSources().ifPresent { it.forEach { it.validate() } } + createdAt() + createdBy() + createdByUserObj().ifPresent { it.validate() } + description() + metadata().ifPresent { it.validate() } + name() + permissions() + predefinedRole() + resourceType() + updatedAt() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OpenAIInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (if (id.asKnown().isPresent) 1 else 0) + + (assignmentSources.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + + (if (createdAt.asKnown().isPresent) 1 else 0) + + (if (createdBy.asKnown().isPresent) 1 else 0) + + (createdByUserObj.asKnown().getOrNull()?.validity() ?: 0) + + (if (description.asKnown().isPresent) 1 else 0) + + (metadata.asKnown().getOrNull()?.validity() ?: 0) + + (if (name.asKnown().isPresent) 1 else 0) + + (permissions.asKnown().getOrNull()?.size ?: 0) + + (if (predefinedRole.asKnown().isPresent) 1 else 0) + + (if (resourceType.asKnown().isPresent) 1 else 0) + + (if (updatedAt.asKnown().isPresent) 1 else 0) + + class AssignmentSource + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val principalId: JsonField, + private val principalType: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("principal_id") + @ExcludeMissing + principalId: JsonField = JsonMissing.of(), + @JsonProperty("principal_type") + @ExcludeMissing + principalType: JsonField = JsonMissing.of(), + ) : this(principalId, principalType, mutableMapOf()) + + /** + * @throws OpenAIInvalidDataException 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 principalId(): String = principalId.getRequired("principal_id") + + /** + * @throws OpenAIInvalidDataException 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 principalType(): String = principalType.getRequired("principal_type") + + /** + * Returns the raw JSON value of [principalId]. + * + * Unlike [principalId], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("principal_id") + @ExcludeMissing + fun _principalId(): JsonField = principalId + + /** + * Returns the raw JSON value of [principalType]. + * + * Unlike [principalType], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("principal_type") + @ExcludeMissing + fun _principalType(): JsonField = principalType + + @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 [AssignmentSource]. + * + * The following fields are required: + * ```java + * .principalId() + * .principalType() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [AssignmentSource]. */ + class Builder internal constructor() { + + private var principalId: JsonField? = null + private var principalType: JsonField? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(assignmentSource: AssignmentSource) = apply { + principalId = assignmentSource.principalId + principalType = assignmentSource.principalType + additionalProperties = assignmentSource.additionalProperties.toMutableMap() + } + + fun principalId(principalId: String) = principalId(JsonField.of(principalId)) + + /** + * Sets [Builder.principalId] to an arbitrary JSON value. + * + * You should usually call [Builder.principalId] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun principalId(principalId: JsonField) = apply { + this.principalId = principalId + } + + fun principalType(principalType: String) = principalType(JsonField.of(principalType)) + + /** + * Sets [Builder.principalType] to an arbitrary JSON value. + * + * You should usually call [Builder.principalType] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun principalType(principalType: JsonField) = apply { + this.principalType = principalType + } + + 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 [AssignmentSource]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .principalId() + * .principalType() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): AssignmentSource = + AssignmentSource( + checkRequired("principalId", principalId), + checkRequired("principalType", principalType), + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing fields. + * + * @throws OpenAIInvalidDataException if any value type in this object doesn't match its + * expected type. + */ + fun validate(): AssignmentSource = apply { + if (validated) { + return@apply + } + + principalId() + principalType() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OpenAIInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (if (principalId.asKnown().isPresent) 1 else 0) + + (if (principalType.asKnown().isPresent) 1 else 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is AssignmentSource && + principalId == other.principalId && + principalType == other.principalType && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(principalId, principalType, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "AssignmentSource{principalId=$principalId, principalType=$principalType, additionalProperties=$additionalProperties}" + } + + /** User details for the actor that created the role, when available. */ + class CreatedByUserObj + @JsonCreator + private constructor( + @com.fasterxml.jackson.annotation.JsonValue + private val additionalProperties: Map + ) { + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = additionalProperties + + fun toBuilder() = Builder().from(this) + + companion object { + + /** Returns a mutable builder for constructing an instance of [CreatedByUserObj]. */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [CreatedByUserObj]. */ + class Builder internal constructor() { + + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(createdByUserObj: CreatedByUserObj) = apply { + additionalProperties = createdByUserObj.additionalProperties.toMutableMap() + } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [CreatedByUserObj]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): CreatedByUserObj = CreatedByUserObj(additionalProperties.toImmutable()) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing fields. + * + * @throws OpenAIInvalidDataException if any value type in this object doesn't match its + * expected type. + */ + fun validate(): CreatedByUserObj = apply { + if (validated) { + return@apply + } + + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OpenAIInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + additionalProperties.count { (_, value) -> !value.isNull() && !value.isMissing() } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is CreatedByUserObj && additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = "CreatedByUserObj{additionalProperties=$additionalProperties}" + } + + /** Arbitrary metadata stored on the role. */ + class Metadata + @JsonCreator + private constructor( + @com.fasterxml.jackson.annotation.JsonValue + private val additionalProperties: Map + ) { + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = additionalProperties + + fun toBuilder() = Builder().from(this) + + companion object { + + /** Returns a mutable builder for constructing an instance of [Metadata]. */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [Metadata]. */ + class Builder internal constructor() { + + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(metadata: Metadata) = apply { + additionalProperties = metadata.additionalProperties.toMutableMap() + } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [Metadata]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): Metadata = Metadata(additionalProperties.toImmutable()) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing fields. + * + * @throws OpenAIInvalidDataException if any value type in this object doesn't match its + * expected type. + */ + fun validate(): Metadata = apply { + if (validated) { + return@apply + } + + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OpenAIInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + additionalProperties.count { (_, value) -> !value.isNull() && !value.isMissing() } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Metadata && additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = "Metadata{additionalProperties=$additionalProperties}" + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is RoleRetrieveResponse && + id == other.id && + assignmentSources == other.assignmentSources && + createdAt == other.createdAt && + createdBy == other.createdBy && + createdByUserObj == other.createdByUserObj && + description == other.description && + metadata == other.metadata && + name == other.name && + permissions == other.permissions && + predefinedRole == other.predefinedRole && + resourceType == other.resourceType && + updatedAt == other.updatedAt && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + id, + assignmentSources, + createdAt, + createdBy, + createdByUserObj, + description, + metadata, + name, + permissions, + predefinedRole, + resourceType, + updatedAt, + additionalProperties, + ) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "RoleRetrieveResponse{id=$id, assignmentSources=$assignmentSources, createdAt=$createdAt, createdBy=$createdBy, createdByUserObj=$createdByUserObj, description=$description, metadata=$metadata, name=$name, permissions=$permissions, predefinedRole=$predefinedRole, resourceType=$resourceType, updatedAt=$updatedAt, additionalProperties=$additionalProperties}" +} diff --git a/openai-java-core/src/main/kotlin/com/openai/models/responses/ResponseFunctionWebSearch.kt b/openai-java-core/src/main/kotlin/com/openai/models/responses/ResponseFunctionWebSearch.kt index ecbe1232c..edf29d553 100644 --- a/openai-java-core/src/main/kotlin/com/openai/models/responses/ResponseFunctionWebSearch.kt +++ b/openai-java-core/src/main/kotlin/com/openai/models/responses/ResponseFunctionWebSearch.kt @@ -1110,7 +1110,7 @@ private constructor( ) : this(type, url, mutableMapOf()) /** - * The action type. Always `open_page`. + * The action type. * * Expected to always return the following: * ```java diff --git a/openai-java-core/src/main/kotlin/com/openai/services/async/admin/OrganizationServiceAsync.kt b/openai-java-core/src/main/kotlin/com/openai/services/async/admin/OrganizationServiceAsync.kt index 5d114eee2..658470d47 100644 --- a/openai-java-core/src/main/kotlin/com/openai/services/async/admin/OrganizationServiceAsync.kt +++ b/openai-java-core/src/main/kotlin/com/openai/services/async/admin/OrganizationServiceAsync.kt @@ -6,10 +6,12 @@ import com.openai.core.ClientOptions import com.openai.services.async.admin.organization.AdminApiKeyServiceAsync import com.openai.services.async.admin.organization.AuditLogServiceAsync import com.openai.services.async.admin.organization.CertificateServiceAsync +import com.openai.services.async.admin.organization.DataRetentionServiceAsync import com.openai.services.async.admin.organization.GroupServiceAsync import com.openai.services.async.admin.organization.InviteServiceAsync import com.openai.services.async.admin.organization.ProjectServiceAsync import com.openai.services.async.admin.organization.RoleServiceAsync +import com.openai.services.async.admin.organization.SpendAlertServiceAsync import com.openai.services.async.admin.organization.UsageServiceAsync import com.openai.services.async.admin.organization.UserServiceAsync import java.util.function.Consumer @@ -43,6 +45,10 @@ interface OrganizationServiceAsync { fun roles(): RoleServiceAsync + fun dataRetention(): DataRetentionServiceAsync + + fun spendAlerts(): SpendAlertServiceAsync + fun certificates(): CertificateServiceAsync fun projects(): ProjectServiceAsync @@ -77,6 +83,10 @@ interface OrganizationServiceAsync { fun roles(): RoleServiceAsync.WithRawResponse + fun dataRetention(): DataRetentionServiceAsync.WithRawResponse + + fun spendAlerts(): SpendAlertServiceAsync.WithRawResponse + fun certificates(): CertificateServiceAsync.WithRawResponse fun projects(): ProjectServiceAsync.WithRawResponse diff --git a/openai-java-core/src/main/kotlin/com/openai/services/async/admin/OrganizationServiceAsyncImpl.kt b/openai-java-core/src/main/kotlin/com/openai/services/async/admin/OrganizationServiceAsyncImpl.kt index 5718523a8..735c4166e 100644 --- a/openai-java-core/src/main/kotlin/com/openai/services/async/admin/OrganizationServiceAsyncImpl.kt +++ b/openai-java-core/src/main/kotlin/com/openai/services/async/admin/OrganizationServiceAsyncImpl.kt @@ -9,6 +9,8 @@ import com.openai.services.async.admin.organization.AuditLogServiceAsync import com.openai.services.async.admin.organization.AuditLogServiceAsyncImpl import com.openai.services.async.admin.organization.CertificateServiceAsync import com.openai.services.async.admin.organization.CertificateServiceAsyncImpl +import com.openai.services.async.admin.organization.DataRetentionServiceAsync +import com.openai.services.async.admin.organization.DataRetentionServiceAsyncImpl import com.openai.services.async.admin.organization.GroupServiceAsync import com.openai.services.async.admin.organization.GroupServiceAsyncImpl import com.openai.services.async.admin.organization.InviteServiceAsync @@ -17,6 +19,8 @@ import com.openai.services.async.admin.organization.ProjectServiceAsync import com.openai.services.async.admin.organization.ProjectServiceAsyncImpl import com.openai.services.async.admin.organization.RoleServiceAsync import com.openai.services.async.admin.organization.RoleServiceAsyncImpl +import com.openai.services.async.admin.organization.SpendAlertServiceAsync +import com.openai.services.async.admin.organization.SpendAlertServiceAsyncImpl import com.openai.services.async.admin.organization.UsageServiceAsync import com.openai.services.async.admin.organization.UsageServiceAsyncImpl import com.openai.services.async.admin.organization.UserServiceAsync @@ -46,6 +50,14 @@ class OrganizationServiceAsyncImpl internal constructor(private val clientOption private val roles: RoleServiceAsync by lazy { RoleServiceAsyncImpl(clientOptions) } + private val dataRetention: DataRetentionServiceAsync by lazy { + DataRetentionServiceAsyncImpl(clientOptions) + } + + private val spendAlerts: SpendAlertServiceAsync by lazy { + SpendAlertServiceAsyncImpl(clientOptions) + } + private val certificates: CertificateServiceAsync by lazy { CertificateServiceAsyncImpl(clientOptions) } @@ -72,6 +84,10 @@ class OrganizationServiceAsyncImpl internal constructor(private val clientOption override fun roles(): RoleServiceAsync = roles + override fun dataRetention(): DataRetentionServiceAsync = dataRetention + + override fun spendAlerts(): SpendAlertServiceAsync = spendAlerts + override fun certificates(): CertificateServiceAsync = certificates override fun projects(): ProjectServiceAsync = projects @@ -107,6 +123,14 @@ class OrganizationServiceAsyncImpl internal constructor(private val clientOption RoleServiceAsyncImpl.WithRawResponseImpl(clientOptions) } + private val dataRetention: DataRetentionServiceAsync.WithRawResponse by lazy { + DataRetentionServiceAsyncImpl.WithRawResponseImpl(clientOptions) + } + + private val spendAlerts: SpendAlertServiceAsync.WithRawResponse by lazy { + SpendAlertServiceAsyncImpl.WithRawResponseImpl(clientOptions) + } + private val certificates: CertificateServiceAsync.WithRawResponse by lazy { CertificateServiceAsyncImpl.WithRawResponseImpl(clientOptions) } @@ -137,6 +161,10 @@ class OrganizationServiceAsyncImpl internal constructor(private val clientOption override fun roles(): RoleServiceAsync.WithRawResponse = roles + override fun dataRetention(): DataRetentionServiceAsync.WithRawResponse = dataRetention + + override fun spendAlerts(): SpendAlertServiceAsync.WithRawResponse = spendAlerts + override fun certificates(): CertificateServiceAsync.WithRawResponse = certificates override fun projects(): ProjectServiceAsync.WithRawResponse = projects diff --git a/openai-java-core/src/main/kotlin/com/openai/services/async/admin/organization/DataRetentionServiceAsync.kt b/openai-java-core/src/main/kotlin/com/openai/services/async/admin/organization/DataRetentionServiceAsync.kt new file mode 100644 index 000000000..0ebd422f2 --- /dev/null +++ b/openai-java-core/src/main/kotlin/com/openai/services/async/admin/organization/DataRetentionServiceAsync.kt @@ -0,0 +1,112 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.services.async.admin.organization + +import com.openai.core.ClientOptions +import com.openai.core.RequestOptions +import com.openai.core.http.HttpResponseFor +import com.openai.models.admin.organization.dataretention.DataRetentionRetrieveParams +import com.openai.models.admin.organization.dataretention.DataRetentionUpdateParams +import com.openai.models.admin.organization.dataretention.OrganizationDataRetention +import java.util.concurrent.CompletableFuture +import java.util.function.Consumer + +interface DataRetentionServiceAsync { + + /** + * Returns a view of this service that provides access to raw HTTP responses for each method. + */ + fun withRawResponse(): WithRawResponse + + /** + * Returns a view of this service with the given option modifications applied. + * + * The original service is not modified. + */ + fun withOptions(modifier: Consumer): DataRetentionServiceAsync + + /** Retrieves organization data retention controls. */ + fun retrieve(): CompletableFuture = + retrieve(DataRetentionRetrieveParams.none()) + + /** @see retrieve */ + fun retrieve( + params: DataRetentionRetrieveParams = DataRetentionRetrieveParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture + + /** @see retrieve */ + fun retrieve( + params: DataRetentionRetrieveParams = DataRetentionRetrieveParams.none() + ): CompletableFuture = retrieve(params, RequestOptions.none()) + + /** @see retrieve */ + fun retrieve(requestOptions: RequestOptions): CompletableFuture = + retrieve(DataRetentionRetrieveParams.none(), requestOptions) + + /** Updates organization data retention controls. */ + fun update(params: DataRetentionUpdateParams): CompletableFuture = + update(params, RequestOptions.none()) + + /** @see update */ + fun update( + params: DataRetentionUpdateParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture + + /** + * A view of [DataRetentionServiceAsync] that provides access to raw HTTP responses for each + * method. + */ + interface WithRawResponse { + + /** + * Returns a view of this service with the given option modifications applied. + * + * The original service is not modified. + */ + fun withOptions( + modifier: Consumer + ): DataRetentionServiceAsync.WithRawResponse + + /** + * Returns a raw HTTP response for `get /organization/data_retention`, but is otherwise the + * same as [DataRetentionServiceAsync.retrieve]. + */ + fun retrieve(): CompletableFuture> = + retrieve(DataRetentionRetrieveParams.none()) + + /** @see retrieve */ + fun retrieve( + params: DataRetentionRetrieveParams = DataRetentionRetrieveParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture> + + /** @see retrieve */ + fun retrieve( + params: DataRetentionRetrieveParams = DataRetentionRetrieveParams.none() + ): CompletableFuture> = + retrieve(params, RequestOptions.none()) + + /** @see retrieve */ + fun retrieve( + requestOptions: RequestOptions + ): CompletableFuture> = + retrieve(DataRetentionRetrieveParams.none(), requestOptions) + + /** + * Returns a raw HTTP response for `post /organization/data_retention`, but is otherwise the + * same as [DataRetentionServiceAsync.update]. + */ + fun update( + params: DataRetentionUpdateParams + ): CompletableFuture> = + update(params, RequestOptions.none()) + + /** @see update */ + fun update( + params: DataRetentionUpdateParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture> + } +} diff --git a/openai-java-core/src/main/kotlin/com/openai/services/async/admin/organization/DataRetentionServiceAsyncImpl.kt b/openai-java-core/src/main/kotlin/com/openai/services/async/admin/organization/DataRetentionServiceAsyncImpl.kt new file mode 100644 index 000000000..2dd958822 --- /dev/null +++ b/openai-java-core/src/main/kotlin/com/openai/services/async/admin/organization/DataRetentionServiceAsyncImpl.kt @@ -0,0 +1,133 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.services.async.admin.organization + +import com.openai.core.ClientOptions +import com.openai.core.RequestOptions +import com.openai.core.SecurityOptions +import com.openai.core.handlers.errorBodyHandler +import com.openai.core.handlers.errorHandler +import com.openai.core.handlers.jsonHandler +import com.openai.core.http.HttpMethod +import com.openai.core.http.HttpRequest +import com.openai.core.http.HttpResponse +import com.openai.core.http.HttpResponse.Handler +import com.openai.core.http.HttpResponseFor +import com.openai.core.http.json +import com.openai.core.http.parseable +import com.openai.core.prepareAsync +import com.openai.models.admin.organization.dataretention.DataRetentionRetrieveParams +import com.openai.models.admin.organization.dataretention.DataRetentionUpdateParams +import com.openai.models.admin.organization.dataretention.OrganizationDataRetention +import java.util.concurrent.CompletableFuture +import java.util.function.Consumer + +class DataRetentionServiceAsyncImpl internal constructor(private val clientOptions: ClientOptions) : + DataRetentionServiceAsync { + + private val withRawResponse: DataRetentionServiceAsync.WithRawResponse by lazy { + WithRawResponseImpl(clientOptions) + } + + override fun withRawResponse(): DataRetentionServiceAsync.WithRawResponse = withRawResponse + + override fun withOptions(modifier: Consumer): DataRetentionServiceAsync = + DataRetentionServiceAsyncImpl(clientOptions.toBuilder().apply(modifier::accept).build()) + + override fun retrieve( + params: DataRetentionRetrieveParams, + requestOptions: RequestOptions, + ): CompletableFuture = + // get /organization/data_retention + withRawResponse().retrieve(params, requestOptions).thenApply { it.parse() } + + override fun update( + params: DataRetentionUpdateParams, + requestOptions: RequestOptions, + ): CompletableFuture = + // post /organization/data_retention + withRawResponse().update(params, requestOptions).thenApply { it.parse() } + + class WithRawResponseImpl internal constructor(private val clientOptions: ClientOptions) : + DataRetentionServiceAsync.WithRawResponse { + + private val errorHandler: Handler = + errorHandler(errorBodyHandler(clientOptions.jsonMapper)) + + override fun withOptions( + modifier: Consumer + ): DataRetentionServiceAsync.WithRawResponse = + DataRetentionServiceAsyncImpl.WithRawResponseImpl( + clientOptions.toBuilder().apply(modifier::accept).build() + ) + + private val retrieveHandler: Handler = + jsonHandler(clientOptions.jsonMapper) + + override fun retrieve( + params: DataRetentionRetrieveParams, + requestOptions: RequestOptions, + ): CompletableFuture> { + val request = + HttpRequest.builder() + .method(HttpMethod.GET) + .baseUrl(clientOptions.baseUrl()) + .addPathSegments("organization", "data_retention") + .build() + .prepareAsync( + clientOptions, + params, + SecurityOptions.builder().adminApiKeyAuth(true).build(), + ) + val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) + return request + .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } + .thenApply { response -> + errorHandler.handle(response).parseable { + response + .use { retrieveHandler.handle(it) } + .also { + if (requestOptions.responseValidation!!) { + it.validate() + } + } + } + } + } + + private val updateHandler: Handler = + jsonHandler(clientOptions.jsonMapper) + + override fun update( + params: DataRetentionUpdateParams, + requestOptions: RequestOptions, + ): CompletableFuture> { + val request = + HttpRequest.builder() + .method(HttpMethod.POST) + .baseUrl(clientOptions.baseUrl()) + .addPathSegments("organization", "data_retention") + .body(json(clientOptions.jsonMapper, params._body())) + .build() + .prepareAsync( + clientOptions, + params, + SecurityOptions.builder().adminApiKeyAuth(true).build(), + ) + val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) + return request + .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } + .thenApply { response -> + errorHandler.handle(response).parseable { + response + .use { updateHandler.handle(it) } + .also { + if (requestOptions.responseValidation!!) { + it.validate() + } + } + } + } + } + } +} diff --git a/openai-java-core/src/main/kotlin/com/openai/services/async/admin/organization/GroupServiceAsync.kt b/openai-java-core/src/main/kotlin/com/openai/services/async/admin/organization/GroupServiceAsync.kt index ee5e6bfe4..ef7c31ba1 100644 --- a/openai-java-core/src/main/kotlin/com/openai/services/async/admin/organization/GroupServiceAsync.kt +++ b/openai-java-core/src/main/kotlin/com/openai/services/async/admin/organization/GroupServiceAsync.kt @@ -11,6 +11,7 @@ import com.openai.models.admin.organization.groups.GroupDeleteParams import com.openai.models.admin.organization.groups.GroupDeleteResponse import com.openai.models.admin.organization.groups.GroupListPageAsync import com.openai.models.admin.organization.groups.GroupListParams +import com.openai.models.admin.organization.groups.GroupRetrieveParams import com.openai.models.admin.organization.groups.GroupUpdateParams import com.openai.models.admin.organization.groups.GroupUpdateResponse import com.openai.services.async.admin.organization.groups.RoleServiceAsync @@ -46,6 +47,38 @@ interface GroupServiceAsync { requestOptions: RequestOptions = RequestOptions.none(), ): CompletableFuture + /** Retrieves a group. */ + fun retrieve(groupId: String): CompletableFuture = + retrieve(groupId, GroupRetrieveParams.none()) + + /** @see retrieve */ + fun retrieve( + groupId: String, + params: GroupRetrieveParams = GroupRetrieveParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture = + retrieve(params.toBuilder().groupId(groupId).build(), requestOptions) + + /** @see retrieve */ + fun retrieve( + groupId: String, + params: GroupRetrieveParams = GroupRetrieveParams.none(), + ): CompletableFuture = retrieve(groupId, params, RequestOptions.none()) + + /** @see retrieve */ + fun retrieve( + params: GroupRetrieveParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture + + /** @see retrieve */ + fun retrieve(params: GroupRetrieveParams): CompletableFuture = + retrieve(params, RequestOptions.none()) + + /** @see retrieve */ + fun retrieve(groupId: String, requestOptions: RequestOptions): CompletableFuture = + retrieve(groupId, GroupRetrieveParams.none(), requestOptions) + /** Updates a group's information. */ fun update(groupId: String, params: GroupUpdateParams): CompletableFuture = update(groupId, params, RequestOptions.none()) @@ -150,6 +183,45 @@ interface GroupServiceAsync { requestOptions: RequestOptions = RequestOptions.none(), ): CompletableFuture> + /** + * Returns a raw HTTP response for `get /organization/groups/{group_id}`, but is otherwise + * the same as [GroupServiceAsync.retrieve]. + */ + fun retrieve(groupId: String): CompletableFuture> = + retrieve(groupId, GroupRetrieveParams.none()) + + /** @see retrieve */ + fun retrieve( + groupId: String, + params: GroupRetrieveParams = GroupRetrieveParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture> = + retrieve(params.toBuilder().groupId(groupId).build(), requestOptions) + + /** @see retrieve */ + fun retrieve( + groupId: String, + params: GroupRetrieveParams = GroupRetrieveParams.none(), + ): CompletableFuture> = + retrieve(groupId, params, RequestOptions.none()) + + /** @see retrieve */ + fun retrieve( + params: GroupRetrieveParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture> + + /** @see retrieve */ + fun retrieve(params: GroupRetrieveParams): CompletableFuture> = + retrieve(params, RequestOptions.none()) + + /** @see retrieve */ + fun retrieve( + groupId: String, + requestOptions: RequestOptions, + ): CompletableFuture> = + retrieve(groupId, GroupRetrieveParams.none(), requestOptions) + /** * Returns a raw HTTP response for `post /organization/groups/{group_id}`, but is otherwise * the same as [GroupServiceAsync.update]. diff --git a/openai-java-core/src/main/kotlin/com/openai/services/async/admin/organization/GroupServiceAsyncImpl.kt b/openai-java-core/src/main/kotlin/com/openai/services/async/admin/organization/GroupServiceAsyncImpl.kt index ad472d75d..898f2d721 100644 --- a/openai-java-core/src/main/kotlin/com/openai/services/async/admin/organization/GroupServiceAsyncImpl.kt +++ b/openai-java-core/src/main/kotlin/com/openai/services/async/admin/organization/GroupServiceAsyncImpl.kt @@ -24,6 +24,7 @@ import com.openai.models.admin.organization.groups.GroupDeleteResponse import com.openai.models.admin.organization.groups.GroupListPageAsync import com.openai.models.admin.organization.groups.GroupListPageResponse import com.openai.models.admin.organization.groups.GroupListParams +import com.openai.models.admin.organization.groups.GroupRetrieveParams import com.openai.models.admin.organization.groups.GroupUpdateParams import com.openai.models.admin.organization.groups.GroupUpdateResponse import com.openai.services.async.admin.organization.groups.RoleServiceAsync @@ -61,6 +62,13 @@ class GroupServiceAsyncImpl internal constructor(private val clientOptions: Clie // post /organization/groups withRawResponse().create(params, requestOptions).thenApply { it.parse() } + override fun retrieve( + params: GroupRetrieveParams, + requestOptions: RequestOptions, + ): CompletableFuture = + // get /organization/groups/{group_id} + withRawResponse().retrieve(params, requestOptions).thenApply { it.parse() } + override fun update( params: GroupUpdateParams, requestOptions: RequestOptions, @@ -141,6 +149,42 @@ class GroupServiceAsyncImpl internal constructor(private val clientOptions: Clie } } + private val retrieveHandler: Handler = jsonHandler(clientOptions.jsonMapper) + + override fun retrieve( + params: GroupRetrieveParams, + requestOptions: RequestOptions, + ): CompletableFuture> { + // We check here instead of in the params builder because this can be specified + // positionally or in the params class. + checkRequired("groupId", params.groupId().getOrNull()) + val request = + HttpRequest.builder() + .method(HttpMethod.GET) + .baseUrl(clientOptions.baseUrl()) + .addPathSegments("organization", "groups", params._pathParam(0)) + .build() + .prepareAsync( + clientOptions, + params, + SecurityOptions.builder().adminApiKeyAuth(true).build(), + ) + val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) + return request + .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } + .thenApply { response -> + errorHandler.handle(response).parseable { + response + .use { retrieveHandler.handle(it) } + .also { + if (requestOptions.responseValidation!!) { + it.validate() + } + } + } + } + } + private val updateHandler: Handler = jsonHandler(clientOptions.jsonMapper) diff --git a/openai-java-core/src/main/kotlin/com/openai/services/async/admin/organization/ProjectServiceAsync.kt b/openai-java-core/src/main/kotlin/com/openai/services/async/admin/organization/ProjectServiceAsync.kt index d8b62335d..e6f331830 100644 --- a/openai-java-core/src/main/kotlin/com/openai/services/async/admin/organization/ProjectServiceAsync.kt +++ b/openai-java-core/src/main/kotlin/com/openai/services/async/admin/organization/ProjectServiceAsync.kt @@ -14,12 +14,14 @@ import com.openai.models.admin.organization.projects.ProjectRetrieveParams import com.openai.models.admin.organization.projects.ProjectUpdateParams import com.openai.services.async.admin.organization.projects.ApiKeyServiceAsync import com.openai.services.async.admin.organization.projects.CertificateServiceAsync +import com.openai.services.async.admin.organization.projects.DataRetentionServiceAsync import com.openai.services.async.admin.organization.projects.GroupServiceAsync import com.openai.services.async.admin.organization.projects.HostedToolPermissionServiceAsync import com.openai.services.async.admin.organization.projects.ModelPermissionServiceAsync import com.openai.services.async.admin.organization.projects.RateLimitServiceAsync import com.openai.services.async.admin.organization.projects.RoleServiceAsync import com.openai.services.async.admin.organization.projects.ServiceAccountServiceAsync +import com.openai.services.async.admin.organization.projects.SpendAlertServiceAsync import com.openai.services.async.admin.organization.projects.UserServiceAsync import java.util.concurrent.CompletableFuture import java.util.function.Consumer @@ -54,6 +56,10 @@ interface ProjectServiceAsync { fun roles(): RoleServiceAsync + fun dataRetention(): DataRetentionServiceAsync + + fun spendAlerts(): SpendAlertServiceAsync + fun certificates(): CertificateServiceAsync /** @@ -213,6 +219,10 @@ interface ProjectServiceAsync { fun roles(): RoleServiceAsync.WithRawResponse + fun dataRetention(): DataRetentionServiceAsync.WithRawResponse + + fun spendAlerts(): SpendAlertServiceAsync.WithRawResponse + fun certificates(): CertificateServiceAsync.WithRawResponse /** diff --git a/openai-java-core/src/main/kotlin/com/openai/services/async/admin/organization/ProjectServiceAsyncImpl.kt b/openai-java-core/src/main/kotlin/com/openai/services/async/admin/organization/ProjectServiceAsyncImpl.kt index b26eb0faa..726da5a8a 100644 --- a/openai-java-core/src/main/kotlin/com/openai/services/async/admin/organization/ProjectServiceAsyncImpl.kt +++ b/openai-java-core/src/main/kotlin/com/openai/services/async/admin/organization/ProjectServiceAsyncImpl.kt @@ -29,6 +29,8 @@ import com.openai.services.async.admin.organization.projects.ApiKeyServiceAsync import com.openai.services.async.admin.organization.projects.ApiKeyServiceAsyncImpl import com.openai.services.async.admin.organization.projects.CertificateServiceAsync import com.openai.services.async.admin.organization.projects.CertificateServiceAsyncImpl +import com.openai.services.async.admin.organization.projects.DataRetentionServiceAsync +import com.openai.services.async.admin.organization.projects.DataRetentionServiceAsyncImpl import com.openai.services.async.admin.organization.projects.GroupServiceAsync import com.openai.services.async.admin.organization.projects.GroupServiceAsyncImpl import com.openai.services.async.admin.organization.projects.HostedToolPermissionServiceAsync @@ -41,6 +43,8 @@ import com.openai.services.async.admin.organization.projects.RoleServiceAsync import com.openai.services.async.admin.organization.projects.RoleServiceAsyncImpl import com.openai.services.async.admin.organization.projects.ServiceAccountServiceAsync import com.openai.services.async.admin.organization.projects.ServiceAccountServiceAsyncImpl +import com.openai.services.async.admin.organization.projects.SpendAlertServiceAsync +import com.openai.services.async.admin.organization.projects.SpendAlertServiceAsyncImpl import com.openai.services.async.admin.organization.projects.UserServiceAsync import com.openai.services.async.admin.organization.projects.UserServiceAsyncImpl import java.util.concurrent.CompletableFuture @@ -78,6 +82,14 @@ class ProjectServiceAsyncImpl internal constructor(private val clientOptions: Cl private val roles: RoleServiceAsync by lazy { RoleServiceAsyncImpl(clientOptions) } + private val dataRetention: DataRetentionServiceAsync by lazy { + DataRetentionServiceAsyncImpl(clientOptions) + } + + private val spendAlerts: SpendAlertServiceAsync by lazy { + SpendAlertServiceAsyncImpl(clientOptions) + } + private val certificates: CertificateServiceAsync by lazy { CertificateServiceAsyncImpl(clientOptions) } @@ -103,6 +115,10 @@ class ProjectServiceAsyncImpl internal constructor(private val clientOptions: Cl override fun roles(): RoleServiceAsync = roles + override fun dataRetention(): DataRetentionServiceAsync = dataRetention + + override fun spendAlerts(): SpendAlertServiceAsync = spendAlerts + override fun certificates(): CertificateServiceAsync = certificates override fun create( @@ -179,6 +195,14 @@ class ProjectServiceAsyncImpl internal constructor(private val clientOptions: Cl RoleServiceAsyncImpl.WithRawResponseImpl(clientOptions) } + private val dataRetention: DataRetentionServiceAsync.WithRawResponse by lazy { + DataRetentionServiceAsyncImpl.WithRawResponseImpl(clientOptions) + } + + private val spendAlerts: SpendAlertServiceAsync.WithRawResponse by lazy { + SpendAlertServiceAsyncImpl.WithRawResponseImpl(clientOptions) + } + private val certificates: CertificateServiceAsync.WithRawResponse by lazy { CertificateServiceAsyncImpl.WithRawResponseImpl(clientOptions) } @@ -208,6 +232,10 @@ class ProjectServiceAsyncImpl internal constructor(private val clientOptions: Cl override fun roles(): RoleServiceAsync.WithRawResponse = roles + override fun dataRetention(): DataRetentionServiceAsync.WithRawResponse = dataRetention + + override fun spendAlerts(): SpendAlertServiceAsync.WithRawResponse = spendAlerts + override fun certificates(): CertificateServiceAsync.WithRawResponse = certificates private val createHandler: Handler = jsonHandler(clientOptions.jsonMapper) diff --git a/openai-java-core/src/main/kotlin/com/openai/services/async/admin/organization/RoleServiceAsync.kt b/openai-java-core/src/main/kotlin/com/openai/services/async/admin/organization/RoleServiceAsync.kt index 0a0acdee9..06177ed9e 100644 --- a/openai-java-core/src/main/kotlin/com/openai/services/async/admin/organization/RoleServiceAsync.kt +++ b/openai-java-core/src/main/kotlin/com/openai/services/async/admin/organization/RoleServiceAsync.kt @@ -11,6 +11,7 @@ import com.openai.models.admin.organization.roles.RoleDeleteParams import com.openai.models.admin.organization.roles.RoleDeleteResponse import com.openai.models.admin.organization.roles.RoleListPageAsync import com.openai.models.admin.organization.roles.RoleListParams +import com.openai.models.admin.organization.roles.RoleRetrieveParams import com.openai.models.admin.organization.roles.RoleUpdateParams import java.util.concurrent.CompletableFuture import java.util.function.Consumer @@ -39,6 +40,37 @@ interface RoleServiceAsync { requestOptions: RequestOptions = RequestOptions.none(), ): CompletableFuture + /** Retrieves an organization role. */ + fun retrieve(roleId: String): CompletableFuture = + retrieve(roleId, RoleRetrieveParams.none()) + + /** @see retrieve */ + fun retrieve( + roleId: String, + params: RoleRetrieveParams = RoleRetrieveParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture = retrieve(params.toBuilder().roleId(roleId).build(), requestOptions) + + /** @see retrieve */ + fun retrieve( + roleId: String, + params: RoleRetrieveParams = RoleRetrieveParams.none(), + ): CompletableFuture = retrieve(roleId, params, RequestOptions.none()) + + /** @see retrieve */ + fun retrieve( + params: RoleRetrieveParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture + + /** @see retrieve */ + fun retrieve(params: RoleRetrieveParams): CompletableFuture = + retrieve(params, RequestOptions.none()) + + /** @see retrieve */ + fun retrieve(roleId: String, requestOptions: RequestOptions): CompletableFuture = + retrieve(roleId, RoleRetrieveParams.none(), requestOptions) + /** Updates an existing organization role. */ fun update(roleId: String): CompletableFuture = update(roleId, RoleUpdateParams.none()) @@ -144,6 +176,45 @@ interface RoleServiceAsync { requestOptions: RequestOptions = RequestOptions.none(), ): CompletableFuture> + /** + * Returns a raw HTTP response for `get /organization/roles/{role_id}`, but is otherwise the + * same as [RoleServiceAsync.retrieve]. + */ + fun retrieve(roleId: String): CompletableFuture> = + retrieve(roleId, RoleRetrieveParams.none()) + + /** @see retrieve */ + fun retrieve( + roleId: String, + params: RoleRetrieveParams = RoleRetrieveParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture> = + retrieve(params.toBuilder().roleId(roleId).build(), requestOptions) + + /** @see retrieve */ + fun retrieve( + roleId: String, + params: RoleRetrieveParams = RoleRetrieveParams.none(), + ): CompletableFuture> = + retrieve(roleId, params, RequestOptions.none()) + + /** @see retrieve */ + fun retrieve( + params: RoleRetrieveParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture> + + /** @see retrieve */ + fun retrieve(params: RoleRetrieveParams): CompletableFuture> = + retrieve(params, RequestOptions.none()) + + /** @see retrieve */ + fun retrieve( + roleId: String, + requestOptions: RequestOptions, + ): CompletableFuture> = + retrieve(roleId, RoleRetrieveParams.none(), requestOptions) + /** * Returns a raw HTTP response for `post /organization/roles/{role_id}`, but is otherwise * the same as [RoleServiceAsync.update]. diff --git a/openai-java-core/src/main/kotlin/com/openai/services/async/admin/organization/RoleServiceAsyncImpl.kt b/openai-java-core/src/main/kotlin/com/openai/services/async/admin/organization/RoleServiceAsyncImpl.kt index 19d07b020..0baa8ae60 100644 --- a/openai-java-core/src/main/kotlin/com/openai/services/async/admin/organization/RoleServiceAsyncImpl.kt +++ b/openai-java-core/src/main/kotlin/com/openai/services/async/admin/organization/RoleServiceAsyncImpl.kt @@ -24,6 +24,7 @@ import com.openai.models.admin.organization.roles.RoleDeleteResponse import com.openai.models.admin.organization.roles.RoleListPageAsync import com.openai.models.admin.organization.roles.RoleListPageResponse import com.openai.models.admin.organization.roles.RoleListParams +import com.openai.models.admin.organization.roles.RoleRetrieveParams import com.openai.models.admin.organization.roles.RoleUpdateParams import java.util.concurrent.CompletableFuture import java.util.function.Consumer @@ -48,6 +49,13 @@ class RoleServiceAsyncImpl internal constructor(private val clientOptions: Clien // post /organization/roles withRawResponse().create(params, requestOptions).thenApply { it.parse() } + override fun retrieve( + params: RoleRetrieveParams, + requestOptions: RequestOptions, + ): CompletableFuture = + // get /organization/roles/{role_id} + withRawResponse().retrieve(params, requestOptions).thenApply { it.parse() } + override fun update( params: RoleUpdateParams, requestOptions: RequestOptions, @@ -116,6 +124,42 @@ class RoleServiceAsyncImpl internal constructor(private val clientOptions: Clien } } + private val retrieveHandler: Handler = jsonHandler(clientOptions.jsonMapper) + + override fun retrieve( + params: RoleRetrieveParams, + requestOptions: RequestOptions, + ): CompletableFuture> { + // We check here instead of in the params builder because this can be specified + // positionally or in the params class. + checkRequired("roleId", params.roleId().getOrNull()) + val request = + HttpRequest.builder() + .method(HttpMethod.GET) + .baseUrl(clientOptions.baseUrl()) + .addPathSegments("organization", "roles", params._pathParam(0)) + .build() + .prepareAsync( + clientOptions, + params, + SecurityOptions.builder().adminApiKeyAuth(true).build(), + ) + val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) + return request + .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } + .thenApply { response -> + errorHandler.handle(response).parseable { + response + .use { retrieveHandler.handle(it) } + .also { + if (requestOptions.responseValidation!!) { + it.validate() + } + } + } + } + } + private val updateHandler: Handler = jsonHandler(clientOptions.jsonMapper) override fun update( diff --git a/openai-java-core/src/main/kotlin/com/openai/services/async/admin/organization/SpendAlertServiceAsync.kt b/openai-java-core/src/main/kotlin/com/openai/services/async/admin/organization/SpendAlertServiceAsync.kt new file mode 100644 index 000000000..ff416b2d2 --- /dev/null +++ b/openai-java-core/src/main/kotlin/com/openai/services/async/admin/organization/SpendAlertServiceAsync.kt @@ -0,0 +1,248 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.services.async.admin.organization + +import com.openai.core.ClientOptions +import com.openai.core.RequestOptions +import com.openai.core.http.HttpResponseFor +import com.openai.models.admin.organization.spendalerts.OrganizationSpendAlert +import com.openai.models.admin.organization.spendalerts.OrganizationSpendAlertDeleted +import com.openai.models.admin.organization.spendalerts.SpendAlertCreateParams +import com.openai.models.admin.organization.spendalerts.SpendAlertDeleteParams +import com.openai.models.admin.organization.spendalerts.SpendAlertListPageAsync +import com.openai.models.admin.organization.spendalerts.SpendAlertListParams +import com.openai.models.admin.organization.spendalerts.SpendAlertUpdateParams +import java.util.concurrent.CompletableFuture +import java.util.function.Consumer + +interface SpendAlertServiceAsync { + + /** + * Returns a view of this service that provides access to raw HTTP responses for each method. + */ + fun withRawResponse(): WithRawResponse + + /** + * Returns a view of this service with the given option modifications applied. + * + * The original service is not modified. + */ + fun withOptions(modifier: Consumer): SpendAlertServiceAsync + + /** Creates an organization spend alert. */ + fun create(params: SpendAlertCreateParams): CompletableFuture = + create(params, RequestOptions.none()) + + /** @see create */ + fun create( + params: SpendAlertCreateParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture + + /** Updates an organization spend alert. */ + fun update( + alertId: String, + params: SpendAlertUpdateParams, + ): CompletableFuture = update(alertId, params, RequestOptions.none()) + + /** @see update */ + fun update( + alertId: String, + params: SpendAlertUpdateParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture = + update(params.toBuilder().alertId(alertId).build(), requestOptions) + + /** @see update */ + fun update(params: SpendAlertUpdateParams): CompletableFuture = + update(params, RequestOptions.none()) + + /** @see update */ + fun update( + params: SpendAlertUpdateParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture + + /** Lists organization spend alerts. */ + fun list(): CompletableFuture = list(SpendAlertListParams.none()) + + /** @see list */ + fun list( + params: SpendAlertListParams = SpendAlertListParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture + + /** @see list */ + fun list( + params: SpendAlertListParams = SpendAlertListParams.none() + ): CompletableFuture = list(params, RequestOptions.none()) + + /** @see list */ + fun list(requestOptions: RequestOptions): CompletableFuture = + list(SpendAlertListParams.none(), requestOptions) + + /** Deletes an organization spend alert. */ + fun delete(alertId: String): CompletableFuture = + delete(alertId, SpendAlertDeleteParams.none()) + + /** @see delete */ + fun delete( + alertId: String, + params: SpendAlertDeleteParams = SpendAlertDeleteParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture = + delete(params.toBuilder().alertId(alertId).build(), requestOptions) + + /** @see delete */ + fun delete( + alertId: String, + params: SpendAlertDeleteParams = SpendAlertDeleteParams.none(), + ): CompletableFuture = + delete(alertId, params, RequestOptions.none()) + + /** @see delete */ + fun delete( + params: SpendAlertDeleteParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture + + /** @see delete */ + fun delete(params: SpendAlertDeleteParams): CompletableFuture = + delete(params, RequestOptions.none()) + + /** @see delete */ + fun delete( + alertId: String, + requestOptions: RequestOptions, + ): CompletableFuture = + delete(alertId, SpendAlertDeleteParams.none(), requestOptions) + + /** + * A view of [SpendAlertServiceAsync] that provides access to raw HTTP responses for each + * method. + */ + interface WithRawResponse { + + /** + * Returns a view of this service with the given option modifications applied. + * + * The original service is not modified. + */ + fun withOptions( + modifier: Consumer + ): SpendAlertServiceAsync.WithRawResponse + + /** + * Returns a raw HTTP response for `post /organization/spend_alerts`, but is otherwise the + * same as [SpendAlertServiceAsync.create]. + */ + fun create( + params: SpendAlertCreateParams + ): CompletableFuture> = + create(params, RequestOptions.none()) + + /** @see create */ + fun create( + params: SpendAlertCreateParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture> + + /** + * Returns a raw HTTP response for `post /organization/spend_alerts/{alert_id}`, but is + * otherwise the same as [SpendAlertServiceAsync.update]. + */ + fun update( + alertId: String, + params: SpendAlertUpdateParams, + ): CompletableFuture> = + update(alertId, params, RequestOptions.none()) + + /** @see update */ + fun update( + alertId: String, + params: SpendAlertUpdateParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture> = + update(params.toBuilder().alertId(alertId).build(), requestOptions) + + /** @see update */ + fun update( + params: SpendAlertUpdateParams + ): CompletableFuture> = + update(params, RequestOptions.none()) + + /** @see update */ + fun update( + params: SpendAlertUpdateParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture> + + /** + * Returns a raw HTTP response for `get /organization/spend_alerts`, but is otherwise the + * same as [SpendAlertServiceAsync.list]. + */ + fun list(): CompletableFuture> = + list(SpendAlertListParams.none()) + + /** @see list */ + fun list( + params: SpendAlertListParams = SpendAlertListParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture> + + /** @see list */ + fun list( + params: SpendAlertListParams = SpendAlertListParams.none() + ): CompletableFuture> = + list(params, RequestOptions.none()) + + /** @see list */ + fun list( + requestOptions: RequestOptions + ): CompletableFuture> = + list(SpendAlertListParams.none(), requestOptions) + + /** + * Returns a raw HTTP response for `delete /organization/spend_alerts/{alert_id}`, but is + * otherwise the same as [SpendAlertServiceAsync.delete]. + */ + fun delete( + alertId: String + ): CompletableFuture> = + delete(alertId, SpendAlertDeleteParams.none()) + + /** @see delete */ + fun delete( + alertId: String, + params: SpendAlertDeleteParams = SpendAlertDeleteParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture> = + delete(params.toBuilder().alertId(alertId).build(), requestOptions) + + /** @see delete */ + fun delete( + alertId: String, + params: SpendAlertDeleteParams = SpendAlertDeleteParams.none(), + ): CompletableFuture> = + delete(alertId, params, RequestOptions.none()) + + /** @see delete */ + fun delete( + params: SpendAlertDeleteParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture> + + /** @see delete */ + fun delete( + params: SpendAlertDeleteParams + ): CompletableFuture> = + delete(params, RequestOptions.none()) + + /** @see delete */ + fun delete( + alertId: String, + requestOptions: RequestOptions, + ): CompletableFuture> = + delete(alertId, SpendAlertDeleteParams.none(), requestOptions) + } +} diff --git a/openai-java-core/src/main/kotlin/com/openai/services/async/admin/organization/SpendAlertServiceAsyncImpl.kt b/openai-java-core/src/main/kotlin/com/openai/services/async/admin/organization/SpendAlertServiceAsyncImpl.kt new file mode 100644 index 000000000..3e811c34b --- /dev/null +++ b/openai-java-core/src/main/kotlin/com/openai/services/async/admin/organization/SpendAlertServiceAsyncImpl.kt @@ -0,0 +1,238 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.services.async.admin.organization + +import com.openai.core.ClientOptions +import com.openai.core.RequestOptions +import com.openai.core.SecurityOptions +import com.openai.core.checkRequired +import com.openai.core.handlers.errorBodyHandler +import com.openai.core.handlers.errorHandler +import com.openai.core.handlers.jsonHandler +import com.openai.core.http.HttpMethod +import com.openai.core.http.HttpRequest +import com.openai.core.http.HttpResponse +import com.openai.core.http.HttpResponse.Handler +import com.openai.core.http.HttpResponseFor +import com.openai.core.http.json +import com.openai.core.http.parseable +import com.openai.core.prepareAsync +import com.openai.models.admin.organization.spendalerts.OrganizationSpendAlert +import com.openai.models.admin.organization.spendalerts.OrganizationSpendAlertDeleted +import com.openai.models.admin.organization.spendalerts.SpendAlertCreateParams +import com.openai.models.admin.organization.spendalerts.SpendAlertDeleteParams +import com.openai.models.admin.organization.spendalerts.SpendAlertListPageAsync +import com.openai.models.admin.organization.spendalerts.SpendAlertListPageResponse +import com.openai.models.admin.organization.spendalerts.SpendAlertListParams +import com.openai.models.admin.organization.spendalerts.SpendAlertUpdateParams +import java.util.concurrent.CompletableFuture +import java.util.function.Consumer +import kotlin.jvm.optionals.getOrNull + +class SpendAlertServiceAsyncImpl internal constructor(private val clientOptions: ClientOptions) : + SpendAlertServiceAsync { + + private val withRawResponse: SpendAlertServiceAsync.WithRawResponse by lazy { + WithRawResponseImpl(clientOptions) + } + + override fun withRawResponse(): SpendAlertServiceAsync.WithRawResponse = withRawResponse + + override fun withOptions(modifier: Consumer): SpendAlertServiceAsync = + SpendAlertServiceAsyncImpl(clientOptions.toBuilder().apply(modifier::accept).build()) + + override fun create( + params: SpendAlertCreateParams, + requestOptions: RequestOptions, + ): CompletableFuture = + // post /organization/spend_alerts + withRawResponse().create(params, requestOptions).thenApply { it.parse() } + + override fun update( + params: SpendAlertUpdateParams, + requestOptions: RequestOptions, + ): CompletableFuture = + // post /organization/spend_alerts/{alert_id} + withRawResponse().update(params, requestOptions).thenApply { it.parse() } + + override fun list( + params: SpendAlertListParams, + requestOptions: RequestOptions, + ): CompletableFuture = + // get /organization/spend_alerts + withRawResponse().list(params, requestOptions).thenApply { it.parse() } + + override fun delete( + params: SpendAlertDeleteParams, + requestOptions: RequestOptions, + ): CompletableFuture = + // delete /organization/spend_alerts/{alert_id} + withRawResponse().delete(params, requestOptions).thenApply { it.parse() } + + class WithRawResponseImpl internal constructor(private val clientOptions: ClientOptions) : + SpendAlertServiceAsync.WithRawResponse { + + private val errorHandler: Handler = + errorHandler(errorBodyHandler(clientOptions.jsonMapper)) + + override fun withOptions( + modifier: Consumer + ): SpendAlertServiceAsync.WithRawResponse = + SpendAlertServiceAsyncImpl.WithRawResponseImpl( + clientOptions.toBuilder().apply(modifier::accept).build() + ) + + private val createHandler: Handler = + jsonHandler(clientOptions.jsonMapper) + + override fun create( + params: SpendAlertCreateParams, + requestOptions: RequestOptions, + ): CompletableFuture> { + val request = + HttpRequest.builder() + .method(HttpMethod.POST) + .baseUrl(clientOptions.baseUrl()) + .addPathSegments("organization", "spend_alerts") + .body(json(clientOptions.jsonMapper, params._body())) + .build() + .prepareAsync( + clientOptions, + params, + SecurityOptions.builder().adminApiKeyAuth(true).build(), + ) + val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) + return request + .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } + .thenApply { response -> + errorHandler.handle(response).parseable { + response + .use { createHandler.handle(it) } + .also { + if (requestOptions.responseValidation!!) { + it.validate() + } + } + } + } + } + + private val updateHandler: Handler = + jsonHandler(clientOptions.jsonMapper) + + override fun update( + params: SpendAlertUpdateParams, + requestOptions: RequestOptions, + ): CompletableFuture> { + // We check here instead of in the params builder because this can be specified + // positionally or in the params class. + checkRequired("alertId", params.alertId().getOrNull()) + val request = + HttpRequest.builder() + .method(HttpMethod.POST) + .baseUrl(clientOptions.baseUrl()) + .addPathSegments("organization", "spend_alerts", params._pathParam(0)) + .body(json(clientOptions.jsonMapper, params._body())) + .build() + .prepareAsync( + clientOptions, + params, + SecurityOptions.builder().adminApiKeyAuth(true).build(), + ) + val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) + return request + .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } + .thenApply { response -> + errorHandler.handle(response).parseable { + response + .use { updateHandler.handle(it) } + .also { + if (requestOptions.responseValidation!!) { + it.validate() + } + } + } + } + } + + private val listHandler: Handler = + jsonHandler(clientOptions.jsonMapper) + + override fun list( + params: SpendAlertListParams, + requestOptions: RequestOptions, + ): CompletableFuture> { + val request = + HttpRequest.builder() + .method(HttpMethod.GET) + .baseUrl(clientOptions.baseUrl()) + .addPathSegments("organization", "spend_alerts") + .build() + .prepareAsync( + clientOptions, + params, + SecurityOptions.builder().adminApiKeyAuth(true).build(), + ) + val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) + return request + .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } + .thenApply { response -> + errorHandler.handle(response).parseable { + response + .use { listHandler.handle(it) } + .also { + if (requestOptions.responseValidation!!) { + it.validate() + } + } + .let { + SpendAlertListPageAsync.builder() + .service(SpendAlertServiceAsyncImpl(clientOptions)) + .streamHandlerExecutor(clientOptions.streamHandlerExecutor) + .params(params) + .response(it) + .build() + } + } + } + } + + private val deleteHandler: Handler = + jsonHandler(clientOptions.jsonMapper) + + override fun delete( + params: SpendAlertDeleteParams, + requestOptions: RequestOptions, + ): CompletableFuture> { + // We check here instead of in the params builder because this can be specified + // positionally or in the params class. + checkRequired("alertId", params.alertId().getOrNull()) + val request = + HttpRequest.builder() + .method(HttpMethod.DELETE) + .baseUrl(clientOptions.baseUrl()) + .addPathSegments("organization", "spend_alerts", params._pathParam(0)) + .apply { params._body().ifPresent { body(json(clientOptions.jsonMapper, it)) } } + .build() + .prepareAsync( + clientOptions, + params, + SecurityOptions.builder().adminApiKeyAuth(true).build(), + ) + val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) + return request + .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } + .thenApply { response -> + errorHandler.handle(response).parseable { + response + .use { deleteHandler.handle(it) } + .also { + if (requestOptions.responseValidation!!) { + it.validate() + } + } + } + } + } + } +} diff --git a/openai-java-core/src/main/kotlin/com/openai/services/async/admin/organization/groups/RoleServiceAsync.kt b/openai-java-core/src/main/kotlin/com/openai/services/async/admin/organization/groups/RoleServiceAsync.kt index 94b16d5c8..abaa4905a 100644 --- a/openai-java-core/src/main/kotlin/com/openai/services/async/admin/organization/groups/RoleServiceAsync.kt +++ b/openai-java-core/src/main/kotlin/com/openai/services/async/admin/organization/groups/RoleServiceAsync.kt @@ -11,6 +11,8 @@ import com.openai.models.admin.organization.groups.roles.RoleDeleteParams import com.openai.models.admin.organization.groups.roles.RoleDeleteResponse import com.openai.models.admin.organization.groups.roles.RoleListPageAsync import com.openai.models.admin.organization.groups.roles.RoleListParams +import com.openai.models.admin.organization.groups.roles.RoleRetrieveParams +import com.openai.models.admin.organization.groups.roles.RoleRetrieveResponse import java.util.concurrent.CompletableFuture import java.util.function.Consumer @@ -50,6 +52,30 @@ interface RoleServiceAsync { requestOptions: RequestOptions = RequestOptions.none(), ): CompletableFuture + /** Retrieves an organization role assigned to a group. */ + fun retrieve( + roleId: String, + params: RoleRetrieveParams, + ): CompletableFuture = retrieve(roleId, params, RequestOptions.none()) + + /** @see retrieve */ + fun retrieve( + roleId: String, + params: RoleRetrieveParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture = + retrieve(params.toBuilder().roleId(roleId).build(), requestOptions) + + /** @see retrieve */ + fun retrieve(params: RoleRetrieveParams): CompletableFuture = + retrieve(params, RequestOptions.none()) + + /** @see retrieve */ + fun retrieve( + params: RoleRetrieveParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture + /** Lists the organization roles assigned to a group within the organization. */ fun list(groupId: String): CompletableFuture = list(groupId, RoleListParams.none()) @@ -146,6 +172,36 @@ interface RoleServiceAsync { requestOptions: RequestOptions = RequestOptions.none(), ): CompletableFuture> + /** + * Returns a raw HTTP response for `get /organization/groups/{group_id}/roles/{role_id}`, + * but is otherwise the same as [RoleServiceAsync.retrieve]. + */ + fun retrieve( + roleId: String, + params: RoleRetrieveParams, + ): CompletableFuture> = + retrieve(roleId, params, RequestOptions.none()) + + /** @see retrieve */ + fun retrieve( + roleId: String, + params: RoleRetrieveParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture> = + retrieve(params.toBuilder().roleId(roleId).build(), requestOptions) + + /** @see retrieve */ + fun retrieve( + params: RoleRetrieveParams + ): CompletableFuture> = + retrieve(params, RequestOptions.none()) + + /** @see retrieve */ + fun retrieve( + params: RoleRetrieveParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture> + /** * Returns a raw HTTP response for `get /organization/groups/{group_id}/roles`, but is * otherwise the same as [RoleServiceAsync.list]. diff --git a/openai-java-core/src/main/kotlin/com/openai/services/async/admin/organization/groups/RoleServiceAsyncImpl.kt b/openai-java-core/src/main/kotlin/com/openai/services/async/admin/organization/groups/RoleServiceAsyncImpl.kt index 228b3da89..62b61d094 100644 --- a/openai-java-core/src/main/kotlin/com/openai/services/async/admin/organization/groups/RoleServiceAsyncImpl.kt +++ b/openai-java-core/src/main/kotlin/com/openai/services/async/admin/organization/groups/RoleServiceAsyncImpl.kt @@ -24,6 +24,8 @@ import com.openai.models.admin.organization.groups.roles.RoleDeleteResponse import com.openai.models.admin.organization.groups.roles.RoleListPageAsync import com.openai.models.admin.organization.groups.roles.RoleListPageResponse import com.openai.models.admin.organization.groups.roles.RoleListParams +import com.openai.models.admin.organization.groups.roles.RoleRetrieveParams +import com.openai.models.admin.organization.groups.roles.RoleRetrieveResponse import java.util.concurrent.CompletableFuture import java.util.function.Consumer import kotlin.jvm.optionals.getOrNull @@ -47,6 +49,13 @@ class RoleServiceAsyncImpl internal constructor(private val clientOptions: Clien // post /organization/groups/{group_id}/roles withRawResponse().create(params, requestOptions).thenApply { it.parse() } + override fun retrieve( + params: RoleRetrieveParams, + requestOptions: RequestOptions, + ): CompletableFuture = + // get /organization/groups/{group_id}/roles/{role_id} + withRawResponse().retrieve(params, requestOptions).thenApply { it.parse() } + override fun list( params: RoleListParams, requestOptions: RequestOptions, @@ -112,6 +121,49 @@ class RoleServiceAsyncImpl internal constructor(private val clientOptions: Clien } } + private val retrieveHandler: Handler = + jsonHandler(clientOptions.jsonMapper) + + override fun retrieve( + params: RoleRetrieveParams, + requestOptions: RequestOptions, + ): CompletableFuture> { + // We check here instead of in the params builder because this can be specified + // positionally or in the params class. + checkRequired("roleId", params.roleId().getOrNull()) + val request = + HttpRequest.builder() + .method(HttpMethod.GET) + .baseUrl(clientOptions.baseUrl()) + .addPathSegments( + "organization", + "groups", + params._pathParam(0), + "roles", + params._pathParam(1), + ) + .build() + .prepareAsync( + clientOptions, + params, + SecurityOptions.builder().adminApiKeyAuth(true).build(), + ) + val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) + return request + .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } + .thenApply { response -> + errorHandler.handle(response).parseable { + response + .use { retrieveHandler.handle(it) } + .also { + if (requestOptions.responseValidation!!) { + it.validate() + } + } + } + } + } + private val listHandler: Handler = jsonHandler(clientOptions.jsonMapper) diff --git a/openai-java-core/src/main/kotlin/com/openai/services/async/admin/organization/groups/UserServiceAsync.kt b/openai-java-core/src/main/kotlin/com/openai/services/async/admin/organization/groups/UserServiceAsync.kt index 9b66808a1..7c0a2089f 100644 --- a/openai-java-core/src/main/kotlin/com/openai/services/async/admin/organization/groups/UserServiceAsync.kt +++ b/openai-java-core/src/main/kotlin/com/openai/services/async/admin/organization/groups/UserServiceAsync.kt @@ -11,6 +11,8 @@ import com.openai.models.admin.organization.groups.users.UserDeleteParams import com.openai.models.admin.organization.groups.users.UserDeleteResponse import com.openai.models.admin.organization.groups.users.UserListPageAsync import com.openai.models.admin.organization.groups.users.UserListParams +import com.openai.models.admin.organization.groups.users.UserRetrieveParams +import com.openai.models.admin.organization.groups.users.UserRetrieveResponse import java.util.concurrent.CompletableFuture import java.util.function.Consumer @@ -50,6 +52,30 @@ interface UserServiceAsync { requestOptions: RequestOptions = RequestOptions.none(), ): CompletableFuture + /** Retrieves a user in a group. */ + fun retrieve( + userId: String, + params: UserRetrieveParams, + ): CompletableFuture = retrieve(userId, params, RequestOptions.none()) + + /** @see retrieve */ + fun retrieve( + userId: String, + params: UserRetrieveParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture = + retrieve(params.toBuilder().userId(userId).build(), requestOptions) + + /** @see retrieve */ + fun retrieve(params: UserRetrieveParams): CompletableFuture = + retrieve(params, RequestOptions.none()) + + /** @see retrieve */ + fun retrieve( + params: UserRetrieveParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture + /** Lists the users assigned to a group. */ fun list(groupId: String): CompletableFuture = list(groupId, UserListParams.none()) @@ -146,6 +172,36 @@ interface UserServiceAsync { requestOptions: RequestOptions = RequestOptions.none(), ): CompletableFuture> + /** + * Returns a raw HTTP response for `get /organization/groups/{group_id}/users/{user_id}`, + * but is otherwise the same as [UserServiceAsync.retrieve]. + */ + fun retrieve( + userId: String, + params: UserRetrieveParams, + ): CompletableFuture> = + retrieve(userId, params, RequestOptions.none()) + + /** @see retrieve */ + fun retrieve( + userId: String, + params: UserRetrieveParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture> = + retrieve(params.toBuilder().userId(userId).build(), requestOptions) + + /** @see retrieve */ + fun retrieve( + params: UserRetrieveParams + ): CompletableFuture> = + retrieve(params, RequestOptions.none()) + + /** @see retrieve */ + fun retrieve( + params: UserRetrieveParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture> + /** * Returns a raw HTTP response for `get /organization/groups/{group_id}/users`, but is * otherwise the same as [UserServiceAsync.list]. diff --git a/openai-java-core/src/main/kotlin/com/openai/services/async/admin/organization/groups/UserServiceAsyncImpl.kt b/openai-java-core/src/main/kotlin/com/openai/services/async/admin/organization/groups/UserServiceAsyncImpl.kt index f77c590f7..e431b78e5 100644 --- a/openai-java-core/src/main/kotlin/com/openai/services/async/admin/organization/groups/UserServiceAsyncImpl.kt +++ b/openai-java-core/src/main/kotlin/com/openai/services/async/admin/organization/groups/UserServiceAsyncImpl.kt @@ -24,6 +24,8 @@ import com.openai.models.admin.organization.groups.users.UserDeleteResponse import com.openai.models.admin.organization.groups.users.UserListPageAsync import com.openai.models.admin.organization.groups.users.UserListPageResponse import com.openai.models.admin.organization.groups.users.UserListParams +import com.openai.models.admin.organization.groups.users.UserRetrieveParams +import com.openai.models.admin.organization.groups.users.UserRetrieveResponse import java.util.concurrent.CompletableFuture import java.util.function.Consumer import kotlin.jvm.optionals.getOrNull @@ -47,6 +49,13 @@ class UserServiceAsyncImpl internal constructor(private val clientOptions: Clien // post /organization/groups/{group_id}/users withRawResponse().create(params, requestOptions).thenApply { it.parse() } + override fun retrieve( + params: UserRetrieveParams, + requestOptions: RequestOptions, + ): CompletableFuture = + // get /organization/groups/{group_id}/users/{user_id} + withRawResponse().retrieve(params, requestOptions).thenApply { it.parse() } + override fun list( params: UserListParams, requestOptions: RequestOptions, @@ -112,6 +121,49 @@ class UserServiceAsyncImpl internal constructor(private val clientOptions: Clien } } + private val retrieveHandler: Handler = + jsonHandler(clientOptions.jsonMapper) + + override fun retrieve( + params: UserRetrieveParams, + requestOptions: RequestOptions, + ): CompletableFuture> { + // We check here instead of in the params builder because this can be specified + // positionally or in the params class. + checkRequired("userId", params.userId().getOrNull()) + val request = + HttpRequest.builder() + .method(HttpMethod.GET) + .baseUrl(clientOptions.baseUrl()) + .addPathSegments( + "organization", + "groups", + params._pathParam(0), + "users", + params._pathParam(1), + ) + .build() + .prepareAsync( + clientOptions, + params, + SecurityOptions.builder().adminApiKeyAuth(true).build(), + ) + val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) + return request + .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } + .thenApply { response -> + errorHandler.handle(response).parseable { + response + .use { retrieveHandler.handle(it) } + .also { + if (requestOptions.responseValidation!!) { + it.validate() + } + } + } + } + } + private val listHandler: Handler = jsonHandler(clientOptions.jsonMapper) diff --git a/openai-java-core/src/main/kotlin/com/openai/services/async/admin/organization/projects/DataRetentionServiceAsync.kt b/openai-java-core/src/main/kotlin/com/openai/services/async/admin/organization/projects/DataRetentionServiceAsync.kt new file mode 100644 index 000000000..4dfeba7a8 --- /dev/null +++ b/openai-java-core/src/main/kotlin/com/openai/services/async/admin/organization/projects/DataRetentionServiceAsync.kt @@ -0,0 +1,174 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.services.async.admin.organization.projects + +import com.openai.core.ClientOptions +import com.openai.core.RequestOptions +import com.openai.core.http.HttpResponseFor +import com.openai.models.admin.organization.projects.dataretention.DataRetentionRetrieveParams +import com.openai.models.admin.organization.projects.dataretention.DataRetentionUpdateParams +import com.openai.models.admin.organization.projects.dataretention.ProjectDataRetention +import java.util.concurrent.CompletableFuture +import java.util.function.Consumer + +interface DataRetentionServiceAsync { + + /** + * Returns a view of this service that provides access to raw HTTP responses for each method. + */ + fun withRawResponse(): WithRawResponse + + /** + * Returns a view of this service with the given option modifications applied. + * + * The original service is not modified. + */ + fun withOptions(modifier: Consumer): DataRetentionServiceAsync + + /** Retrieves project data retention controls. */ + fun retrieve(projectId: String): CompletableFuture = + retrieve(projectId, DataRetentionRetrieveParams.none()) + + /** @see retrieve */ + fun retrieve( + projectId: String, + params: DataRetentionRetrieveParams = DataRetentionRetrieveParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture = + retrieve(params.toBuilder().projectId(projectId).build(), requestOptions) + + /** @see retrieve */ + fun retrieve( + projectId: String, + params: DataRetentionRetrieveParams = DataRetentionRetrieveParams.none(), + ): CompletableFuture = retrieve(projectId, params, RequestOptions.none()) + + /** @see retrieve */ + fun retrieve( + params: DataRetentionRetrieveParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture + + /** @see retrieve */ + fun retrieve(params: DataRetentionRetrieveParams): CompletableFuture = + retrieve(params, RequestOptions.none()) + + /** @see retrieve */ + fun retrieve( + projectId: String, + requestOptions: RequestOptions, + ): CompletableFuture = + retrieve(projectId, DataRetentionRetrieveParams.none(), requestOptions) + + /** Updates project data retention controls. */ + fun update( + projectId: String, + params: DataRetentionUpdateParams, + ): CompletableFuture = update(projectId, params, RequestOptions.none()) + + /** @see update */ + fun update( + projectId: String, + params: DataRetentionUpdateParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture = + update(params.toBuilder().projectId(projectId).build(), requestOptions) + + /** @see update */ + fun update(params: DataRetentionUpdateParams): CompletableFuture = + update(params, RequestOptions.none()) + + /** @see update */ + fun update( + params: DataRetentionUpdateParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture + + /** + * A view of [DataRetentionServiceAsync] that provides access to raw HTTP responses for each + * method. + */ + interface WithRawResponse { + + /** + * Returns a view of this service with the given option modifications applied. + * + * The original service is not modified. + */ + fun withOptions( + modifier: Consumer + ): DataRetentionServiceAsync.WithRawResponse + + /** + * Returns a raw HTTP response for `get /organization/projects/{project_id}/data_retention`, + * but is otherwise the same as [DataRetentionServiceAsync.retrieve]. + */ + fun retrieve(projectId: String): CompletableFuture> = + retrieve(projectId, DataRetentionRetrieveParams.none()) + + /** @see retrieve */ + fun retrieve( + projectId: String, + params: DataRetentionRetrieveParams = DataRetentionRetrieveParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture> = + retrieve(params.toBuilder().projectId(projectId).build(), requestOptions) + + /** @see retrieve */ + fun retrieve( + projectId: String, + params: DataRetentionRetrieveParams = DataRetentionRetrieveParams.none(), + ): CompletableFuture> = + retrieve(projectId, params, RequestOptions.none()) + + /** @see retrieve */ + fun retrieve( + params: DataRetentionRetrieveParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture> + + /** @see retrieve */ + fun retrieve( + params: DataRetentionRetrieveParams + ): CompletableFuture> = + retrieve(params, RequestOptions.none()) + + /** @see retrieve */ + fun retrieve( + projectId: String, + requestOptions: RequestOptions, + ): CompletableFuture> = + retrieve(projectId, DataRetentionRetrieveParams.none(), requestOptions) + + /** + * Returns a raw HTTP response for `post + * /organization/projects/{project_id}/data_retention`, but is otherwise the same as + * [DataRetentionServiceAsync.update]. + */ + fun update( + projectId: String, + params: DataRetentionUpdateParams, + ): CompletableFuture> = + update(projectId, params, RequestOptions.none()) + + /** @see update */ + fun update( + projectId: String, + params: DataRetentionUpdateParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture> = + update(params.toBuilder().projectId(projectId).build(), requestOptions) + + /** @see update */ + fun update( + params: DataRetentionUpdateParams + ): CompletableFuture> = + update(params, RequestOptions.none()) + + /** @see update */ + fun update( + params: DataRetentionUpdateParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture> + } +} diff --git a/openai-java-core/src/main/kotlin/com/openai/services/async/admin/organization/projects/DataRetentionServiceAsyncImpl.kt b/openai-java-core/src/main/kotlin/com/openai/services/async/admin/organization/projects/DataRetentionServiceAsyncImpl.kt new file mode 100644 index 000000000..92e6497a4 --- /dev/null +++ b/openai-java-core/src/main/kotlin/com/openai/services/async/admin/organization/projects/DataRetentionServiceAsyncImpl.kt @@ -0,0 +1,151 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.services.async.admin.organization.projects + +import com.openai.core.ClientOptions +import com.openai.core.RequestOptions +import com.openai.core.SecurityOptions +import com.openai.core.checkRequired +import com.openai.core.handlers.errorBodyHandler +import com.openai.core.handlers.errorHandler +import com.openai.core.handlers.jsonHandler +import com.openai.core.http.HttpMethod +import com.openai.core.http.HttpRequest +import com.openai.core.http.HttpResponse +import com.openai.core.http.HttpResponse.Handler +import com.openai.core.http.HttpResponseFor +import com.openai.core.http.json +import com.openai.core.http.parseable +import com.openai.core.prepareAsync +import com.openai.models.admin.organization.projects.dataretention.DataRetentionRetrieveParams +import com.openai.models.admin.organization.projects.dataretention.DataRetentionUpdateParams +import com.openai.models.admin.organization.projects.dataretention.ProjectDataRetention +import java.util.concurrent.CompletableFuture +import java.util.function.Consumer +import kotlin.jvm.optionals.getOrNull + +class DataRetentionServiceAsyncImpl internal constructor(private val clientOptions: ClientOptions) : + DataRetentionServiceAsync { + + private val withRawResponse: DataRetentionServiceAsync.WithRawResponse by lazy { + WithRawResponseImpl(clientOptions) + } + + override fun withRawResponse(): DataRetentionServiceAsync.WithRawResponse = withRawResponse + + override fun withOptions(modifier: Consumer): DataRetentionServiceAsync = + DataRetentionServiceAsyncImpl(clientOptions.toBuilder().apply(modifier::accept).build()) + + override fun retrieve( + params: DataRetentionRetrieveParams, + requestOptions: RequestOptions, + ): CompletableFuture = + // get /organization/projects/{project_id}/data_retention + withRawResponse().retrieve(params, requestOptions).thenApply { it.parse() } + + override fun update( + params: DataRetentionUpdateParams, + requestOptions: RequestOptions, + ): CompletableFuture = + // post /organization/projects/{project_id}/data_retention + withRawResponse().update(params, requestOptions).thenApply { it.parse() } + + class WithRawResponseImpl internal constructor(private val clientOptions: ClientOptions) : + DataRetentionServiceAsync.WithRawResponse { + + private val errorHandler: Handler = + errorHandler(errorBodyHandler(clientOptions.jsonMapper)) + + override fun withOptions( + modifier: Consumer + ): DataRetentionServiceAsync.WithRawResponse = + DataRetentionServiceAsyncImpl.WithRawResponseImpl( + clientOptions.toBuilder().apply(modifier::accept).build() + ) + + private val retrieveHandler: Handler = + jsonHandler(clientOptions.jsonMapper) + + override fun retrieve( + params: DataRetentionRetrieveParams, + requestOptions: RequestOptions, + ): CompletableFuture> { + // We check here instead of in the params builder because this can be specified + // positionally or in the params class. + checkRequired("projectId", params.projectId().getOrNull()) + val request = + HttpRequest.builder() + .method(HttpMethod.GET) + .baseUrl(clientOptions.baseUrl()) + .addPathSegments( + "organization", + "projects", + params._pathParam(0), + "data_retention", + ) + .build() + .prepareAsync( + clientOptions, + params, + SecurityOptions.builder().adminApiKeyAuth(true).build(), + ) + val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) + return request + .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } + .thenApply { response -> + errorHandler.handle(response).parseable { + response + .use { retrieveHandler.handle(it) } + .also { + if (requestOptions.responseValidation!!) { + it.validate() + } + } + } + } + } + + private val updateHandler: Handler = + jsonHandler(clientOptions.jsonMapper) + + override fun update( + params: DataRetentionUpdateParams, + requestOptions: RequestOptions, + ): CompletableFuture> { + // We check here instead of in the params builder because this can be specified + // positionally or in the params class. + checkRequired("projectId", params.projectId().getOrNull()) + val request = + HttpRequest.builder() + .method(HttpMethod.POST) + .baseUrl(clientOptions.baseUrl()) + .addPathSegments( + "organization", + "projects", + params._pathParam(0), + "data_retention", + ) + .body(json(clientOptions.jsonMapper, params._body())) + .build() + .prepareAsync( + clientOptions, + params, + SecurityOptions.builder().adminApiKeyAuth(true).build(), + ) + val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) + return request + .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } + .thenApply { response -> + errorHandler.handle(response).parseable { + response + .use { updateHandler.handle(it) } + .also { + if (requestOptions.responseValidation!!) { + it.validate() + } + } + } + } + } + } +} diff --git a/openai-java-core/src/main/kotlin/com/openai/services/async/admin/organization/projects/GroupServiceAsync.kt b/openai-java-core/src/main/kotlin/com/openai/services/async/admin/organization/projects/GroupServiceAsync.kt index 1af582b46..be59fa2cb 100644 --- a/openai-java-core/src/main/kotlin/com/openai/services/async/admin/organization/projects/GroupServiceAsync.kt +++ b/openai-java-core/src/main/kotlin/com/openai/services/async/admin/organization/projects/GroupServiceAsync.kt @@ -10,6 +10,7 @@ import com.openai.models.admin.organization.projects.groups.GroupDeleteParams import com.openai.models.admin.organization.projects.groups.GroupDeleteResponse import com.openai.models.admin.organization.projects.groups.GroupListPageAsync import com.openai.models.admin.organization.projects.groups.GroupListParams +import com.openai.models.admin.organization.projects.groups.GroupRetrieveParams import com.openai.models.admin.organization.projects.groups.ProjectGroup import com.openai.services.async.admin.organization.projects.groups.RoleServiceAsync import java.util.concurrent.CompletableFuture @@ -53,6 +54,28 @@ interface GroupServiceAsync { requestOptions: RequestOptions = RequestOptions.none(), ): CompletableFuture + /** Retrieves a project's group. */ + fun retrieve(groupId: String, params: GroupRetrieveParams): CompletableFuture = + retrieve(groupId, params, RequestOptions.none()) + + /** @see retrieve */ + fun retrieve( + groupId: String, + params: GroupRetrieveParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture = + retrieve(params.toBuilder().groupId(groupId).build(), requestOptions) + + /** @see retrieve */ + fun retrieve(params: GroupRetrieveParams): CompletableFuture = + retrieve(params, RequestOptions.none()) + + /** @see retrieve */ + fun retrieve( + params: GroupRetrieveParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture + /** Lists the groups that have access to a project. */ fun list(projectId: String): CompletableFuture = list(projectId, GroupListParams.none()) @@ -152,6 +175,37 @@ interface GroupServiceAsync { requestOptions: RequestOptions = RequestOptions.none(), ): CompletableFuture> + /** + * Returns a raw HTTP response for `get + * /organization/projects/{project_id}/groups/{group_id}`, but is otherwise the same as + * [GroupServiceAsync.retrieve]. + */ + fun retrieve( + groupId: String, + params: GroupRetrieveParams, + ): CompletableFuture> = + retrieve(groupId, params, RequestOptions.none()) + + /** @see retrieve */ + fun retrieve( + groupId: String, + params: GroupRetrieveParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture> = + retrieve(params.toBuilder().groupId(groupId).build(), requestOptions) + + /** @see retrieve */ + fun retrieve( + params: GroupRetrieveParams + ): CompletableFuture> = + retrieve(params, RequestOptions.none()) + + /** @see retrieve */ + fun retrieve( + params: GroupRetrieveParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture> + /** * Returns a raw HTTP response for `get /organization/projects/{project_id}/groups`, but is * otherwise the same as [GroupServiceAsync.list]. diff --git a/openai-java-core/src/main/kotlin/com/openai/services/async/admin/organization/projects/GroupServiceAsyncImpl.kt b/openai-java-core/src/main/kotlin/com/openai/services/async/admin/organization/projects/GroupServiceAsyncImpl.kt index 2b968d975..e84d2968f 100644 --- a/openai-java-core/src/main/kotlin/com/openai/services/async/admin/organization/projects/GroupServiceAsyncImpl.kt +++ b/openai-java-core/src/main/kotlin/com/openai/services/async/admin/organization/projects/GroupServiceAsyncImpl.kt @@ -23,6 +23,7 @@ import com.openai.models.admin.organization.projects.groups.GroupDeleteResponse import com.openai.models.admin.organization.projects.groups.GroupListPageAsync import com.openai.models.admin.organization.projects.groups.GroupListPageResponse import com.openai.models.admin.organization.projects.groups.GroupListParams +import com.openai.models.admin.organization.projects.groups.GroupRetrieveParams import com.openai.models.admin.organization.projects.groups.ProjectGroup import com.openai.services.async.admin.organization.projects.groups.RoleServiceAsync import com.openai.services.async.admin.organization.projects.groups.RoleServiceAsyncImpl @@ -53,6 +54,13 @@ class GroupServiceAsyncImpl internal constructor(private val clientOptions: Clie // post /organization/projects/{project_id}/groups withRawResponse().create(params, requestOptions).thenApply { it.parse() } + override fun retrieve( + params: GroupRetrieveParams, + requestOptions: RequestOptions, + ): CompletableFuture = + // get /organization/projects/{project_id}/groups/{group_id} + withRawResponse().retrieve(params, requestOptions).thenApply { it.parse() } + override fun list( params: GroupListParams, requestOptions: RequestOptions, @@ -124,6 +132,49 @@ class GroupServiceAsyncImpl internal constructor(private val clientOptions: Clie } } + private val retrieveHandler: Handler = + jsonHandler(clientOptions.jsonMapper) + + override fun retrieve( + params: GroupRetrieveParams, + requestOptions: RequestOptions, + ): CompletableFuture> { + // We check here instead of in the params builder because this can be specified + // positionally or in the params class. + checkRequired("groupId", params.groupId().getOrNull()) + val request = + HttpRequest.builder() + .method(HttpMethod.GET) + .baseUrl(clientOptions.baseUrl()) + .addPathSegments( + "organization", + "projects", + params._pathParam(0), + "groups", + params._pathParam(1), + ) + .build() + .prepareAsync( + clientOptions, + params, + SecurityOptions.builder().adminApiKeyAuth(true).build(), + ) + val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) + return request + .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } + .thenApply { response -> + errorHandler.handle(response).parseable { + response + .use { retrieveHandler.handle(it) } + .also { + if (requestOptions.responseValidation!!) { + it.validate() + } + } + } + } + } + private val listHandler: Handler = jsonHandler(clientOptions.jsonMapper) diff --git a/openai-java-core/src/main/kotlin/com/openai/services/async/admin/organization/projects/RoleServiceAsync.kt b/openai-java-core/src/main/kotlin/com/openai/services/async/admin/organization/projects/RoleServiceAsync.kt index 42abdb06a..8d9d6c704 100644 --- a/openai-java-core/src/main/kotlin/com/openai/services/async/admin/organization/projects/RoleServiceAsync.kt +++ b/openai-java-core/src/main/kotlin/com/openai/services/async/admin/organization/projects/RoleServiceAsync.kt @@ -10,6 +10,7 @@ import com.openai.models.admin.organization.projects.roles.RoleDeleteParams import com.openai.models.admin.organization.projects.roles.RoleDeleteResponse import com.openai.models.admin.organization.projects.roles.RoleListPageAsync import com.openai.models.admin.organization.projects.roles.RoleListParams +import com.openai.models.admin.organization.projects.roles.RoleRetrieveParams import com.openai.models.admin.organization.projects.roles.RoleUpdateParams import com.openai.models.admin.organization.roles.Role import java.util.concurrent.CompletableFuture @@ -51,6 +52,27 @@ interface RoleServiceAsync { requestOptions: RequestOptions = RequestOptions.none(), ): CompletableFuture + /** Retrieves a project role. */ + fun retrieve(roleId: String, params: RoleRetrieveParams): CompletableFuture = + retrieve(roleId, params, RequestOptions.none()) + + /** @see retrieve */ + fun retrieve( + roleId: String, + params: RoleRetrieveParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture = retrieve(params.toBuilder().roleId(roleId).build(), requestOptions) + + /** @see retrieve */ + fun retrieve(params: RoleRetrieveParams): CompletableFuture = + retrieve(params, RequestOptions.none()) + + /** @see retrieve */ + fun retrieve( + params: RoleRetrieveParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture + /** Updates an existing project role. */ fun update(roleId: String, params: RoleUpdateParams): CompletableFuture = update(roleId, params, RequestOptions.none()) @@ -166,6 +188,34 @@ interface RoleServiceAsync { requestOptions: RequestOptions = RequestOptions.none(), ): CompletableFuture> + /** + * Returns a raw HTTP response for `get /projects/{project_id}/roles/{role_id}`, but is + * otherwise the same as [RoleServiceAsync.retrieve]. + */ + fun retrieve( + roleId: String, + params: RoleRetrieveParams, + ): CompletableFuture> = + retrieve(roleId, params, RequestOptions.none()) + + /** @see retrieve */ + fun retrieve( + roleId: String, + params: RoleRetrieveParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture> = + retrieve(params.toBuilder().roleId(roleId).build(), requestOptions) + + /** @see retrieve */ + fun retrieve(params: RoleRetrieveParams): CompletableFuture> = + retrieve(params, RequestOptions.none()) + + /** @see retrieve */ + fun retrieve( + params: RoleRetrieveParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture> + /** * Returns a raw HTTP response for `post /projects/{project_id}/roles/{role_id}`, but is * otherwise the same as [RoleServiceAsync.update]. diff --git a/openai-java-core/src/main/kotlin/com/openai/services/async/admin/organization/projects/RoleServiceAsyncImpl.kt b/openai-java-core/src/main/kotlin/com/openai/services/async/admin/organization/projects/RoleServiceAsyncImpl.kt index 7d0397364..20fd771ba 100644 --- a/openai-java-core/src/main/kotlin/com/openai/services/async/admin/organization/projects/RoleServiceAsyncImpl.kt +++ b/openai-java-core/src/main/kotlin/com/openai/services/async/admin/organization/projects/RoleServiceAsyncImpl.kt @@ -23,6 +23,7 @@ import com.openai.models.admin.organization.projects.roles.RoleDeleteResponse import com.openai.models.admin.organization.projects.roles.RoleListPageAsync import com.openai.models.admin.organization.projects.roles.RoleListPageResponse import com.openai.models.admin.organization.projects.roles.RoleListParams +import com.openai.models.admin.organization.projects.roles.RoleRetrieveParams import com.openai.models.admin.organization.projects.roles.RoleUpdateParams import com.openai.models.admin.organization.roles.Role import java.util.concurrent.CompletableFuture @@ -48,6 +49,13 @@ class RoleServiceAsyncImpl internal constructor(private val clientOptions: Clien // post /projects/{project_id}/roles withRawResponse().create(params, requestOptions).thenApply { it.parse() } + override fun retrieve( + params: RoleRetrieveParams, + requestOptions: RequestOptions, + ): CompletableFuture = + // get /projects/{project_id}/roles/{role_id} + withRawResponse().retrieve(params, requestOptions).thenApply { it.parse() } + override fun update( params: RoleUpdateParams, requestOptions: RequestOptions, @@ -119,6 +127,47 @@ class RoleServiceAsyncImpl internal constructor(private val clientOptions: Clien } } + private val retrieveHandler: Handler = jsonHandler(clientOptions.jsonMapper) + + override fun retrieve( + params: RoleRetrieveParams, + requestOptions: RequestOptions, + ): CompletableFuture> { + // We check here instead of in the params builder because this can be specified + // positionally or in the params class. + checkRequired("roleId", params.roleId().getOrNull()) + val request = + HttpRequest.builder() + .method(HttpMethod.GET) + .baseUrl(clientOptions.baseUrl()) + .addPathSegments( + "projects", + params._pathParam(0), + "roles", + params._pathParam(1), + ) + .build() + .prepareAsync( + clientOptions, + params, + SecurityOptions.builder().adminApiKeyAuth(true).build(), + ) + val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) + return request + .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } + .thenApply { response -> + errorHandler.handle(response).parseable { + response + .use { retrieveHandler.handle(it) } + .also { + if (requestOptions.responseValidation!!) { + it.validate() + } + } + } + } + } + private val updateHandler: Handler = jsonHandler(clientOptions.jsonMapper) override fun update( diff --git a/openai-java-core/src/main/kotlin/com/openai/services/async/admin/organization/projects/ServiceAccountServiceAsync.kt b/openai-java-core/src/main/kotlin/com/openai/services/async/admin/organization/projects/ServiceAccountServiceAsync.kt index f9eabacf8..0ece534c3 100644 --- a/openai-java-core/src/main/kotlin/com/openai/services/async/admin/organization/projects/ServiceAccountServiceAsync.kt +++ b/openai-java-core/src/main/kotlin/com/openai/services/async/admin/organization/projects/ServiceAccountServiceAsync.kt @@ -13,6 +13,7 @@ import com.openai.models.admin.organization.projects.serviceaccounts.ServiceAcco import com.openai.models.admin.organization.projects.serviceaccounts.ServiceAccountListPageAsync import com.openai.models.admin.organization.projects.serviceaccounts.ServiceAccountListParams import com.openai.models.admin.organization.projects.serviceaccounts.ServiceAccountRetrieveParams +import com.openai.models.admin.organization.projects.serviceaccounts.ServiceAccountUpdateParams import java.util.concurrent.CompletableFuture import java.util.function.Consumer @@ -84,6 +85,31 @@ interface ServiceAccountServiceAsync { requestOptions: RequestOptions = RequestOptions.none(), ): CompletableFuture + /** Updates a service account in the project. */ + fun update( + serviceAccountId: String, + params: ServiceAccountUpdateParams, + ): CompletableFuture = + update(serviceAccountId, params, RequestOptions.none()) + + /** @see update */ + fun update( + serviceAccountId: String, + params: ServiceAccountUpdateParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture = + update(params.toBuilder().serviceAccountId(serviceAccountId).build(), requestOptions) + + /** @see update */ + fun update(params: ServiceAccountUpdateParams): CompletableFuture = + update(params, RequestOptions.none()) + + /** @see update */ + fun update( + params: ServiceAccountUpdateParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture + /** Returns a list of service accounts in the project. */ fun list(projectId: String): CompletableFuture = list(projectId, ServiceAccountListParams.none()) @@ -228,6 +254,37 @@ interface ServiceAccountServiceAsync { requestOptions: RequestOptions = RequestOptions.none(), ): CompletableFuture> + /** + * Returns a raw HTTP response for `post + * /organization/projects/{project_id}/service_accounts/{service_account_id}`, but is + * otherwise the same as [ServiceAccountServiceAsync.update]. + */ + fun update( + serviceAccountId: String, + params: ServiceAccountUpdateParams, + ): CompletableFuture> = + update(serviceAccountId, params, RequestOptions.none()) + + /** @see update */ + fun update( + serviceAccountId: String, + params: ServiceAccountUpdateParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture> = + update(params.toBuilder().serviceAccountId(serviceAccountId).build(), requestOptions) + + /** @see update */ + fun update( + params: ServiceAccountUpdateParams + ): CompletableFuture> = + update(params, RequestOptions.none()) + + /** @see update */ + fun update( + params: ServiceAccountUpdateParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture> + /** * Returns a raw HTTP response for `get * /organization/projects/{project_id}/service_accounts`, but is otherwise the same as diff --git a/openai-java-core/src/main/kotlin/com/openai/services/async/admin/organization/projects/ServiceAccountServiceAsyncImpl.kt b/openai-java-core/src/main/kotlin/com/openai/services/async/admin/organization/projects/ServiceAccountServiceAsyncImpl.kt index 9fd7117c6..2b373c7e2 100644 --- a/openai-java-core/src/main/kotlin/com/openai/services/async/admin/organization/projects/ServiceAccountServiceAsyncImpl.kt +++ b/openai-java-core/src/main/kotlin/com/openai/services/async/admin/organization/projects/ServiceAccountServiceAsyncImpl.kt @@ -26,6 +26,7 @@ import com.openai.models.admin.organization.projects.serviceaccounts.ServiceAcco import com.openai.models.admin.organization.projects.serviceaccounts.ServiceAccountListPageResponse import com.openai.models.admin.organization.projects.serviceaccounts.ServiceAccountListParams import com.openai.models.admin.organization.projects.serviceaccounts.ServiceAccountRetrieveParams +import com.openai.models.admin.organization.projects.serviceaccounts.ServiceAccountUpdateParams import java.util.concurrent.CompletableFuture import java.util.function.Consumer import kotlin.jvm.optionals.getOrNull @@ -58,6 +59,13 @@ internal constructor(private val clientOptions: ClientOptions) : ServiceAccountS // get /organization/projects/{project_id}/service_accounts/{service_account_id} withRawResponse().retrieve(params, requestOptions).thenApply { it.parse() } + override fun update( + params: ServiceAccountUpdateParams, + requestOptions: RequestOptions, + ): CompletableFuture = + // post /organization/projects/{project_id}/service_accounts/{service_account_id} + withRawResponse().update(params, requestOptions).thenApply { it.parse() } + override fun list( params: ServiceAccountListParams, requestOptions: RequestOptions, @@ -171,6 +179,50 @@ internal constructor(private val clientOptions: ClientOptions) : ServiceAccountS } } + private val updateHandler: Handler = + jsonHandler(clientOptions.jsonMapper) + + override fun update( + params: ServiceAccountUpdateParams, + requestOptions: RequestOptions, + ): CompletableFuture> { + // We check here instead of in the params builder because this can be specified + // positionally or in the params class. + checkRequired("serviceAccountId", params.serviceAccountId().getOrNull()) + val request = + HttpRequest.builder() + .method(HttpMethod.POST) + .baseUrl(clientOptions.baseUrl()) + .addPathSegments( + "organization", + "projects", + params._pathParam(0), + "service_accounts", + params._pathParam(1), + ) + .body(json(clientOptions.jsonMapper, params._body())) + .build() + .prepareAsync( + clientOptions, + params, + SecurityOptions.builder().adminApiKeyAuth(true).build(), + ) + val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) + return request + .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } + .thenApply { response -> + errorHandler.handle(response).parseable { + response + .use { updateHandler.handle(it) } + .also { + if (requestOptions.responseValidation!!) { + it.validate() + } + } + } + } + } + private val listHandler: Handler = jsonHandler(clientOptions.jsonMapper) diff --git a/openai-java-core/src/main/kotlin/com/openai/services/async/admin/organization/projects/SpendAlertServiceAsync.kt b/openai-java-core/src/main/kotlin/com/openai/services/async/admin/organization/projects/SpendAlertServiceAsync.kt new file mode 100644 index 000000000..b9cdefa63 --- /dev/null +++ b/openai-java-core/src/main/kotlin/com/openai/services/async/admin/organization/projects/SpendAlertServiceAsync.kt @@ -0,0 +1,287 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.services.async.admin.organization.projects + +import com.openai.core.ClientOptions +import com.openai.core.RequestOptions +import com.openai.core.http.HttpResponseFor +import com.openai.models.admin.organization.projects.spendalerts.ProjectSpendAlert +import com.openai.models.admin.organization.projects.spendalerts.ProjectSpendAlertDeleted +import com.openai.models.admin.organization.projects.spendalerts.SpendAlertCreateParams +import com.openai.models.admin.organization.projects.spendalerts.SpendAlertDeleteParams +import com.openai.models.admin.organization.projects.spendalerts.SpendAlertListPageAsync +import com.openai.models.admin.organization.projects.spendalerts.SpendAlertListParams +import com.openai.models.admin.organization.projects.spendalerts.SpendAlertUpdateParams +import java.util.concurrent.CompletableFuture +import java.util.function.Consumer + +interface SpendAlertServiceAsync { + + /** + * Returns a view of this service that provides access to raw HTTP responses for each method. + */ + fun withRawResponse(): WithRawResponse + + /** + * Returns a view of this service with the given option modifications applied. + * + * The original service is not modified. + */ + fun withOptions(modifier: Consumer): SpendAlertServiceAsync + + /** Creates a project spend alert. */ + fun create( + projectId: String, + params: SpendAlertCreateParams, + ): CompletableFuture = create(projectId, params, RequestOptions.none()) + + /** @see create */ + fun create( + projectId: String, + params: SpendAlertCreateParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture = + create(params.toBuilder().projectId(projectId).build(), requestOptions) + + /** @see create */ + fun create(params: SpendAlertCreateParams): CompletableFuture = + create(params, RequestOptions.none()) + + /** @see create */ + fun create( + params: SpendAlertCreateParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture + + /** Updates a project spend alert. */ + fun update( + alertId: String, + params: SpendAlertUpdateParams, + ): CompletableFuture = update(alertId, params, RequestOptions.none()) + + /** @see update */ + fun update( + alertId: String, + params: SpendAlertUpdateParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture = + update(params.toBuilder().alertId(alertId).build(), requestOptions) + + /** @see update */ + fun update(params: SpendAlertUpdateParams): CompletableFuture = + update(params, RequestOptions.none()) + + /** @see update */ + fun update( + params: SpendAlertUpdateParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture + + /** Lists project spend alerts. */ + fun list(projectId: String): CompletableFuture = + list(projectId, SpendAlertListParams.none()) + + /** @see list */ + fun list( + projectId: String, + params: SpendAlertListParams = SpendAlertListParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture = + list(params.toBuilder().projectId(projectId).build(), requestOptions) + + /** @see list */ + fun list( + projectId: String, + params: SpendAlertListParams = SpendAlertListParams.none(), + ): CompletableFuture = list(projectId, params, RequestOptions.none()) + + /** @see list */ + fun list( + params: SpendAlertListParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture + + /** @see list */ + fun list(params: SpendAlertListParams): CompletableFuture = + list(params, RequestOptions.none()) + + /** @see list */ + fun list( + projectId: String, + requestOptions: RequestOptions, + ): CompletableFuture = + list(projectId, SpendAlertListParams.none(), requestOptions) + + /** Deletes a project spend alert. */ + fun delete( + alertId: String, + params: SpendAlertDeleteParams, + ): CompletableFuture = delete(alertId, params, RequestOptions.none()) + + /** @see delete */ + fun delete( + alertId: String, + params: SpendAlertDeleteParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture = + delete(params.toBuilder().alertId(alertId).build(), requestOptions) + + /** @see delete */ + fun delete(params: SpendAlertDeleteParams): CompletableFuture = + delete(params, RequestOptions.none()) + + /** @see delete */ + fun delete( + params: SpendAlertDeleteParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture + + /** + * A view of [SpendAlertServiceAsync] that provides access to raw HTTP responses for each + * method. + */ + interface WithRawResponse { + + /** + * Returns a view of this service with the given option modifications applied. + * + * The original service is not modified. + */ + fun withOptions( + modifier: Consumer + ): SpendAlertServiceAsync.WithRawResponse + + /** + * Returns a raw HTTP response for `post /organization/projects/{project_id}/spend_alerts`, + * but is otherwise the same as [SpendAlertServiceAsync.create]. + */ + fun create( + projectId: String, + params: SpendAlertCreateParams, + ): CompletableFuture> = + create(projectId, params, RequestOptions.none()) + + /** @see create */ + fun create( + projectId: String, + params: SpendAlertCreateParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture> = + create(params.toBuilder().projectId(projectId).build(), requestOptions) + + /** @see create */ + fun create( + params: SpendAlertCreateParams + ): CompletableFuture> = + create(params, RequestOptions.none()) + + /** @see create */ + fun create( + params: SpendAlertCreateParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture> + + /** + * Returns a raw HTTP response for `post + * /organization/projects/{project_id}/spend_alerts/{alert_id}`, but is otherwise the same + * as [SpendAlertServiceAsync.update]. + */ + fun update( + alertId: String, + params: SpendAlertUpdateParams, + ): CompletableFuture> = + update(alertId, params, RequestOptions.none()) + + /** @see update */ + fun update( + alertId: String, + params: SpendAlertUpdateParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture> = + update(params.toBuilder().alertId(alertId).build(), requestOptions) + + /** @see update */ + fun update( + params: SpendAlertUpdateParams + ): CompletableFuture> = + update(params, RequestOptions.none()) + + /** @see update */ + fun update( + params: SpendAlertUpdateParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture> + + /** + * Returns a raw HTTP response for `get /organization/projects/{project_id}/spend_alerts`, + * but is otherwise the same as [SpendAlertServiceAsync.list]. + */ + fun list(projectId: String): CompletableFuture> = + list(projectId, SpendAlertListParams.none()) + + /** @see list */ + fun list( + projectId: String, + params: SpendAlertListParams = SpendAlertListParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture> = + list(params.toBuilder().projectId(projectId).build(), requestOptions) + + /** @see list */ + fun list( + projectId: String, + params: SpendAlertListParams = SpendAlertListParams.none(), + ): CompletableFuture> = + list(projectId, params, RequestOptions.none()) + + /** @see list */ + fun list( + params: SpendAlertListParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture> + + /** @see list */ + fun list( + params: SpendAlertListParams + ): CompletableFuture> = + list(params, RequestOptions.none()) + + /** @see list */ + fun list( + projectId: String, + requestOptions: RequestOptions, + ): CompletableFuture> = + list(projectId, SpendAlertListParams.none(), requestOptions) + + /** + * Returns a raw HTTP response for `delete + * /organization/projects/{project_id}/spend_alerts/{alert_id}`, but is otherwise the same + * as [SpendAlertServiceAsync.delete]. + */ + fun delete( + alertId: String, + params: SpendAlertDeleteParams, + ): CompletableFuture> = + delete(alertId, params, RequestOptions.none()) + + /** @see delete */ + fun delete( + alertId: String, + params: SpendAlertDeleteParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture> = + delete(params.toBuilder().alertId(alertId).build(), requestOptions) + + /** @see delete */ + fun delete( + params: SpendAlertDeleteParams + ): CompletableFuture> = + delete(params, RequestOptions.none()) + + /** @see delete */ + fun delete( + params: SpendAlertDeleteParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture> + } +} diff --git a/openai-java-core/src/main/kotlin/com/openai/services/async/admin/organization/projects/SpendAlertServiceAsyncImpl.kt b/openai-java-core/src/main/kotlin/com/openai/services/async/admin/organization/projects/SpendAlertServiceAsyncImpl.kt new file mode 100644 index 000000000..708b4efcb --- /dev/null +++ b/openai-java-core/src/main/kotlin/com/openai/services/async/admin/organization/projects/SpendAlertServiceAsyncImpl.kt @@ -0,0 +1,266 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.services.async.admin.organization.projects + +import com.openai.core.ClientOptions +import com.openai.core.RequestOptions +import com.openai.core.SecurityOptions +import com.openai.core.checkRequired +import com.openai.core.handlers.errorBodyHandler +import com.openai.core.handlers.errorHandler +import com.openai.core.handlers.jsonHandler +import com.openai.core.http.HttpMethod +import com.openai.core.http.HttpRequest +import com.openai.core.http.HttpResponse +import com.openai.core.http.HttpResponse.Handler +import com.openai.core.http.HttpResponseFor +import com.openai.core.http.json +import com.openai.core.http.parseable +import com.openai.core.prepareAsync +import com.openai.models.admin.organization.projects.spendalerts.ProjectSpendAlert +import com.openai.models.admin.organization.projects.spendalerts.ProjectSpendAlertDeleted +import com.openai.models.admin.organization.projects.spendalerts.SpendAlertCreateParams +import com.openai.models.admin.organization.projects.spendalerts.SpendAlertDeleteParams +import com.openai.models.admin.organization.projects.spendalerts.SpendAlertListPageAsync +import com.openai.models.admin.organization.projects.spendalerts.SpendAlertListPageResponse +import com.openai.models.admin.organization.projects.spendalerts.SpendAlertListParams +import com.openai.models.admin.organization.projects.spendalerts.SpendAlertUpdateParams +import java.util.concurrent.CompletableFuture +import java.util.function.Consumer +import kotlin.jvm.optionals.getOrNull + +class SpendAlertServiceAsyncImpl internal constructor(private val clientOptions: ClientOptions) : + SpendAlertServiceAsync { + + private val withRawResponse: SpendAlertServiceAsync.WithRawResponse by lazy { + WithRawResponseImpl(clientOptions) + } + + override fun withRawResponse(): SpendAlertServiceAsync.WithRawResponse = withRawResponse + + override fun withOptions(modifier: Consumer): SpendAlertServiceAsync = + SpendAlertServiceAsyncImpl(clientOptions.toBuilder().apply(modifier::accept).build()) + + override fun create( + params: SpendAlertCreateParams, + requestOptions: RequestOptions, + ): CompletableFuture = + // post /organization/projects/{project_id}/spend_alerts + withRawResponse().create(params, requestOptions).thenApply { it.parse() } + + override fun update( + params: SpendAlertUpdateParams, + requestOptions: RequestOptions, + ): CompletableFuture = + // post /organization/projects/{project_id}/spend_alerts/{alert_id} + withRawResponse().update(params, requestOptions).thenApply { it.parse() } + + override fun list( + params: SpendAlertListParams, + requestOptions: RequestOptions, + ): CompletableFuture = + // get /organization/projects/{project_id}/spend_alerts + withRawResponse().list(params, requestOptions).thenApply { it.parse() } + + override fun delete( + params: SpendAlertDeleteParams, + requestOptions: RequestOptions, + ): CompletableFuture = + // delete /organization/projects/{project_id}/spend_alerts/{alert_id} + withRawResponse().delete(params, requestOptions).thenApply { it.parse() } + + class WithRawResponseImpl internal constructor(private val clientOptions: ClientOptions) : + SpendAlertServiceAsync.WithRawResponse { + + private val errorHandler: Handler = + errorHandler(errorBodyHandler(clientOptions.jsonMapper)) + + override fun withOptions( + modifier: Consumer + ): SpendAlertServiceAsync.WithRawResponse = + SpendAlertServiceAsyncImpl.WithRawResponseImpl( + clientOptions.toBuilder().apply(modifier::accept).build() + ) + + private val createHandler: Handler = + jsonHandler(clientOptions.jsonMapper) + + override fun create( + params: SpendAlertCreateParams, + requestOptions: RequestOptions, + ): CompletableFuture> { + // We check here instead of in the params builder because this can be specified + // positionally or in the params class. + checkRequired("projectId", params.projectId().getOrNull()) + val request = + HttpRequest.builder() + .method(HttpMethod.POST) + .baseUrl(clientOptions.baseUrl()) + .addPathSegments( + "organization", + "projects", + params._pathParam(0), + "spend_alerts", + ) + .body(json(clientOptions.jsonMapper, params._body())) + .build() + .prepareAsync( + clientOptions, + params, + SecurityOptions.builder().adminApiKeyAuth(true).build(), + ) + val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) + return request + .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } + .thenApply { response -> + errorHandler.handle(response).parseable { + response + .use { createHandler.handle(it) } + .also { + if (requestOptions.responseValidation!!) { + it.validate() + } + } + } + } + } + + private val updateHandler: Handler = + jsonHandler(clientOptions.jsonMapper) + + override fun update( + params: SpendAlertUpdateParams, + requestOptions: RequestOptions, + ): CompletableFuture> { + // We check here instead of in the params builder because this can be specified + // positionally or in the params class. + checkRequired("alertId", params.alertId().getOrNull()) + val request = + HttpRequest.builder() + .method(HttpMethod.POST) + .baseUrl(clientOptions.baseUrl()) + .addPathSegments( + "organization", + "projects", + params._pathParam(0), + "spend_alerts", + params._pathParam(1), + ) + .body(json(clientOptions.jsonMapper, params._body())) + .build() + .prepareAsync( + clientOptions, + params, + SecurityOptions.builder().adminApiKeyAuth(true).build(), + ) + val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) + return request + .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } + .thenApply { response -> + errorHandler.handle(response).parseable { + response + .use { updateHandler.handle(it) } + .also { + if (requestOptions.responseValidation!!) { + it.validate() + } + } + } + } + } + + private val listHandler: Handler = + jsonHandler(clientOptions.jsonMapper) + + override fun list( + params: SpendAlertListParams, + requestOptions: RequestOptions, + ): CompletableFuture> { + // We check here instead of in the params builder because this can be specified + // positionally or in the params class. + checkRequired("projectId", params.projectId().getOrNull()) + val request = + HttpRequest.builder() + .method(HttpMethod.GET) + .baseUrl(clientOptions.baseUrl()) + .addPathSegments( + "organization", + "projects", + params._pathParam(0), + "spend_alerts", + ) + .build() + .prepareAsync( + clientOptions, + params, + SecurityOptions.builder().adminApiKeyAuth(true).build(), + ) + val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) + return request + .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } + .thenApply { response -> + errorHandler.handle(response).parseable { + response + .use { listHandler.handle(it) } + .also { + if (requestOptions.responseValidation!!) { + it.validate() + } + } + .let { + SpendAlertListPageAsync.builder() + .service(SpendAlertServiceAsyncImpl(clientOptions)) + .streamHandlerExecutor(clientOptions.streamHandlerExecutor) + .params(params) + .response(it) + .build() + } + } + } + } + + private val deleteHandler: Handler = + jsonHandler(clientOptions.jsonMapper) + + override fun delete( + params: SpendAlertDeleteParams, + requestOptions: RequestOptions, + ): CompletableFuture> { + // We check here instead of in the params builder because this can be specified + // positionally or in the params class. + checkRequired("alertId", params.alertId().getOrNull()) + val request = + HttpRequest.builder() + .method(HttpMethod.DELETE) + .baseUrl(clientOptions.baseUrl()) + .addPathSegments( + "organization", + "projects", + params._pathParam(0), + "spend_alerts", + params._pathParam(1), + ) + .apply { params._body().ifPresent { body(json(clientOptions.jsonMapper, it)) } } + .build() + .prepareAsync( + clientOptions, + params, + SecurityOptions.builder().adminApiKeyAuth(true).build(), + ) + val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) + return request + .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } + .thenApply { response -> + errorHandler.handle(response).parseable { + response + .use { deleteHandler.handle(it) } + .also { + if (requestOptions.responseValidation!!) { + it.validate() + } + } + } + } + } + } +} diff --git a/openai-java-core/src/main/kotlin/com/openai/services/async/admin/organization/projects/groups/RoleServiceAsync.kt b/openai-java-core/src/main/kotlin/com/openai/services/async/admin/organization/projects/groups/RoleServiceAsync.kt index b98705369..139b9de5e 100644 --- a/openai-java-core/src/main/kotlin/com/openai/services/async/admin/organization/projects/groups/RoleServiceAsync.kt +++ b/openai-java-core/src/main/kotlin/com/openai/services/async/admin/organization/projects/groups/RoleServiceAsync.kt @@ -11,6 +11,8 @@ import com.openai.models.admin.organization.projects.groups.roles.RoleDeletePara import com.openai.models.admin.organization.projects.groups.roles.RoleDeleteResponse import com.openai.models.admin.organization.projects.groups.roles.RoleListPageAsync import com.openai.models.admin.organization.projects.groups.roles.RoleListParams +import com.openai.models.admin.organization.projects.groups.roles.RoleRetrieveParams +import com.openai.models.admin.organization.projects.groups.roles.RoleRetrieveResponse import java.util.concurrent.CompletableFuture import java.util.function.Consumer @@ -50,6 +52,30 @@ interface RoleServiceAsync { requestOptions: RequestOptions = RequestOptions.none(), ): CompletableFuture + /** Retrieves a project role assigned to a group. */ + fun retrieve( + roleId: String, + params: RoleRetrieveParams, + ): CompletableFuture = retrieve(roleId, params, RequestOptions.none()) + + /** @see retrieve */ + fun retrieve( + roleId: String, + params: RoleRetrieveParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture = + retrieve(params.toBuilder().roleId(roleId).build(), requestOptions) + + /** @see retrieve */ + fun retrieve(params: RoleRetrieveParams): CompletableFuture = + retrieve(params, RequestOptions.none()) + + /** @see retrieve */ + fun retrieve( + params: RoleRetrieveParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture + /** Lists the project roles assigned to a group within a project. */ fun list(groupId: String, params: RoleListParams): CompletableFuture = list(groupId, params, RequestOptions.none()) @@ -134,6 +160,37 @@ interface RoleServiceAsync { requestOptions: RequestOptions = RequestOptions.none(), ): CompletableFuture> + /** + * Returns a raw HTTP response for `get + * /projects/{project_id}/groups/{group_id}/roles/{role_id}`, but is otherwise the same as + * [RoleServiceAsync.retrieve]. + */ + fun retrieve( + roleId: String, + params: RoleRetrieveParams, + ): CompletableFuture> = + retrieve(roleId, params, RequestOptions.none()) + + /** @see retrieve */ + fun retrieve( + roleId: String, + params: RoleRetrieveParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture> = + retrieve(params.toBuilder().roleId(roleId).build(), requestOptions) + + /** @see retrieve */ + fun retrieve( + params: RoleRetrieveParams + ): CompletableFuture> = + retrieve(params, RequestOptions.none()) + + /** @see retrieve */ + fun retrieve( + params: RoleRetrieveParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture> + /** * Returns a raw HTTP response for `get /projects/{project_id}/groups/{group_id}/roles`, but * is otherwise the same as [RoleServiceAsync.list]. diff --git a/openai-java-core/src/main/kotlin/com/openai/services/async/admin/organization/projects/groups/RoleServiceAsyncImpl.kt b/openai-java-core/src/main/kotlin/com/openai/services/async/admin/organization/projects/groups/RoleServiceAsyncImpl.kt index b06a82fbe..7f5399c7f 100644 --- a/openai-java-core/src/main/kotlin/com/openai/services/async/admin/organization/projects/groups/RoleServiceAsyncImpl.kt +++ b/openai-java-core/src/main/kotlin/com/openai/services/async/admin/organization/projects/groups/RoleServiceAsyncImpl.kt @@ -24,6 +24,8 @@ import com.openai.models.admin.organization.projects.groups.roles.RoleDeleteResp import com.openai.models.admin.organization.projects.groups.roles.RoleListPageAsync import com.openai.models.admin.organization.projects.groups.roles.RoleListPageResponse import com.openai.models.admin.organization.projects.groups.roles.RoleListParams +import com.openai.models.admin.organization.projects.groups.roles.RoleRetrieveParams +import com.openai.models.admin.organization.projects.groups.roles.RoleRetrieveResponse import java.util.concurrent.CompletableFuture import java.util.function.Consumer import kotlin.jvm.optionals.getOrNull @@ -47,6 +49,13 @@ class RoleServiceAsyncImpl internal constructor(private val clientOptions: Clien // post /projects/{project_id}/groups/{group_id}/roles withRawResponse().create(params, requestOptions).thenApply { it.parse() } + override fun retrieve( + params: RoleRetrieveParams, + requestOptions: RequestOptions, + ): CompletableFuture = + // get /projects/{project_id}/groups/{group_id}/roles/{role_id} + withRawResponse().retrieve(params, requestOptions).thenApply { it.parse() } + override fun list( params: RoleListParams, requestOptions: RequestOptions, @@ -118,6 +127,50 @@ class RoleServiceAsyncImpl internal constructor(private val clientOptions: Clien } } + private val retrieveHandler: Handler = + jsonHandler(clientOptions.jsonMapper) + + override fun retrieve( + params: RoleRetrieveParams, + requestOptions: RequestOptions, + ): CompletableFuture> { + // We check here instead of in the params builder because this can be specified + // positionally or in the params class. + checkRequired("roleId", params.roleId().getOrNull()) + val request = + HttpRequest.builder() + .method(HttpMethod.GET) + .baseUrl(clientOptions.baseUrl()) + .addPathSegments( + "projects", + params._pathParam(0), + "groups", + params._pathParam(1), + "roles", + params._pathParam(2), + ) + .build() + .prepareAsync( + clientOptions, + params, + SecurityOptions.builder().adminApiKeyAuth(true).build(), + ) + val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) + return request + .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } + .thenApply { response -> + errorHandler.handle(response).parseable { + response + .use { retrieveHandler.handle(it) } + .also { + if (requestOptions.responseValidation!!) { + it.validate() + } + } + } + } + } + private val listHandler: Handler = jsonHandler(clientOptions.jsonMapper) diff --git a/openai-java-core/src/main/kotlin/com/openai/services/async/admin/organization/projects/users/RoleServiceAsync.kt b/openai-java-core/src/main/kotlin/com/openai/services/async/admin/organization/projects/users/RoleServiceAsync.kt index 1c94b22b7..72f3caff3 100644 --- a/openai-java-core/src/main/kotlin/com/openai/services/async/admin/organization/projects/users/RoleServiceAsync.kt +++ b/openai-java-core/src/main/kotlin/com/openai/services/async/admin/organization/projects/users/RoleServiceAsync.kt @@ -11,6 +11,8 @@ import com.openai.models.admin.organization.projects.users.roles.RoleDeleteParam import com.openai.models.admin.organization.projects.users.roles.RoleDeleteResponse import com.openai.models.admin.organization.projects.users.roles.RoleListPageAsync import com.openai.models.admin.organization.projects.users.roles.RoleListParams +import com.openai.models.admin.organization.projects.users.roles.RoleRetrieveParams +import com.openai.models.admin.organization.projects.users.roles.RoleRetrieveResponse import java.util.concurrent.CompletableFuture import java.util.function.Consumer @@ -50,6 +52,30 @@ interface RoleServiceAsync { requestOptions: RequestOptions = RequestOptions.none(), ): CompletableFuture + /** Retrieves a project role assigned to a user. */ + fun retrieve( + roleId: String, + params: RoleRetrieveParams, + ): CompletableFuture = retrieve(roleId, params, RequestOptions.none()) + + /** @see retrieve */ + fun retrieve( + roleId: String, + params: RoleRetrieveParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture = + retrieve(params.toBuilder().roleId(roleId).build(), requestOptions) + + /** @see retrieve */ + fun retrieve(params: RoleRetrieveParams): CompletableFuture = + retrieve(params, RequestOptions.none()) + + /** @see retrieve */ + fun retrieve( + params: RoleRetrieveParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture + /** Lists the project roles assigned to a user within a project. */ fun list(userId: String, params: RoleListParams): CompletableFuture = list(userId, params, RequestOptions.none()) @@ -134,6 +160,37 @@ interface RoleServiceAsync { requestOptions: RequestOptions = RequestOptions.none(), ): CompletableFuture> + /** + * Returns a raw HTTP response for `get + * /projects/{project_id}/users/{user_id}/roles/{role_id}`, but is otherwise the same as + * [RoleServiceAsync.retrieve]. + */ + fun retrieve( + roleId: String, + params: RoleRetrieveParams, + ): CompletableFuture> = + retrieve(roleId, params, RequestOptions.none()) + + /** @see retrieve */ + fun retrieve( + roleId: String, + params: RoleRetrieveParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture> = + retrieve(params.toBuilder().roleId(roleId).build(), requestOptions) + + /** @see retrieve */ + fun retrieve( + params: RoleRetrieveParams + ): CompletableFuture> = + retrieve(params, RequestOptions.none()) + + /** @see retrieve */ + fun retrieve( + params: RoleRetrieveParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture> + /** * Returns a raw HTTP response for `get /projects/{project_id}/users/{user_id}/roles`, but * is otherwise the same as [RoleServiceAsync.list]. diff --git a/openai-java-core/src/main/kotlin/com/openai/services/async/admin/organization/projects/users/RoleServiceAsyncImpl.kt b/openai-java-core/src/main/kotlin/com/openai/services/async/admin/organization/projects/users/RoleServiceAsyncImpl.kt index c8ec49bf3..5e637d191 100644 --- a/openai-java-core/src/main/kotlin/com/openai/services/async/admin/organization/projects/users/RoleServiceAsyncImpl.kt +++ b/openai-java-core/src/main/kotlin/com/openai/services/async/admin/organization/projects/users/RoleServiceAsyncImpl.kt @@ -24,6 +24,8 @@ import com.openai.models.admin.organization.projects.users.roles.RoleDeleteRespo import com.openai.models.admin.organization.projects.users.roles.RoleListPageAsync import com.openai.models.admin.organization.projects.users.roles.RoleListPageResponse import com.openai.models.admin.organization.projects.users.roles.RoleListParams +import com.openai.models.admin.organization.projects.users.roles.RoleRetrieveParams +import com.openai.models.admin.organization.projects.users.roles.RoleRetrieveResponse import java.util.concurrent.CompletableFuture import java.util.function.Consumer import kotlin.jvm.optionals.getOrNull @@ -47,6 +49,13 @@ class RoleServiceAsyncImpl internal constructor(private val clientOptions: Clien // post /projects/{project_id}/users/{user_id}/roles withRawResponse().create(params, requestOptions).thenApply { it.parse() } + override fun retrieve( + params: RoleRetrieveParams, + requestOptions: RequestOptions, + ): CompletableFuture = + // get /projects/{project_id}/users/{user_id}/roles/{role_id} + withRawResponse().retrieve(params, requestOptions).thenApply { it.parse() } + override fun list( params: RoleListParams, requestOptions: RequestOptions, @@ -118,6 +127,50 @@ class RoleServiceAsyncImpl internal constructor(private val clientOptions: Clien } } + private val retrieveHandler: Handler = + jsonHandler(clientOptions.jsonMapper) + + override fun retrieve( + params: RoleRetrieveParams, + requestOptions: RequestOptions, + ): CompletableFuture> { + // We check here instead of in the params builder because this can be specified + // positionally or in the params class. + checkRequired("roleId", params.roleId().getOrNull()) + val request = + HttpRequest.builder() + .method(HttpMethod.GET) + .baseUrl(clientOptions.baseUrl()) + .addPathSegments( + "projects", + params._pathParam(0), + "users", + params._pathParam(1), + "roles", + params._pathParam(2), + ) + .build() + .prepareAsync( + clientOptions, + params, + SecurityOptions.builder().adminApiKeyAuth(true).build(), + ) + val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) + return request + .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } + .thenApply { response -> + errorHandler.handle(response).parseable { + response + .use { retrieveHandler.handle(it) } + .also { + if (requestOptions.responseValidation!!) { + it.validate() + } + } + } + } + } + private val listHandler: Handler = jsonHandler(clientOptions.jsonMapper) diff --git a/openai-java-core/src/main/kotlin/com/openai/services/async/admin/organization/users/RoleServiceAsync.kt b/openai-java-core/src/main/kotlin/com/openai/services/async/admin/organization/users/RoleServiceAsync.kt index 14f9d5b69..b15b5b6d7 100644 --- a/openai-java-core/src/main/kotlin/com/openai/services/async/admin/organization/users/RoleServiceAsync.kt +++ b/openai-java-core/src/main/kotlin/com/openai/services/async/admin/organization/users/RoleServiceAsync.kt @@ -11,6 +11,8 @@ import com.openai.models.admin.organization.users.roles.RoleDeleteParams import com.openai.models.admin.organization.users.roles.RoleDeleteResponse import com.openai.models.admin.organization.users.roles.RoleListPageAsync import com.openai.models.admin.organization.users.roles.RoleListParams +import com.openai.models.admin.organization.users.roles.RoleRetrieveParams +import com.openai.models.admin.organization.users.roles.RoleRetrieveResponse import java.util.concurrent.CompletableFuture import java.util.function.Consumer @@ -50,6 +52,30 @@ interface RoleServiceAsync { requestOptions: RequestOptions = RequestOptions.none(), ): CompletableFuture + /** Retrieves an organization role assigned to a user. */ + fun retrieve( + roleId: String, + params: RoleRetrieveParams, + ): CompletableFuture = retrieve(roleId, params, RequestOptions.none()) + + /** @see retrieve */ + fun retrieve( + roleId: String, + params: RoleRetrieveParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture = + retrieve(params.toBuilder().roleId(roleId).build(), requestOptions) + + /** @see retrieve */ + fun retrieve(params: RoleRetrieveParams): CompletableFuture = + retrieve(params, RequestOptions.none()) + + /** @see retrieve */ + fun retrieve( + params: RoleRetrieveParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture + /** Lists the organization roles assigned to a user within the organization. */ fun list(userId: String): CompletableFuture = list(userId, RoleListParams.none()) @@ -144,6 +170,36 @@ interface RoleServiceAsync { requestOptions: RequestOptions = RequestOptions.none(), ): CompletableFuture> + /** + * Returns a raw HTTP response for `get /organization/users/{user_id}/roles/{role_id}`, but + * is otherwise the same as [RoleServiceAsync.retrieve]. + */ + fun retrieve( + roleId: String, + params: RoleRetrieveParams, + ): CompletableFuture> = + retrieve(roleId, params, RequestOptions.none()) + + /** @see retrieve */ + fun retrieve( + roleId: String, + params: RoleRetrieveParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture> = + retrieve(params.toBuilder().roleId(roleId).build(), requestOptions) + + /** @see retrieve */ + fun retrieve( + params: RoleRetrieveParams + ): CompletableFuture> = + retrieve(params, RequestOptions.none()) + + /** @see retrieve */ + fun retrieve( + params: RoleRetrieveParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture> + /** * Returns a raw HTTP response for `get /organization/users/{user_id}/roles`, but is * otherwise the same as [RoleServiceAsync.list]. diff --git a/openai-java-core/src/main/kotlin/com/openai/services/async/admin/organization/users/RoleServiceAsyncImpl.kt b/openai-java-core/src/main/kotlin/com/openai/services/async/admin/organization/users/RoleServiceAsyncImpl.kt index eb112193f..8c3526bdc 100644 --- a/openai-java-core/src/main/kotlin/com/openai/services/async/admin/organization/users/RoleServiceAsyncImpl.kt +++ b/openai-java-core/src/main/kotlin/com/openai/services/async/admin/organization/users/RoleServiceAsyncImpl.kt @@ -24,6 +24,8 @@ import com.openai.models.admin.organization.users.roles.RoleDeleteResponse import com.openai.models.admin.organization.users.roles.RoleListPageAsync import com.openai.models.admin.organization.users.roles.RoleListPageResponse import com.openai.models.admin.organization.users.roles.RoleListParams +import com.openai.models.admin.organization.users.roles.RoleRetrieveParams +import com.openai.models.admin.organization.users.roles.RoleRetrieveResponse import java.util.concurrent.CompletableFuture import java.util.function.Consumer import kotlin.jvm.optionals.getOrNull @@ -47,6 +49,13 @@ class RoleServiceAsyncImpl internal constructor(private val clientOptions: Clien // post /organization/users/{user_id}/roles withRawResponse().create(params, requestOptions).thenApply { it.parse() } + override fun retrieve( + params: RoleRetrieveParams, + requestOptions: RequestOptions, + ): CompletableFuture = + // get /organization/users/{user_id}/roles/{role_id} + withRawResponse().retrieve(params, requestOptions).thenApply { it.parse() } + override fun list( params: RoleListParams, requestOptions: RequestOptions, @@ -112,6 +121,49 @@ class RoleServiceAsyncImpl internal constructor(private val clientOptions: Clien } } + private val retrieveHandler: Handler = + jsonHandler(clientOptions.jsonMapper) + + override fun retrieve( + params: RoleRetrieveParams, + requestOptions: RequestOptions, + ): CompletableFuture> { + // We check here instead of in the params builder because this can be specified + // positionally or in the params class. + checkRequired("roleId", params.roleId().getOrNull()) + val request = + HttpRequest.builder() + .method(HttpMethod.GET) + .baseUrl(clientOptions.baseUrl()) + .addPathSegments( + "organization", + "users", + params._pathParam(0), + "roles", + params._pathParam(1), + ) + .build() + .prepareAsync( + clientOptions, + params, + SecurityOptions.builder().adminApiKeyAuth(true).build(), + ) + val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) + return request + .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } + .thenApply { response -> + errorHandler.handle(response).parseable { + response + .use { retrieveHandler.handle(it) } + .also { + if (requestOptions.responseValidation!!) { + it.validate() + } + } + } + } + } + private val listHandler: Handler = jsonHandler(clientOptions.jsonMapper) diff --git a/openai-java-core/src/main/kotlin/com/openai/services/blocking/admin/OrganizationService.kt b/openai-java-core/src/main/kotlin/com/openai/services/blocking/admin/OrganizationService.kt index 7d39a325f..3909362fb 100644 --- a/openai-java-core/src/main/kotlin/com/openai/services/blocking/admin/OrganizationService.kt +++ b/openai-java-core/src/main/kotlin/com/openai/services/blocking/admin/OrganizationService.kt @@ -6,10 +6,12 @@ import com.openai.core.ClientOptions import com.openai.services.blocking.admin.organization.AdminApiKeyService import com.openai.services.blocking.admin.organization.AuditLogService import com.openai.services.blocking.admin.organization.CertificateService +import com.openai.services.blocking.admin.organization.DataRetentionService import com.openai.services.blocking.admin.organization.GroupService import com.openai.services.blocking.admin.organization.InviteService import com.openai.services.blocking.admin.organization.ProjectService import com.openai.services.blocking.admin.organization.RoleService +import com.openai.services.blocking.admin.organization.SpendAlertService import com.openai.services.blocking.admin.organization.UsageService import com.openai.services.blocking.admin.organization.UserService import java.util.function.Consumer @@ -43,6 +45,10 @@ interface OrganizationService { fun roles(): RoleService + fun dataRetention(): DataRetentionService + + fun spendAlerts(): SpendAlertService + fun certificates(): CertificateService fun projects(): ProjectService @@ -76,6 +82,10 @@ interface OrganizationService { fun roles(): RoleService.WithRawResponse + fun dataRetention(): DataRetentionService.WithRawResponse + + fun spendAlerts(): SpendAlertService.WithRawResponse + fun certificates(): CertificateService.WithRawResponse fun projects(): ProjectService.WithRawResponse diff --git a/openai-java-core/src/main/kotlin/com/openai/services/blocking/admin/OrganizationServiceImpl.kt b/openai-java-core/src/main/kotlin/com/openai/services/blocking/admin/OrganizationServiceImpl.kt index eeb249f22..0459f52e0 100644 --- a/openai-java-core/src/main/kotlin/com/openai/services/blocking/admin/OrganizationServiceImpl.kt +++ b/openai-java-core/src/main/kotlin/com/openai/services/blocking/admin/OrganizationServiceImpl.kt @@ -9,6 +9,8 @@ import com.openai.services.blocking.admin.organization.AuditLogService import com.openai.services.blocking.admin.organization.AuditLogServiceImpl import com.openai.services.blocking.admin.organization.CertificateService import com.openai.services.blocking.admin.organization.CertificateServiceImpl +import com.openai.services.blocking.admin.organization.DataRetentionService +import com.openai.services.blocking.admin.organization.DataRetentionServiceImpl import com.openai.services.blocking.admin.organization.GroupService import com.openai.services.blocking.admin.organization.GroupServiceImpl import com.openai.services.blocking.admin.organization.InviteService @@ -17,6 +19,8 @@ import com.openai.services.blocking.admin.organization.ProjectService import com.openai.services.blocking.admin.organization.ProjectServiceImpl import com.openai.services.blocking.admin.organization.RoleService import com.openai.services.blocking.admin.organization.RoleServiceImpl +import com.openai.services.blocking.admin.organization.SpendAlertService +import com.openai.services.blocking.admin.organization.SpendAlertServiceImpl import com.openai.services.blocking.admin.organization.UsageService import com.openai.services.blocking.admin.organization.UsageServiceImpl import com.openai.services.blocking.admin.organization.UserService @@ -44,6 +48,12 @@ class OrganizationServiceImpl internal constructor(private val clientOptions: Cl private val roles: RoleService by lazy { RoleServiceImpl(clientOptions) } + private val dataRetention: DataRetentionService by lazy { + DataRetentionServiceImpl(clientOptions) + } + + private val spendAlerts: SpendAlertService by lazy { SpendAlertServiceImpl(clientOptions) } + private val certificates: CertificateService by lazy { CertificateServiceImpl(clientOptions) } private val projects: ProjectService by lazy { ProjectServiceImpl(clientOptions) } @@ -68,6 +78,10 @@ class OrganizationServiceImpl internal constructor(private val clientOptions: Cl override fun roles(): RoleService = roles + override fun dataRetention(): DataRetentionService = dataRetention + + override fun spendAlerts(): SpendAlertService = spendAlerts + override fun certificates(): CertificateService = certificates override fun projects(): ProjectService = projects @@ -103,6 +117,14 @@ class OrganizationServiceImpl internal constructor(private val clientOptions: Cl RoleServiceImpl.WithRawResponseImpl(clientOptions) } + private val dataRetention: DataRetentionService.WithRawResponse by lazy { + DataRetentionServiceImpl.WithRawResponseImpl(clientOptions) + } + + private val spendAlerts: SpendAlertService.WithRawResponse by lazy { + SpendAlertServiceImpl.WithRawResponseImpl(clientOptions) + } + private val certificates: CertificateService.WithRawResponse by lazy { CertificateServiceImpl.WithRawResponseImpl(clientOptions) } @@ -133,6 +155,10 @@ class OrganizationServiceImpl internal constructor(private val clientOptions: Cl override fun roles(): RoleService.WithRawResponse = roles + override fun dataRetention(): DataRetentionService.WithRawResponse = dataRetention + + override fun spendAlerts(): SpendAlertService.WithRawResponse = spendAlerts + override fun certificates(): CertificateService.WithRawResponse = certificates override fun projects(): ProjectService.WithRawResponse = projects diff --git a/openai-java-core/src/main/kotlin/com/openai/services/blocking/admin/organization/DataRetentionService.kt b/openai-java-core/src/main/kotlin/com/openai/services/blocking/admin/organization/DataRetentionService.kt new file mode 100644 index 000000000..06cf86216 --- /dev/null +++ b/openai-java-core/src/main/kotlin/com/openai/services/blocking/admin/organization/DataRetentionService.kt @@ -0,0 +1,111 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.services.blocking.admin.organization + +import com.google.errorprone.annotations.MustBeClosed +import com.openai.core.ClientOptions +import com.openai.core.RequestOptions +import com.openai.core.http.HttpResponseFor +import com.openai.models.admin.organization.dataretention.DataRetentionRetrieveParams +import com.openai.models.admin.organization.dataretention.DataRetentionUpdateParams +import com.openai.models.admin.organization.dataretention.OrganizationDataRetention +import java.util.function.Consumer + +interface DataRetentionService { + + /** + * Returns a view of this service that provides access to raw HTTP responses for each method. + */ + fun withRawResponse(): WithRawResponse + + /** + * Returns a view of this service with the given option modifications applied. + * + * The original service is not modified. + */ + fun withOptions(modifier: Consumer): DataRetentionService + + /** Retrieves organization data retention controls. */ + fun retrieve(): OrganizationDataRetention = retrieve(DataRetentionRetrieveParams.none()) + + /** @see retrieve */ + fun retrieve( + params: DataRetentionRetrieveParams = DataRetentionRetrieveParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): OrganizationDataRetention + + /** @see retrieve */ + fun retrieve( + params: DataRetentionRetrieveParams = DataRetentionRetrieveParams.none() + ): OrganizationDataRetention = retrieve(params, RequestOptions.none()) + + /** @see retrieve */ + fun retrieve(requestOptions: RequestOptions): OrganizationDataRetention = + retrieve(DataRetentionRetrieveParams.none(), requestOptions) + + /** Updates organization data retention controls. */ + fun update(params: DataRetentionUpdateParams): OrganizationDataRetention = + update(params, RequestOptions.none()) + + /** @see update */ + fun update( + params: DataRetentionUpdateParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): OrganizationDataRetention + + /** + * A view of [DataRetentionService] that provides access to raw HTTP responses for each method. + */ + interface WithRawResponse { + + /** + * Returns a view of this service with the given option modifications applied. + * + * The original service is not modified. + */ + fun withOptions( + modifier: Consumer + ): DataRetentionService.WithRawResponse + + /** + * Returns a raw HTTP response for `get /organization/data_retention`, but is otherwise the + * same as [DataRetentionService.retrieve]. + */ + @MustBeClosed + fun retrieve(): HttpResponseFor = + retrieve(DataRetentionRetrieveParams.none()) + + /** @see retrieve */ + @MustBeClosed + fun retrieve( + params: DataRetentionRetrieveParams = DataRetentionRetrieveParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): HttpResponseFor + + /** @see retrieve */ + @MustBeClosed + fun retrieve( + params: DataRetentionRetrieveParams = DataRetentionRetrieveParams.none() + ): HttpResponseFor = retrieve(params, RequestOptions.none()) + + /** @see retrieve */ + @MustBeClosed + fun retrieve(requestOptions: RequestOptions): HttpResponseFor = + retrieve(DataRetentionRetrieveParams.none(), requestOptions) + + /** + * Returns a raw HTTP response for `post /organization/data_retention`, but is otherwise the + * same as [DataRetentionService.update]. + */ + @MustBeClosed + fun update(params: DataRetentionUpdateParams): HttpResponseFor = + update(params, RequestOptions.none()) + + /** @see update */ + @MustBeClosed + fun update( + params: DataRetentionUpdateParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): HttpResponseFor + } +} diff --git a/openai-java-core/src/main/kotlin/com/openai/services/blocking/admin/organization/DataRetentionServiceImpl.kt b/openai-java-core/src/main/kotlin/com/openai/services/blocking/admin/organization/DataRetentionServiceImpl.kt new file mode 100644 index 000000000..cb67260e3 --- /dev/null +++ b/openai-java-core/src/main/kotlin/com/openai/services/blocking/admin/organization/DataRetentionServiceImpl.kt @@ -0,0 +1,126 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.services.blocking.admin.organization + +import com.openai.core.ClientOptions +import com.openai.core.RequestOptions +import com.openai.core.SecurityOptions +import com.openai.core.handlers.errorBodyHandler +import com.openai.core.handlers.errorHandler +import com.openai.core.handlers.jsonHandler +import com.openai.core.http.HttpMethod +import com.openai.core.http.HttpRequest +import com.openai.core.http.HttpResponse +import com.openai.core.http.HttpResponse.Handler +import com.openai.core.http.HttpResponseFor +import com.openai.core.http.json +import com.openai.core.http.parseable +import com.openai.core.prepare +import com.openai.models.admin.organization.dataretention.DataRetentionRetrieveParams +import com.openai.models.admin.organization.dataretention.DataRetentionUpdateParams +import com.openai.models.admin.organization.dataretention.OrganizationDataRetention +import java.util.function.Consumer + +class DataRetentionServiceImpl internal constructor(private val clientOptions: ClientOptions) : + DataRetentionService { + + private val withRawResponse: DataRetentionService.WithRawResponse by lazy { + WithRawResponseImpl(clientOptions) + } + + override fun withRawResponse(): DataRetentionService.WithRawResponse = withRawResponse + + override fun withOptions(modifier: Consumer): DataRetentionService = + DataRetentionServiceImpl(clientOptions.toBuilder().apply(modifier::accept).build()) + + override fun retrieve( + params: DataRetentionRetrieveParams, + requestOptions: RequestOptions, + ): OrganizationDataRetention = + // get /organization/data_retention + withRawResponse().retrieve(params, requestOptions).parse() + + override fun update( + params: DataRetentionUpdateParams, + requestOptions: RequestOptions, + ): OrganizationDataRetention = + // post /organization/data_retention + withRawResponse().update(params, requestOptions).parse() + + class WithRawResponseImpl internal constructor(private val clientOptions: ClientOptions) : + DataRetentionService.WithRawResponse { + + private val errorHandler: Handler = + errorHandler(errorBodyHandler(clientOptions.jsonMapper)) + + override fun withOptions( + modifier: Consumer + ): DataRetentionService.WithRawResponse = + DataRetentionServiceImpl.WithRawResponseImpl( + clientOptions.toBuilder().apply(modifier::accept).build() + ) + + private val retrieveHandler: Handler = + jsonHandler(clientOptions.jsonMapper) + + override fun retrieve( + params: DataRetentionRetrieveParams, + requestOptions: RequestOptions, + ): HttpResponseFor { + val request = + HttpRequest.builder() + .method(HttpMethod.GET) + .baseUrl(clientOptions.baseUrl()) + .addPathSegments("organization", "data_retention") + .build() + .prepare( + clientOptions, + params, + SecurityOptions.builder().adminApiKeyAuth(true).build(), + ) + val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) + val response = clientOptions.httpClient.execute(request, requestOptions) + return errorHandler.handle(response).parseable { + response + .use { retrieveHandler.handle(it) } + .also { + if (requestOptions.responseValidation!!) { + it.validate() + } + } + } + } + + private val updateHandler: Handler = + jsonHandler(clientOptions.jsonMapper) + + override fun update( + params: DataRetentionUpdateParams, + requestOptions: RequestOptions, + ): HttpResponseFor { + val request = + HttpRequest.builder() + .method(HttpMethod.POST) + .baseUrl(clientOptions.baseUrl()) + .addPathSegments("organization", "data_retention") + .body(json(clientOptions.jsonMapper, params._body())) + .build() + .prepare( + clientOptions, + params, + SecurityOptions.builder().adminApiKeyAuth(true).build(), + ) + val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) + val response = clientOptions.httpClient.execute(request, requestOptions) + return errorHandler.handle(response).parseable { + response + .use { updateHandler.handle(it) } + .also { + if (requestOptions.responseValidation!!) { + it.validate() + } + } + } + } + } +} diff --git a/openai-java-core/src/main/kotlin/com/openai/services/blocking/admin/organization/GroupService.kt b/openai-java-core/src/main/kotlin/com/openai/services/blocking/admin/organization/GroupService.kt index 843eaeb2b..54daa79d5 100644 --- a/openai-java-core/src/main/kotlin/com/openai/services/blocking/admin/organization/GroupService.kt +++ b/openai-java-core/src/main/kotlin/com/openai/services/blocking/admin/organization/GroupService.kt @@ -12,6 +12,7 @@ import com.openai.models.admin.organization.groups.GroupDeleteParams import com.openai.models.admin.organization.groups.GroupDeleteResponse import com.openai.models.admin.organization.groups.GroupListPage import com.openai.models.admin.organization.groups.GroupListParams +import com.openai.models.admin.organization.groups.GroupRetrieveParams import com.openai.models.admin.organization.groups.GroupUpdateParams import com.openai.models.admin.organization.groups.GroupUpdateResponse import com.openai.services.blocking.admin.organization.groups.RoleService @@ -45,6 +46,33 @@ interface GroupService { requestOptions: RequestOptions = RequestOptions.none(), ): Group + /** Retrieves a group. */ + fun retrieve(groupId: String): Group = retrieve(groupId, GroupRetrieveParams.none()) + + /** @see retrieve */ + fun retrieve( + groupId: String, + params: GroupRetrieveParams = GroupRetrieveParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): Group = retrieve(params.toBuilder().groupId(groupId).build(), requestOptions) + + /** @see retrieve */ + fun retrieve(groupId: String, params: GroupRetrieveParams = GroupRetrieveParams.none()): Group = + retrieve(groupId, params, RequestOptions.none()) + + /** @see retrieve */ + fun retrieve( + params: GroupRetrieveParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): Group + + /** @see retrieve */ + fun retrieve(params: GroupRetrieveParams): Group = retrieve(params, RequestOptions.none()) + + /** @see retrieve */ + fun retrieve(groupId: String, requestOptions: RequestOptions): Group = + retrieve(groupId, GroupRetrieveParams.none(), requestOptions) + /** Updates a group's information. */ fun update(groupId: String, params: GroupUpdateParams): GroupUpdateResponse = update(groupId, params, RequestOptions.none()) @@ -142,6 +170,47 @@ interface GroupService { requestOptions: RequestOptions = RequestOptions.none(), ): HttpResponseFor + /** + * Returns a raw HTTP response for `get /organization/groups/{group_id}`, but is otherwise + * the same as [GroupService.retrieve]. + */ + @MustBeClosed + fun retrieve(groupId: String): HttpResponseFor = + retrieve(groupId, GroupRetrieveParams.none()) + + /** @see retrieve */ + @MustBeClosed + fun retrieve( + groupId: String, + params: GroupRetrieveParams = GroupRetrieveParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): HttpResponseFor = + retrieve(params.toBuilder().groupId(groupId).build(), requestOptions) + + /** @see retrieve */ + @MustBeClosed + fun retrieve( + groupId: String, + params: GroupRetrieveParams = GroupRetrieveParams.none(), + ): HttpResponseFor = retrieve(groupId, params, RequestOptions.none()) + + /** @see retrieve */ + @MustBeClosed + fun retrieve( + params: GroupRetrieveParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): HttpResponseFor + + /** @see retrieve */ + @MustBeClosed + fun retrieve(params: GroupRetrieveParams): HttpResponseFor = + retrieve(params, RequestOptions.none()) + + /** @see retrieve */ + @MustBeClosed + fun retrieve(groupId: String, requestOptions: RequestOptions): HttpResponseFor = + retrieve(groupId, GroupRetrieveParams.none(), requestOptions) + /** * Returns a raw HTTP response for `post /organization/groups/{group_id}`, but is otherwise * the same as [GroupService.update]. diff --git a/openai-java-core/src/main/kotlin/com/openai/services/blocking/admin/organization/GroupServiceImpl.kt b/openai-java-core/src/main/kotlin/com/openai/services/blocking/admin/organization/GroupServiceImpl.kt index b27b4af78..121e2835e 100644 --- a/openai-java-core/src/main/kotlin/com/openai/services/blocking/admin/organization/GroupServiceImpl.kt +++ b/openai-java-core/src/main/kotlin/com/openai/services/blocking/admin/organization/GroupServiceImpl.kt @@ -24,6 +24,7 @@ import com.openai.models.admin.organization.groups.GroupDeleteResponse import com.openai.models.admin.organization.groups.GroupListPage import com.openai.models.admin.organization.groups.GroupListPageResponse import com.openai.models.admin.organization.groups.GroupListParams +import com.openai.models.admin.organization.groups.GroupRetrieveParams import com.openai.models.admin.organization.groups.GroupUpdateParams import com.openai.models.admin.organization.groups.GroupUpdateResponse import com.openai.services.blocking.admin.organization.groups.RoleService @@ -57,6 +58,10 @@ class GroupServiceImpl internal constructor(private val clientOptions: ClientOpt // post /organization/groups withRawResponse().create(params, requestOptions).parse() + override fun retrieve(params: GroupRetrieveParams, requestOptions: RequestOptions): Group = + // get /organization/groups/{group_id} + withRawResponse().retrieve(params, requestOptions).parse() + override fun update( params: GroupUpdateParams, requestOptions: RequestOptions, @@ -131,6 +136,39 @@ class GroupServiceImpl internal constructor(private val clientOptions: ClientOpt } } + private val retrieveHandler: Handler = jsonHandler(clientOptions.jsonMapper) + + override fun retrieve( + params: GroupRetrieveParams, + requestOptions: RequestOptions, + ): HttpResponseFor { + // We check here instead of in the params builder because this can be specified + // positionally or in the params class. + checkRequired("groupId", params.groupId().getOrNull()) + val request = + HttpRequest.builder() + .method(HttpMethod.GET) + .baseUrl(clientOptions.baseUrl()) + .addPathSegments("organization", "groups", params._pathParam(0)) + .build() + .prepare( + clientOptions, + params, + SecurityOptions.builder().adminApiKeyAuth(true).build(), + ) + val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) + val response = clientOptions.httpClient.execute(request, requestOptions) + return errorHandler.handle(response).parseable { + response + .use { retrieveHandler.handle(it) } + .also { + if (requestOptions.responseValidation!!) { + it.validate() + } + } + } + } + private val updateHandler: Handler = jsonHandler(clientOptions.jsonMapper) diff --git a/openai-java-core/src/main/kotlin/com/openai/services/blocking/admin/organization/ProjectService.kt b/openai-java-core/src/main/kotlin/com/openai/services/blocking/admin/organization/ProjectService.kt index f9b591515..c7e58fa69 100644 --- a/openai-java-core/src/main/kotlin/com/openai/services/blocking/admin/organization/ProjectService.kt +++ b/openai-java-core/src/main/kotlin/com/openai/services/blocking/admin/organization/ProjectService.kt @@ -15,12 +15,14 @@ import com.openai.models.admin.organization.projects.ProjectRetrieveParams import com.openai.models.admin.organization.projects.ProjectUpdateParams import com.openai.services.blocking.admin.organization.projects.ApiKeyService import com.openai.services.blocking.admin.organization.projects.CertificateService +import com.openai.services.blocking.admin.organization.projects.DataRetentionService import com.openai.services.blocking.admin.organization.projects.GroupService import com.openai.services.blocking.admin.organization.projects.HostedToolPermissionService import com.openai.services.blocking.admin.organization.projects.ModelPermissionService import com.openai.services.blocking.admin.organization.projects.RateLimitService import com.openai.services.blocking.admin.organization.projects.RoleService import com.openai.services.blocking.admin.organization.projects.ServiceAccountService +import com.openai.services.blocking.admin.organization.projects.SpendAlertService import com.openai.services.blocking.admin.organization.projects.UserService import java.util.function.Consumer @@ -54,6 +56,10 @@ interface ProjectService { fun roles(): RoleService + fun dataRetention(): DataRetentionService + + fun spendAlerts(): SpendAlertService + fun certificates(): CertificateService /** @@ -198,6 +204,10 @@ interface ProjectService { fun roles(): RoleService.WithRawResponse + fun dataRetention(): DataRetentionService.WithRawResponse + + fun spendAlerts(): SpendAlertService.WithRawResponse + fun certificates(): CertificateService.WithRawResponse /** diff --git a/openai-java-core/src/main/kotlin/com/openai/services/blocking/admin/organization/ProjectServiceImpl.kt b/openai-java-core/src/main/kotlin/com/openai/services/blocking/admin/organization/ProjectServiceImpl.kt index aacb422fd..41c8fc7ab 100644 --- a/openai-java-core/src/main/kotlin/com/openai/services/blocking/admin/organization/ProjectServiceImpl.kt +++ b/openai-java-core/src/main/kotlin/com/openai/services/blocking/admin/organization/ProjectServiceImpl.kt @@ -29,6 +29,8 @@ import com.openai.services.blocking.admin.organization.projects.ApiKeyService import com.openai.services.blocking.admin.organization.projects.ApiKeyServiceImpl import com.openai.services.blocking.admin.organization.projects.CertificateService import com.openai.services.blocking.admin.organization.projects.CertificateServiceImpl +import com.openai.services.blocking.admin.organization.projects.DataRetentionService +import com.openai.services.blocking.admin.organization.projects.DataRetentionServiceImpl import com.openai.services.blocking.admin.organization.projects.GroupService import com.openai.services.blocking.admin.organization.projects.GroupServiceImpl import com.openai.services.blocking.admin.organization.projects.HostedToolPermissionService @@ -41,6 +43,8 @@ import com.openai.services.blocking.admin.organization.projects.RoleService import com.openai.services.blocking.admin.organization.projects.RoleServiceImpl import com.openai.services.blocking.admin.organization.projects.ServiceAccountService import com.openai.services.blocking.admin.organization.projects.ServiceAccountServiceImpl +import com.openai.services.blocking.admin.organization.projects.SpendAlertService +import com.openai.services.blocking.admin.organization.projects.SpendAlertServiceImpl import com.openai.services.blocking.admin.organization.projects.UserService import com.openai.services.blocking.admin.organization.projects.UserServiceImpl import java.util.function.Consumer @@ -75,6 +79,12 @@ class ProjectServiceImpl internal constructor(private val clientOptions: ClientO private val roles: RoleService by lazy { RoleServiceImpl(clientOptions) } + private val dataRetention: DataRetentionService by lazy { + DataRetentionServiceImpl(clientOptions) + } + + private val spendAlerts: SpendAlertService by lazy { SpendAlertServiceImpl(clientOptions) } + private val certificates: CertificateService by lazy { CertificateServiceImpl(clientOptions) } override fun withRawResponse(): ProjectService.WithRawResponse = withRawResponse @@ -98,6 +108,10 @@ class ProjectServiceImpl internal constructor(private val clientOptions: ClientO override fun roles(): RoleService = roles + override fun dataRetention(): DataRetentionService = dataRetention + + override fun spendAlerts(): SpendAlertService = spendAlerts + override fun certificates(): CertificateService = certificates override fun create(params: ProjectCreateParams, requestOptions: RequestOptions): Project = @@ -158,6 +172,14 @@ class ProjectServiceImpl internal constructor(private val clientOptions: ClientO RoleServiceImpl.WithRawResponseImpl(clientOptions) } + private val dataRetention: DataRetentionService.WithRawResponse by lazy { + DataRetentionServiceImpl.WithRawResponseImpl(clientOptions) + } + + private val spendAlerts: SpendAlertService.WithRawResponse by lazy { + SpendAlertServiceImpl.WithRawResponseImpl(clientOptions) + } + private val certificates: CertificateService.WithRawResponse by lazy { CertificateServiceImpl.WithRawResponseImpl(clientOptions) } @@ -186,6 +208,10 @@ class ProjectServiceImpl internal constructor(private val clientOptions: ClientO override fun roles(): RoleService.WithRawResponse = roles + override fun dataRetention(): DataRetentionService.WithRawResponse = dataRetention + + override fun spendAlerts(): SpendAlertService.WithRawResponse = spendAlerts + override fun certificates(): CertificateService.WithRawResponse = certificates private val createHandler: Handler = jsonHandler(clientOptions.jsonMapper) diff --git a/openai-java-core/src/main/kotlin/com/openai/services/blocking/admin/organization/RoleService.kt b/openai-java-core/src/main/kotlin/com/openai/services/blocking/admin/organization/RoleService.kt index 71d64878e..90ac66c03 100644 --- a/openai-java-core/src/main/kotlin/com/openai/services/blocking/admin/organization/RoleService.kt +++ b/openai-java-core/src/main/kotlin/com/openai/services/blocking/admin/organization/RoleService.kt @@ -12,6 +12,7 @@ import com.openai.models.admin.organization.roles.RoleDeleteParams import com.openai.models.admin.organization.roles.RoleDeleteResponse import com.openai.models.admin.organization.roles.RoleListPage import com.openai.models.admin.organization.roles.RoleListParams +import com.openai.models.admin.organization.roles.RoleRetrieveParams import com.openai.models.admin.organization.roles.RoleUpdateParams import java.util.function.Consumer @@ -38,6 +39,33 @@ interface RoleService { requestOptions: RequestOptions = RequestOptions.none(), ): Role + /** Retrieves an organization role. */ + fun retrieve(roleId: String): Role = retrieve(roleId, RoleRetrieveParams.none()) + + /** @see retrieve */ + fun retrieve( + roleId: String, + params: RoleRetrieveParams = RoleRetrieveParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): Role = retrieve(params.toBuilder().roleId(roleId).build(), requestOptions) + + /** @see retrieve */ + fun retrieve(roleId: String, params: RoleRetrieveParams = RoleRetrieveParams.none()): Role = + retrieve(roleId, params, RequestOptions.none()) + + /** @see retrieve */ + fun retrieve( + params: RoleRetrieveParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): Role + + /** @see retrieve */ + fun retrieve(params: RoleRetrieveParams): Role = retrieve(params, RequestOptions.none()) + + /** @see retrieve */ + fun retrieve(roleId: String, requestOptions: RequestOptions): Role = + retrieve(roleId, RoleRetrieveParams.none(), requestOptions) + /** Updates an existing organization role. */ fun update(roleId: String): Role = update(roleId, RoleUpdateParams.none()) @@ -136,6 +164,47 @@ interface RoleService { requestOptions: RequestOptions = RequestOptions.none(), ): HttpResponseFor + /** + * Returns a raw HTTP response for `get /organization/roles/{role_id}`, but is otherwise the + * same as [RoleService.retrieve]. + */ + @MustBeClosed + fun retrieve(roleId: String): HttpResponseFor = + retrieve(roleId, RoleRetrieveParams.none()) + + /** @see retrieve */ + @MustBeClosed + fun retrieve( + roleId: String, + params: RoleRetrieveParams = RoleRetrieveParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): HttpResponseFor = + retrieve(params.toBuilder().roleId(roleId).build(), requestOptions) + + /** @see retrieve */ + @MustBeClosed + fun retrieve( + roleId: String, + params: RoleRetrieveParams = RoleRetrieveParams.none(), + ): HttpResponseFor = retrieve(roleId, params, RequestOptions.none()) + + /** @see retrieve */ + @MustBeClosed + fun retrieve( + params: RoleRetrieveParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): HttpResponseFor + + /** @see retrieve */ + @MustBeClosed + fun retrieve(params: RoleRetrieveParams): HttpResponseFor = + retrieve(params, RequestOptions.none()) + + /** @see retrieve */ + @MustBeClosed + fun retrieve(roleId: String, requestOptions: RequestOptions): HttpResponseFor = + retrieve(roleId, RoleRetrieveParams.none(), requestOptions) + /** * Returns a raw HTTP response for `post /organization/roles/{role_id}`, but is otherwise * the same as [RoleService.update]. diff --git a/openai-java-core/src/main/kotlin/com/openai/services/blocking/admin/organization/RoleServiceImpl.kt b/openai-java-core/src/main/kotlin/com/openai/services/blocking/admin/organization/RoleServiceImpl.kt index 38c1c288b..7a64dcffa 100644 --- a/openai-java-core/src/main/kotlin/com/openai/services/blocking/admin/organization/RoleServiceImpl.kt +++ b/openai-java-core/src/main/kotlin/com/openai/services/blocking/admin/organization/RoleServiceImpl.kt @@ -24,6 +24,7 @@ import com.openai.models.admin.organization.roles.RoleDeleteResponse import com.openai.models.admin.organization.roles.RoleListPage import com.openai.models.admin.organization.roles.RoleListPageResponse import com.openai.models.admin.organization.roles.RoleListParams +import com.openai.models.admin.organization.roles.RoleRetrieveParams import com.openai.models.admin.organization.roles.RoleUpdateParams import java.util.function.Consumer import kotlin.jvm.optionals.getOrNull @@ -43,6 +44,10 @@ class RoleServiceImpl internal constructor(private val clientOptions: ClientOpti // post /organization/roles withRawResponse().create(params, requestOptions).parse() + override fun retrieve(params: RoleRetrieveParams, requestOptions: RequestOptions): Role = + // get /organization/roles/{role_id} + withRawResponse().retrieve(params, requestOptions).parse() + override fun update(params: RoleUpdateParams, requestOptions: RequestOptions): Role = // post /organization/roles/{role_id} withRawResponse().update(params, requestOptions).parse() @@ -102,6 +107,39 @@ class RoleServiceImpl internal constructor(private val clientOptions: ClientOpti } } + private val retrieveHandler: Handler = jsonHandler(clientOptions.jsonMapper) + + override fun retrieve( + params: RoleRetrieveParams, + requestOptions: RequestOptions, + ): HttpResponseFor { + // We check here instead of in the params builder because this can be specified + // positionally or in the params class. + checkRequired("roleId", params.roleId().getOrNull()) + val request = + HttpRequest.builder() + .method(HttpMethod.GET) + .baseUrl(clientOptions.baseUrl()) + .addPathSegments("organization", "roles", params._pathParam(0)) + .build() + .prepare( + clientOptions, + params, + SecurityOptions.builder().adminApiKeyAuth(true).build(), + ) + val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) + val response = clientOptions.httpClient.execute(request, requestOptions) + return errorHandler.handle(response).parseable { + response + .use { retrieveHandler.handle(it) } + .also { + if (requestOptions.responseValidation!!) { + it.validate() + } + } + } + } + private val updateHandler: Handler = jsonHandler(clientOptions.jsonMapper) override fun update( diff --git a/openai-java-core/src/main/kotlin/com/openai/services/blocking/admin/organization/SpendAlertService.kt b/openai-java-core/src/main/kotlin/com/openai/services/blocking/admin/organization/SpendAlertService.kt new file mode 100644 index 000000000..21e437a5e --- /dev/null +++ b/openai-java-core/src/main/kotlin/com/openai/services/blocking/admin/organization/SpendAlertService.kt @@ -0,0 +1,240 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.services.blocking.admin.organization + +import com.google.errorprone.annotations.MustBeClosed +import com.openai.core.ClientOptions +import com.openai.core.RequestOptions +import com.openai.core.http.HttpResponseFor +import com.openai.models.admin.organization.spendalerts.OrganizationSpendAlert +import com.openai.models.admin.organization.spendalerts.OrganizationSpendAlertDeleted +import com.openai.models.admin.organization.spendalerts.SpendAlertCreateParams +import com.openai.models.admin.organization.spendalerts.SpendAlertDeleteParams +import com.openai.models.admin.organization.spendalerts.SpendAlertListPage +import com.openai.models.admin.organization.spendalerts.SpendAlertListParams +import com.openai.models.admin.organization.spendalerts.SpendAlertUpdateParams +import java.util.function.Consumer + +interface SpendAlertService { + + /** + * Returns a view of this service that provides access to raw HTTP responses for each method. + */ + fun withRawResponse(): WithRawResponse + + /** + * Returns a view of this service with the given option modifications applied. + * + * The original service is not modified. + */ + fun withOptions(modifier: Consumer): SpendAlertService + + /** Creates an organization spend alert. */ + fun create(params: SpendAlertCreateParams): OrganizationSpendAlert = + create(params, RequestOptions.none()) + + /** @see create */ + fun create( + params: SpendAlertCreateParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): OrganizationSpendAlert + + /** Updates an organization spend alert. */ + fun update(alertId: String, params: SpendAlertUpdateParams): OrganizationSpendAlert = + update(alertId, params, RequestOptions.none()) + + /** @see update */ + fun update( + alertId: String, + params: SpendAlertUpdateParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): OrganizationSpendAlert = update(params.toBuilder().alertId(alertId).build(), requestOptions) + + /** @see update */ + fun update(params: SpendAlertUpdateParams): OrganizationSpendAlert = + update(params, RequestOptions.none()) + + /** @see update */ + fun update( + params: SpendAlertUpdateParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): OrganizationSpendAlert + + /** Lists organization spend alerts. */ + fun list(): SpendAlertListPage = list(SpendAlertListParams.none()) + + /** @see list */ + fun list( + params: SpendAlertListParams = SpendAlertListParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): SpendAlertListPage + + /** @see list */ + fun list(params: SpendAlertListParams = SpendAlertListParams.none()): SpendAlertListPage = + list(params, RequestOptions.none()) + + /** @see list */ + fun list(requestOptions: RequestOptions): SpendAlertListPage = + list(SpendAlertListParams.none(), requestOptions) + + /** Deletes an organization spend alert. */ + fun delete(alertId: String): OrganizationSpendAlertDeleted = + delete(alertId, SpendAlertDeleteParams.none()) + + /** @see delete */ + fun delete( + alertId: String, + params: SpendAlertDeleteParams = SpendAlertDeleteParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): OrganizationSpendAlertDeleted = + delete(params.toBuilder().alertId(alertId).build(), requestOptions) + + /** @see delete */ + fun delete( + alertId: String, + params: SpendAlertDeleteParams = SpendAlertDeleteParams.none(), + ): OrganizationSpendAlertDeleted = delete(alertId, params, RequestOptions.none()) + + /** @see delete */ + fun delete( + params: SpendAlertDeleteParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): OrganizationSpendAlertDeleted + + /** @see delete */ + fun delete(params: SpendAlertDeleteParams): OrganizationSpendAlertDeleted = + delete(params, RequestOptions.none()) + + /** @see delete */ + fun delete(alertId: String, requestOptions: RequestOptions): OrganizationSpendAlertDeleted = + delete(alertId, SpendAlertDeleteParams.none(), requestOptions) + + /** A view of [SpendAlertService] that provides access to raw HTTP responses for each method. */ + interface WithRawResponse { + + /** + * Returns a view of this service with the given option modifications applied. + * + * The original service is not modified. + */ + fun withOptions( + modifier: Consumer + ): SpendAlertService.WithRawResponse + + /** + * Returns a raw HTTP response for `post /organization/spend_alerts`, but is otherwise the + * same as [SpendAlertService.create]. + */ + @MustBeClosed + fun create(params: SpendAlertCreateParams): HttpResponseFor = + create(params, RequestOptions.none()) + + /** @see create */ + @MustBeClosed + fun create( + params: SpendAlertCreateParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): HttpResponseFor + + /** + * Returns a raw HTTP response for `post /organization/spend_alerts/{alert_id}`, but is + * otherwise the same as [SpendAlertService.update]. + */ + @MustBeClosed + fun update( + alertId: String, + params: SpendAlertUpdateParams, + ): HttpResponseFor = update(alertId, params, RequestOptions.none()) + + /** @see update */ + @MustBeClosed + fun update( + alertId: String, + params: SpendAlertUpdateParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): HttpResponseFor = + update(params.toBuilder().alertId(alertId).build(), requestOptions) + + /** @see update */ + @MustBeClosed + fun update(params: SpendAlertUpdateParams): HttpResponseFor = + update(params, RequestOptions.none()) + + /** @see update */ + @MustBeClosed + fun update( + params: SpendAlertUpdateParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): HttpResponseFor + + /** + * Returns a raw HTTP response for `get /organization/spend_alerts`, but is otherwise the + * same as [SpendAlertService.list]. + */ + @MustBeClosed + fun list(): HttpResponseFor = list(SpendAlertListParams.none()) + + /** @see list */ + @MustBeClosed + fun list( + params: SpendAlertListParams = SpendAlertListParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): HttpResponseFor + + /** @see list */ + @MustBeClosed + fun list( + params: SpendAlertListParams = SpendAlertListParams.none() + ): HttpResponseFor = list(params, RequestOptions.none()) + + /** @see list */ + @MustBeClosed + fun list(requestOptions: RequestOptions): HttpResponseFor = + list(SpendAlertListParams.none(), requestOptions) + + /** + * Returns a raw HTTP response for `delete /organization/spend_alerts/{alert_id}`, but is + * otherwise the same as [SpendAlertService.delete]. + */ + @MustBeClosed + fun delete(alertId: String): HttpResponseFor = + delete(alertId, SpendAlertDeleteParams.none()) + + /** @see delete */ + @MustBeClosed + fun delete( + alertId: String, + params: SpendAlertDeleteParams = SpendAlertDeleteParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): HttpResponseFor = + delete(params.toBuilder().alertId(alertId).build(), requestOptions) + + /** @see delete */ + @MustBeClosed + fun delete( + alertId: String, + params: SpendAlertDeleteParams = SpendAlertDeleteParams.none(), + ): HttpResponseFor = + delete(alertId, params, RequestOptions.none()) + + /** @see delete */ + @MustBeClosed + fun delete( + params: SpendAlertDeleteParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): HttpResponseFor + + /** @see delete */ + @MustBeClosed + fun delete(params: SpendAlertDeleteParams): HttpResponseFor = + delete(params, RequestOptions.none()) + + /** @see delete */ + @MustBeClosed + fun delete( + alertId: String, + requestOptions: RequestOptions, + ): HttpResponseFor = + delete(alertId, SpendAlertDeleteParams.none(), requestOptions) + } +} diff --git a/openai-java-core/src/main/kotlin/com/openai/services/blocking/admin/organization/SpendAlertServiceImpl.kt b/openai-java-core/src/main/kotlin/com/openai/services/blocking/admin/organization/SpendAlertServiceImpl.kt new file mode 100644 index 000000000..2f295be63 --- /dev/null +++ b/openai-java-core/src/main/kotlin/com/openai/services/blocking/admin/organization/SpendAlertServiceImpl.kt @@ -0,0 +1,224 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.services.blocking.admin.organization + +import com.openai.core.ClientOptions +import com.openai.core.RequestOptions +import com.openai.core.SecurityOptions +import com.openai.core.checkRequired +import com.openai.core.handlers.errorBodyHandler +import com.openai.core.handlers.errorHandler +import com.openai.core.handlers.jsonHandler +import com.openai.core.http.HttpMethod +import com.openai.core.http.HttpRequest +import com.openai.core.http.HttpResponse +import com.openai.core.http.HttpResponse.Handler +import com.openai.core.http.HttpResponseFor +import com.openai.core.http.json +import com.openai.core.http.parseable +import com.openai.core.prepare +import com.openai.models.admin.organization.spendalerts.OrganizationSpendAlert +import com.openai.models.admin.organization.spendalerts.OrganizationSpendAlertDeleted +import com.openai.models.admin.organization.spendalerts.SpendAlertCreateParams +import com.openai.models.admin.organization.spendalerts.SpendAlertDeleteParams +import com.openai.models.admin.organization.spendalerts.SpendAlertListPage +import com.openai.models.admin.organization.spendalerts.SpendAlertListPageResponse +import com.openai.models.admin.organization.spendalerts.SpendAlertListParams +import com.openai.models.admin.organization.spendalerts.SpendAlertUpdateParams +import java.util.function.Consumer +import kotlin.jvm.optionals.getOrNull + +class SpendAlertServiceImpl internal constructor(private val clientOptions: ClientOptions) : + SpendAlertService { + + private val withRawResponse: SpendAlertService.WithRawResponse by lazy { + WithRawResponseImpl(clientOptions) + } + + override fun withRawResponse(): SpendAlertService.WithRawResponse = withRawResponse + + override fun withOptions(modifier: Consumer): SpendAlertService = + SpendAlertServiceImpl(clientOptions.toBuilder().apply(modifier::accept).build()) + + override fun create( + params: SpendAlertCreateParams, + requestOptions: RequestOptions, + ): OrganizationSpendAlert = + // post /organization/spend_alerts + withRawResponse().create(params, requestOptions).parse() + + override fun update( + params: SpendAlertUpdateParams, + requestOptions: RequestOptions, + ): OrganizationSpendAlert = + // post /organization/spend_alerts/{alert_id} + withRawResponse().update(params, requestOptions).parse() + + override fun list( + params: SpendAlertListParams, + requestOptions: RequestOptions, + ): SpendAlertListPage = + // get /organization/spend_alerts + withRawResponse().list(params, requestOptions).parse() + + override fun delete( + params: SpendAlertDeleteParams, + requestOptions: RequestOptions, + ): OrganizationSpendAlertDeleted = + // delete /organization/spend_alerts/{alert_id} + withRawResponse().delete(params, requestOptions).parse() + + class WithRawResponseImpl internal constructor(private val clientOptions: ClientOptions) : + SpendAlertService.WithRawResponse { + + private val errorHandler: Handler = + errorHandler(errorBodyHandler(clientOptions.jsonMapper)) + + override fun withOptions( + modifier: Consumer + ): SpendAlertService.WithRawResponse = + SpendAlertServiceImpl.WithRawResponseImpl( + clientOptions.toBuilder().apply(modifier::accept).build() + ) + + private val createHandler: Handler = + jsonHandler(clientOptions.jsonMapper) + + override fun create( + params: SpendAlertCreateParams, + requestOptions: RequestOptions, + ): HttpResponseFor { + val request = + HttpRequest.builder() + .method(HttpMethod.POST) + .baseUrl(clientOptions.baseUrl()) + .addPathSegments("organization", "spend_alerts") + .body(json(clientOptions.jsonMapper, params._body())) + .build() + .prepare( + clientOptions, + params, + SecurityOptions.builder().adminApiKeyAuth(true).build(), + ) + val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) + val response = clientOptions.httpClient.execute(request, requestOptions) + return errorHandler.handle(response).parseable { + response + .use { createHandler.handle(it) } + .also { + if (requestOptions.responseValidation!!) { + it.validate() + } + } + } + } + + private val updateHandler: Handler = + jsonHandler(clientOptions.jsonMapper) + + override fun update( + params: SpendAlertUpdateParams, + requestOptions: RequestOptions, + ): HttpResponseFor { + // We check here instead of in the params builder because this can be specified + // positionally or in the params class. + checkRequired("alertId", params.alertId().getOrNull()) + val request = + HttpRequest.builder() + .method(HttpMethod.POST) + .baseUrl(clientOptions.baseUrl()) + .addPathSegments("organization", "spend_alerts", params._pathParam(0)) + .body(json(clientOptions.jsonMapper, params._body())) + .build() + .prepare( + clientOptions, + params, + SecurityOptions.builder().adminApiKeyAuth(true).build(), + ) + val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) + val response = clientOptions.httpClient.execute(request, requestOptions) + return errorHandler.handle(response).parseable { + response + .use { updateHandler.handle(it) } + .also { + if (requestOptions.responseValidation!!) { + it.validate() + } + } + } + } + + private val listHandler: Handler = + jsonHandler(clientOptions.jsonMapper) + + override fun list( + params: SpendAlertListParams, + requestOptions: RequestOptions, + ): HttpResponseFor { + val request = + HttpRequest.builder() + .method(HttpMethod.GET) + .baseUrl(clientOptions.baseUrl()) + .addPathSegments("organization", "spend_alerts") + .build() + .prepare( + clientOptions, + params, + SecurityOptions.builder().adminApiKeyAuth(true).build(), + ) + val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) + val response = clientOptions.httpClient.execute(request, requestOptions) + return errorHandler.handle(response).parseable { + response + .use { listHandler.handle(it) } + .also { + if (requestOptions.responseValidation!!) { + it.validate() + } + } + .let { + SpendAlertListPage.builder() + .service(SpendAlertServiceImpl(clientOptions)) + .params(params) + .response(it) + .build() + } + } + } + + private val deleteHandler: Handler = + jsonHandler(clientOptions.jsonMapper) + + override fun delete( + params: SpendAlertDeleteParams, + requestOptions: RequestOptions, + ): HttpResponseFor { + // We check here instead of in the params builder because this can be specified + // positionally or in the params class. + checkRequired("alertId", params.alertId().getOrNull()) + val request = + HttpRequest.builder() + .method(HttpMethod.DELETE) + .baseUrl(clientOptions.baseUrl()) + .addPathSegments("organization", "spend_alerts", params._pathParam(0)) + .apply { params._body().ifPresent { body(json(clientOptions.jsonMapper, it)) } } + .build() + .prepare( + clientOptions, + params, + SecurityOptions.builder().adminApiKeyAuth(true).build(), + ) + val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) + val response = clientOptions.httpClient.execute(request, requestOptions) + return errorHandler.handle(response).parseable { + response + .use { deleteHandler.handle(it) } + .also { + if (requestOptions.responseValidation!!) { + it.validate() + } + } + } + } + } +} diff --git a/openai-java-core/src/main/kotlin/com/openai/services/blocking/admin/organization/groups/RoleService.kt b/openai-java-core/src/main/kotlin/com/openai/services/blocking/admin/organization/groups/RoleService.kt index 35acaadaa..00c3a91e6 100644 --- a/openai-java-core/src/main/kotlin/com/openai/services/blocking/admin/organization/groups/RoleService.kt +++ b/openai-java-core/src/main/kotlin/com/openai/services/blocking/admin/organization/groups/RoleService.kt @@ -12,6 +12,8 @@ import com.openai.models.admin.organization.groups.roles.RoleDeleteParams import com.openai.models.admin.organization.groups.roles.RoleDeleteResponse import com.openai.models.admin.organization.groups.roles.RoleListPage import com.openai.models.admin.organization.groups.roles.RoleListParams +import com.openai.models.admin.organization.groups.roles.RoleRetrieveParams +import com.openai.models.admin.organization.groups.roles.RoleRetrieveResponse import java.util.function.Consumer interface RoleService { @@ -48,6 +50,27 @@ interface RoleService { requestOptions: RequestOptions = RequestOptions.none(), ): RoleCreateResponse + /** Retrieves an organization role assigned to a group. */ + fun retrieve(roleId: String, params: RoleRetrieveParams): RoleRetrieveResponse = + retrieve(roleId, params, RequestOptions.none()) + + /** @see retrieve */ + fun retrieve( + roleId: String, + params: RoleRetrieveParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): RoleRetrieveResponse = retrieve(params.toBuilder().roleId(roleId).build(), requestOptions) + + /** @see retrieve */ + fun retrieve(params: RoleRetrieveParams): RoleRetrieveResponse = + retrieve(params, RequestOptions.none()) + + /** @see retrieve */ + fun retrieve( + params: RoleRetrieveParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): RoleRetrieveResponse + /** Lists the organization roles assigned to a group within the organization. */ fun list(groupId: String): RoleListPage = list(groupId, RoleListParams.none()) @@ -134,6 +157,37 @@ interface RoleService { requestOptions: RequestOptions = RequestOptions.none(), ): HttpResponseFor + /** + * Returns a raw HTTP response for `get /organization/groups/{group_id}/roles/{role_id}`, + * but is otherwise the same as [RoleService.retrieve]. + */ + @MustBeClosed + fun retrieve( + roleId: String, + params: RoleRetrieveParams, + ): HttpResponseFor = retrieve(roleId, params, RequestOptions.none()) + + /** @see retrieve */ + @MustBeClosed + fun retrieve( + roleId: String, + params: RoleRetrieveParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): HttpResponseFor = + retrieve(params.toBuilder().roleId(roleId).build(), requestOptions) + + /** @see retrieve */ + @MustBeClosed + fun retrieve(params: RoleRetrieveParams): HttpResponseFor = + retrieve(params, RequestOptions.none()) + + /** @see retrieve */ + @MustBeClosed + fun retrieve( + params: RoleRetrieveParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): HttpResponseFor + /** * Returns a raw HTTP response for `get /organization/groups/{group_id}/roles`, but is * otherwise the same as [RoleService.list]. diff --git a/openai-java-core/src/main/kotlin/com/openai/services/blocking/admin/organization/groups/RoleServiceImpl.kt b/openai-java-core/src/main/kotlin/com/openai/services/blocking/admin/organization/groups/RoleServiceImpl.kt index 44b626282..df41fe9e6 100644 --- a/openai-java-core/src/main/kotlin/com/openai/services/blocking/admin/organization/groups/RoleServiceImpl.kt +++ b/openai-java-core/src/main/kotlin/com/openai/services/blocking/admin/organization/groups/RoleServiceImpl.kt @@ -24,6 +24,8 @@ import com.openai.models.admin.organization.groups.roles.RoleDeleteResponse import com.openai.models.admin.organization.groups.roles.RoleListPage import com.openai.models.admin.organization.groups.roles.RoleListPageResponse import com.openai.models.admin.organization.groups.roles.RoleListParams +import com.openai.models.admin.organization.groups.roles.RoleRetrieveParams +import com.openai.models.admin.organization.groups.roles.RoleRetrieveResponse import java.util.function.Consumer import kotlin.jvm.optionals.getOrNull @@ -45,6 +47,13 @@ class RoleServiceImpl internal constructor(private val clientOptions: ClientOpti // post /organization/groups/{group_id}/roles withRawResponse().create(params, requestOptions).parse() + override fun retrieve( + params: RoleRetrieveParams, + requestOptions: RequestOptions, + ): RoleRetrieveResponse = + // get /organization/groups/{group_id}/roles/{role_id} + withRawResponse().retrieve(params, requestOptions).parse() + override fun list(params: RoleListParams, requestOptions: RequestOptions): RoleListPage = // get /organization/groups/{group_id}/roles withRawResponse().list(params, requestOptions).parse() @@ -104,6 +113,46 @@ class RoleServiceImpl internal constructor(private val clientOptions: ClientOpti } } + private val retrieveHandler: Handler = + jsonHandler(clientOptions.jsonMapper) + + override fun retrieve( + params: RoleRetrieveParams, + requestOptions: RequestOptions, + ): HttpResponseFor { + // We check here instead of in the params builder because this can be specified + // positionally or in the params class. + checkRequired("roleId", params.roleId().getOrNull()) + val request = + HttpRequest.builder() + .method(HttpMethod.GET) + .baseUrl(clientOptions.baseUrl()) + .addPathSegments( + "organization", + "groups", + params._pathParam(0), + "roles", + params._pathParam(1), + ) + .build() + .prepare( + clientOptions, + params, + SecurityOptions.builder().adminApiKeyAuth(true).build(), + ) + val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) + val response = clientOptions.httpClient.execute(request, requestOptions) + return errorHandler.handle(response).parseable { + response + .use { retrieveHandler.handle(it) } + .also { + if (requestOptions.responseValidation!!) { + it.validate() + } + } + } + } + private val listHandler: Handler = jsonHandler(clientOptions.jsonMapper) diff --git a/openai-java-core/src/main/kotlin/com/openai/services/blocking/admin/organization/groups/UserService.kt b/openai-java-core/src/main/kotlin/com/openai/services/blocking/admin/organization/groups/UserService.kt index 37dc6b9c0..917b9b4d9 100644 --- a/openai-java-core/src/main/kotlin/com/openai/services/blocking/admin/organization/groups/UserService.kt +++ b/openai-java-core/src/main/kotlin/com/openai/services/blocking/admin/organization/groups/UserService.kt @@ -12,6 +12,8 @@ import com.openai.models.admin.organization.groups.users.UserDeleteParams import com.openai.models.admin.organization.groups.users.UserDeleteResponse import com.openai.models.admin.organization.groups.users.UserListPage import com.openai.models.admin.organization.groups.users.UserListParams +import com.openai.models.admin.organization.groups.users.UserRetrieveParams +import com.openai.models.admin.organization.groups.users.UserRetrieveResponse import java.util.function.Consumer interface UserService { @@ -48,6 +50,27 @@ interface UserService { requestOptions: RequestOptions = RequestOptions.none(), ): UserCreateResponse + /** Retrieves a user in a group. */ + fun retrieve(userId: String, params: UserRetrieveParams): UserRetrieveResponse = + retrieve(userId, params, RequestOptions.none()) + + /** @see retrieve */ + fun retrieve( + userId: String, + params: UserRetrieveParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): UserRetrieveResponse = retrieve(params.toBuilder().userId(userId).build(), requestOptions) + + /** @see retrieve */ + fun retrieve(params: UserRetrieveParams): UserRetrieveResponse = + retrieve(params, RequestOptions.none()) + + /** @see retrieve */ + fun retrieve( + params: UserRetrieveParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): UserRetrieveResponse + /** Lists the users assigned to a group. */ fun list(groupId: String): UserListPage = list(groupId, UserListParams.none()) @@ -134,6 +157,37 @@ interface UserService { requestOptions: RequestOptions = RequestOptions.none(), ): HttpResponseFor + /** + * Returns a raw HTTP response for `get /organization/groups/{group_id}/users/{user_id}`, + * but is otherwise the same as [UserService.retrieve]. + */ + @MustBeClosed + fun retrieve( + userId: String, + params: UserRetrieveParams, + ): HttpResponseFor = retrieve(userId, params, RequestOptions.none()) + + /** @see retrieve */ + @MustBeClosed + fun retrieve( + userId: String, + params: UserRetrieveParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): HttpResponseFor = + retrieve(params.toBuilder().userId(userId).build(), requestOptions) + + /** @see retrieve */ + @MustBeClosed + fun retrieve(params: UserRetrieveParams): HttpResponseFor = + retrieve(params, RequestOptions.none()) + + /** @see retrieve */ + @MustBeClosed + fun retrieve( + params: UserRetrieveParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): HttpResponseFor + /** * Returns a raw HTTP response for `get /organization/groups/{group_id}/users`, but is * otherwise the same as [UserService.list]. diff --git a/openai-java-core/src/main/kotlin/com/openai/services/blocking/admin/organization/groups/UserServiceImpl.kt b/openai-java-core/src/main/kotlin/com/openai/services/blocking/admin/organization/groups/UserServiceImpl.kt index d2d5598f6..0409950fd 100644 --- a/openai-java-core/src/main/kotlin/com/openai/services/blocking/admin/organization/groups/UserServiceImpl.kt +++ b/openai-java-core/src/main/kotlin/com/openai/services/blocking/admin/organization/groups/UserServiceImpl.kt @@ -24,6 +24,8 @@ import com.openai.models.admin.organization.groups.users.UserDeleteResponse import com.openai.models.admin.organization.groups.users.UserListPage import com.openai.models.admin.organization.groups.users.UserListPageResponse import com.openai.models.admin.organization.groups.users.UserListParams +import com.openai.models.admin.organization.groups.users.UserRetrieveParams +import com.openai.models.admin.organization.groups.users.UserRetrieveResponse import java.util.function.Consumer import kotlin.jvm.optionals.getOrNull @@ -45,6 +47,13 @@ class UserServiceImpl internal constructor(private val clientOptions: ClientOpti // post /organization/groups/{group_id}/users withRawResponse().create(params, requestOptions).parse() + override fun retrieve( + params: UserRetrieveParams, + requestOptions: RequestOptions, + ): UserRetrieveResponse = + // get /organization/groups/{group_id}/users/{user_id} + withRawResponse().retrieve(params, requestOptions).parse() + override fun list(params: UserListParams, requestOptions: RequestOptions): UserListPage = // get /organization/groups/{group_id}/users withRawResponse().list(params, requestOptions).parse() @@ -104,6 +113,46 @@ class UserServiceImpl internal constructor(private val clientOptions: ClientOpti } } + private val retrieveHandler: Handler = + jsonHandler(clientOptions.jsonMapper) + + override fun retrieve( + params: UserRetrieveParams, + requestOptions: RequestOptions, + ): HttpResponseFor { + // We check here instead of in the params builder because this can be specified + // positionally or in the params class. + checkRequired("userId", params.userId().getOrNull()) + val request = + HttpRequest.builder() + .method(HttpMethod.GET) + .baseUrl(clientOptions.baseUrl()) + .addPathSegments( + "organization", + "groups", + params._pathParam(0), + "users", + params._pathParam(1), + ) + .build() + .prepare( + clientOptions, + params, + SecurityOptions.builder().adminApiKeyAuth(true).build(), + ) + val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) + val response = clientOptions.httpClient.execute(request, requestOptions) + return errorHandler.handle(response).parseable { + response + .use { retrieveHandler.handle(it) } + .also { + if (requestOptions.responseValidation!!) { + it.validate() + } + } + } + } + private val listHandler: Handler = jsonHandler(clientOptions.jsonMapper) diff --git a/openai-java-core/src/main/kotlin/com/openai/services/blocking/admin/organization/projects/DataRetentionService.kt b/openai-java-core/src/main/kotlin/com/openai/services/blocking/admin/organization/projects/DataRetentionService.kt new file mode 100644 index 000000000..d98e08f2b --- /dev/null +++ b/openai-java-core/src/main/kotlin/com/openai/services/blocking/admin/organization/projects/DataRetentionService.kt @@ -0,0 +1,173 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.services.blocking.admin.organization.projects + +import com.google.errorprone.annotations.MustBeClosed +import com.openai.core.ClientOptions +import com.openai.core.RequestOptions +import com.openai.core.http.HttpResponseFor +import com.openai.models.admin.organization.projects.dataretention.DataRetentionRetrieveParams +import com.openai.models.admin.organization.projects.dataretention.DataRetentionUpdateParams +import com.openai.models.admin.organization.projects.dataretention.ProjectDataRetention +import java.util.function.Consumer + +interface DataRetentionService { + + /** + * Returns a view of this service that provides access to raw HTTP responses for each method. + */ + fun withRawResponse(): WithRawResponse + + /** + * Returns a view of this service with the given option modifications applied. + * + * The original service is not modified. + */ + fun withOptions(modifier: Consumer): DataRetentionService + + /** Retrieves project data retention controls. */ + fun retrieve(projectId: String): ProjectDataRetention = + retrieve(projectId, DataRetentionRetrieveParams.none()) + + /** @see retrieve */ + fun retrieve( + projectId: String, + params: DataRetentionRetrieveParams = DataRetentionRetrieveParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): ProjectDataRetention = + retrieve(params.toBuilder().projectId(projectId).build(), requestOptions) + + /** @see retrieve */ + fun retrieve( + projectId: String, + params: DataRetentionRetrieveParams = DataRetentionRetrieveParams.none(), + ): ProjectDataRetention = retrieve(projectId, params, RequestOptions.none()) + + /** @see retrieve */ + fun retrieve( + params: DataRetentionRetrieveParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): ProjectDataRetention + + /** @see retrieve */ + fun retrieve(params: DataRetentionRetrieveParams): ProjectDataRetention = + retrieve(params, RequestOptions.none()) + + /** @see retrieve */ + fun retrieve(projectId: String, requestOptions: RequestOptions): ProjectDataRetention = + retrieve(projectId, DataRetentionRetrieveParams.none(), requestOptions) + + /** Updates project data retention controls. */ + fun update(projectId: String, params: DataRetentionUpdateParams): ProjectDataRetention = + update(projectId, params, RequestOptions.none()) + + /** @see update */ + fun update( + projectId: String, + params: DataRetentionUpdateParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): ProjectDataRetention = + update(params.toBuilder().projectId(projectId).build(), requestOptions) + + /** @see update */ + fun update(params: DataRetentionUpdateParams): ProjectDataRetention = + update(params, RequestOptions.none()) + + /** @see update */ + fun update( + params: DataRetentionUpdateParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): ProjectDataRetention + + /** + * A view of [DataRetentionService] that provides access to raw HTTP responses for each method. + */ + interface WithRawResponse { + + /** + * Returns a view of this service with the given option modifications applied. + * + * The original service is not modified. + */ + fun withOptions( + modifier: Consumer + ): DataRetentionService.WithRawResponse + + /** + * Returns a raw HTTP response for `get /organization/projects/{project_id}/data_retention`, + * but is otherwise the same as [DataRetentionService.retrieve]. + */ + @MustBeClosed + fun retrieve(projectId: String): HttpResponseFor = + retrieve(projectId, DataRetentionRetrieveParams.none()) + + /** @see retrieve */ + @MustBeClosed + fun retrieve( + projectId: String, + params: DataRetentionRetrieveParams = DataRetentionRetrieveParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): HttpResponseFor = + retrieve(params.toBuilder().projectId(projectId).build(), requestOptions) + + /** @see retrieve */ + @MustBeClosed + fun retrieve( + projectId: String, + params: DataRetentionRetrieveParams = DataRetentionRetrieveParams.none(), + ): HttpResponseFor = + retrieve(projectId, params, RequestOptions.none()) + + /** @see retrieve */ + @MustBeClosed + fun retrieve( + params: DataRetentionRetrieveParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): HttpResponseFor + + /** @see retrieve */ + @MustBeClosed + fun retrieve(params: DataRetentionRetrieveParams): HttpResponseFor = + retrieve(params, RequestOptions.none()) + + /** @see retrieve */ + @MustBeClosed + fun retrieve( + projectId: String, + requestOptions: RequestOptions, + ): HttpResponseFor = + retrieve(projectId, DataRetentionRetrieveParams.none(), requestOptions) + + /** + * Returns a raw HTTP response for `post + * /organization/projects/{project_id}/data_retention`, but is otherwise the same as + * [DataRetentionService.update]. + */ + @MustBeClosed + fun update( + projectId: String, + params: DataRetentionUpdateParams, + ): HttpResponseFor = update(projectId, params, RequestOptions.none()) + + /** @see update */ + @MustBeClosed + fun update( + projectId: String, + params: DataRetentionUpdateParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): HttpResponseFor = + update(params.toBuilder().projectId(projectId).build(), requestOptions) + + /** @see update */ + @MustBeClosed + fun update(params: DataRetentionUpdateParams): HttpResponseFor = + update(params, RequestOptions.none()) + + /** @see update */ + @MustBeClosed + fun update( + params: DataRetentionUpdateParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): HttpResponseFor + } +} diff --git a/openai-java-core/src/main/kotlin/com/openai/services/blocking/admin/organization/projects/DataRetentionServiceImpl.kt b/openai-java-core/src/main/kotlin/com/openai/services/blocking/admin/organization/projects/DataRetentionServiceImpl.kt new file mode 100644 index 000000000..4470d20f2 --- /dev/null +++ b/openai-java-core/src/main/kotlin/com/openai/services/blocking/admin/organization/projects/DataRetentionServiceImpl.kt @@ -0,0 +1,144 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.services.blocking.admin.organization.projects + +import com.openai.core.ClientOptions +import com.openai.core.RequestOptions +import com.openai.core.SecurityOptions +import com.openai.core.checkRequired +import com.openai.core.handlers.errorBodyHandler +import com.openai.core.handlers.errorHandler +import com.openai.core.handlers.jsonHandler +import com.openai.core.http.HttpMethod +import com.openai.core.http.HttpRequest +import com.openai.core.http.HttpResponse +import com.openai.core.http.HttpResponse.Handler +import com.openai.core.http.HttpResponseFor +import com.openai.core.http.json +import com.openai.core.http.parseable +import com.openai.core.prepare +import com.openai.models.admin.organization.projects.dataretention.DataRetentionRetrieveParams +import com.openai.models.admin.organization.projects.dataretention.DataRetentionUpdateParams +import com.openai.models.admin.organization.projects.dataretention.ProjectDataRetention +import java.util.function.Consumer +import kotlin.jvm.optionals.getOrNull + +class DataRetentionServiceImpl internal constructor(private val clientOptions: ClientOptions) : + DataRetentionService { + + private val withRawResponse: DataRetentionService.WithRawResponse by lazy { + WithRawResponseImpl(clientOptions) + } + + override fun withRawResponse(): DataRetentionService.WithRawResponse = withRawResponse + + override fun withOptions(modifier: Consumer): DataRetentionService = + DataRetentionServiceImpl(clientOptions.toBuilder().apply(modifier::accept).build()) + + override fun retrieve( + params: DataRetentionRetrieveParams, + requestOptions: RequestOptions, + ): ProjectDataRetention = + // get /organization/projects/{project_id}/data_retention + withRawResponse().retrieve(params, requestOptions).parse() + + override fun update( + params: DataRetentionUpdateParams, + requestOptions: RequestOptions, + ): ProjectDataRetention = + // post /organization/projects/{project_id}/data_retention + withRawResponse().update(params, requestOptions).parse() + + class WithRawResponseImpl internal constructor(private val clientOptions: ClientOptions) : + DataRetentionService.WithRawResponse { + + private val errorHandler: Handler = + errorHandler(errorBodyHandler(clientOptions.jsonMapper)) + + override fun withOptions( + modifier: Consumer + ): DataRetentionService.WithRawResponse = + DataRetentionServiceImpl.WithRawResponseImpl( + clientOptions.toBuilder().apply(modifier::accept).build() + ) + + private val retrieveHandler: Handler = + jsonHandler(clientOptions.jsonMapper) + + override fun retrieve( + params: DataRetentionRetrieveParams, + requestOptions: RequestOptions, + ): HttpResponseFor { + // We check here instead of in the params builder because this can be specified + // positionally or in the params class. + checkRequired("projectId", params.projectId().getOrNull()) + val request = + HttpRequest.builder() + .method(HttpMethod.GET) + .baseUrl(clientOptions.baseUrl()) + .addPathSegments( + "organization", + "projects", + params._pathParam(0), + "data_retention", + ) + .build() + .prepare( + clientOptions, + params, + SecurityOptions.builder().adminApiKeyAuth(true).build(), + ) + val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) + val response = clientOptions.httpClient.execute(request, requestOptions) + return errorHandler.handle(response).parseable { + response + .use { retrieveHandler.handle(it) } + .also { + if (requestOptions.responseValidation!!) { + it.validate() + } + } + } + } + + private val updateHandler: Handler = + jsonHandler(clientOptions.jsonMapper) + + override fun update( + params: DataRetentionUpdateParams, + requestOptions: RequestOptions, + ): HttpResponseFor { + // We check here instead of in the params builder because this can be specified + // positionally or in the params class. + checkRequired("projectId", params.projectId().getOrNull()) + val request = + HttpRequest.builder() + .method(HttpMethod.POST) + .baseUrl(clientOptions.baseUrl()) + .addPathSegments( + "organization", + "projects", + params._pathParam(0), + "data_retention", + ) + .body(json(clientOptions.jsonMapper, params._body())) + .build() + .prepare( + clientOptions, + params, + SecurityOptions.builder().adminApiKeyAuth(true).build(), + ) + val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) + val response = clientOptions.httpClient.execute(request, requestOptions) + return errorHandler.handle(response).parseable { + response + .use { updateHandler.handle(it) } + .also { + if (requestOptions.responseValidation!!) { + it.validate() + } + } + } + } + } +} diff --git a/openai-java-core/src/main/kotlin/com/openai/services/blocking/admin/organization/projects/GroupService.kt b/openai-java-core/src/main/kotlin/com/openai/services/blocking/admin/organization/projects/GroupService.kt index 9d371de8d..1c624076c 100644 --- a/openai-java-core/src/main/kotlin/com/openai/services/blocking/admin/organization/projects/GroupService.kt +++ b/openai-java-core/src/main/kotlin/com/openai/services/blocking/admin/organization/projects/GroupService.kt @@ -11,6 +11,7 @@ import com.openai.models.admin.organization.projects.groups.GroupDeleteParams import com.openai.models.admin.organization.projects.groups.GroupDeleteResponse import com.openai.models.admin.organization.projects.groups.GroupListPage import com.openai.models.admin.organization.projects.groups.GroupListParams +import com.openai.models.admin.organization.projects.groups.GroupRetrieveParams import com.openai.models.admin.organization.projects.groups.ProjectGroup import com.openai.services.blocking.admin.organization.projects.groups.RoleService import java.util.function.Consumer @@ -51,6 +52,27 @@ interface GroupService { requestOptions: RequestOptions = RequestOptions.none(), ): ProjectGroup + /** Retrieves a project's group. */ + fun retrieve(groupId: String, params: GroupRetrieveParams): ProjectGroup = + retrieve(groupId, params, RequestOptions.none()) + + /** @see retrieve */ + fun retrieve( + groupId: String, + params: GroupRetrieveParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): ProjectGroup = retrieve(params.toBuilder().groupId(groupId).build(), requestOptions) + + /** @see retrieve */ + fun retrieve(params: GroupRetrieveParams): ProjectGroup = + retrieve(params, RequestOptions.none()) + + /** @see retrieve */ + fun retrieve( + params: GroupRetrieveParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): ProjectGroup + /** Lists the groups that have access to a project. */ fun list(projectId: String): GroupListPage = list(projectId, GroupListParams.none()) @@ -140,6 +162,36 @@ interface GroupService { requestOptions: RequestOptions = RequestOptions.none(), ): HttpResponseFor + /** + * Returns a raw HTTP response for `get + * /organization/projects/{project_id}/groups/{group_id}`, but is otherwise the same as + * [GroupService.retrieve]. + */ + @MustBeClosed + fun retrieve(groupId: String, params: GroupRetrieveParams): HttpResponseFor = + retrieve(groupId, params, RequestOptions.none()) + + /** @see retrieve */ + @MustBeClosed + fun retrieve( + groupId: String, + params: GroupRetrieveParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): HttpResponseFor = + retrieve(params.toBuilder().groupId(groupId).build(), requestOptions) + + /** @see retrieve */ + @MustBeClosed + fun retrieve(params: GroupRetrieveParams): HttpResponseFor = + retrieve(params, RequestOptions.none()) + + /** @see retrieve */ + @MustBeClosed + fun retrieve( + params: GroupRetrieveParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): HttpResponseFor + /** * Returns a raw HTTP response for `get /organization/projects/{project_id}/groups`, but is * otherwise the same as [GroupService.list]. diff --git a/openai-java-core/src/main/kotlin/com/openai/services/blocking/admin/organization/projects/GroupServiceImpl.kt b/openai-java-core/src/main/kotlin/com/openai/services/blocking/admin/organization/projects/GroupServiceImpl.kt index 46cb54ac8..a8416b924 100644 --- a/openai-java-core/src/main/kotlin/com/openai/services/blocking/admin/organization/projects/GroupServiceImpl.kt +++ b/openai-java-core/src/main/kotlin/com/openai/services/blocking/admin/organization/projects/GroupServiceImpl.kt @@ -23,6 +23,7 @@ import com.openai.models.admin.organization.projects.groups.GroupDeleteResponse import com.openai.models.admin.organization.projects.groups.GroupListPage import com.openai.models.admin.organization.projects.groups.GroupListPageResponse import com.openai.models.admin.organization.projects.groups.GroupListParams +import com.openai.models.admin.organization.projects.groups.GroupRetrieveParams import com.openai.models.admin.organization.projects.groups.ProjectGroup import com.openai.services.blocking.admin.organization.projects.groups.RoleService import com.openai.services.blocking.admin.organization.projects.groups.RoleServiceImpl @@ -49,6 +50,13 @@ class GroupServiceImpl internal constructor(private val clientOptions: ClientOpt // post /organization/projects/{project_id}/groups withRawResponse().create(params, requestOptions).parse() + override fun retrieve( + params: GroupRetrieveParams, + requestOptions: RequestOptions, + ): ProjectGroup = + // get /organization/projects/{project_id}/groups/{group_id} + withRawResponse().retrieve(params, requestOptions).parse() + override fun list(params: GroupListParams, requestOptions: RequestOptions): GroupListPage = // get /organization/projects/{project_id}/groups withRawResponse().list(params, requestOptions).parse() @@ -114,6 +122,46 @@ class GroupServiceImpl internal constructor(private val clientOptions: ClientOpt } } + private val retrieveHandler: Handler = + jsonHandler(clientOptions.jsonMapper) + + override fun retrieve( + params: GroupRetrieveParams, + requestOptions: RequestOptions, + ): HttpResponseFor { + // We check here instead of in the params builder because this can be specified + // positionally or in the params class. + checkRequired("groupId", params.groupId().getOrNull()) + val request = + HttpRequest.builder() + .method(HttpMethod.GET) + .baseUrl(clientOptions.baseUrl()) + .addPathSegments( + "organization", + "projects", + params._pathParam(0), + "groups", + params._pathParam(1), + ) + .build() + .prepare( + clientOptions, + params, + SecurityOptions.builder().adminApiKeyAuth(true).build(), + ) + val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) + val response = clientOptions.httpClient.execute(request, requestOptions) + return errorHandler.handle(response).parseable { + response + .use { retrieveHandler.handle(it) } + .also { + if (requestOptions.responseValidation!!) { + it.validate() + } + } + } + } + private val listHandler: Handler = jsonHandler(clientOptions.jsonMapper) diff --git a/openai-java-core/src/main/kotlin/com/openai/services/blocking/admin/organization/projects/RoleService.kt b/openai-java-core/src/main/kotlin/com/openai/services/blocking/admin/organization/projects/RoleService.kt index 17ff82c20..63f23fab8 100644 --- a/openai-java-core/src/main/kotlin/com/openai/services/blocking/admin/organization/projects/RoleService.kt +++ b/openai-java-core/src/main/kotlin/com/openai/services/blocking/admin/organization/projects/RoleService.kt @@ -11,6 +11,7 @@ import com.openai.models.admin.organization.projects.roles.RoleDeleteParams import com.openai.models.admin.organization.projects.roles.RoleDeleteResponse import com.openai.models.admin.organization.projects.roles.RoleListPage import com.openai.models.admin.organization.projects.roles.RoleListParams +import com.openai.models.admin.organization.projects.roles.RoleRetrieveParams import com.openai.models.admin.organization.projects.roles.RoleUpdateParams import com.openai.models.admin.organization.roles.Role import java.util.function.Consumer @@ -49,6 +50,26 @@ interface RoleService { requestOptions: RequestOptions = RequestOptions.none(), ): Role + /** Retrieves a project role. */ + fun retrieve(roleId: String, params: RoleRetrieveParams): Role = + retrieve(roleId, params, RequestOptions.none()) + + /** @see retrieve */ + fun retrieve( + roleId: String, + params: RoleRetrieveParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): Role = retrieve(params.toBuilder().roleId(roleId).build(), requestOptions) + + /** @see retrieve */ + fun retrieve(params: RoleRetrieveParams): Role = retrieve(params, RequestOptions.none()) + + /** @see retrieve */ + fun retrieve( + params: RoleRetrieveParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): Role + /** Updates an existing project role. */ fun update(roleId: String, params: RoleUpdateParams): Role = update(roleId, params, RequestOptions.none()) @@ -155,6 +176,35 @@ interface RoleService { requestOptions: RequestOptions = RequestOptions.none(), ): HttpResponseFor + /** + * Returns a raw HTTP response for `get /projects/{project_id}/roles/{role_id}`, but is + * otherwise the same as [RoleService.retrieve]. + */ + @MustBeClosed + fun retrieve(roleId: String, params: RoleRetrieveParams): HttpResponseFor = + retrieve(roleId, params, RequestOptions.none()) + + /** @see retrieve */ + @MustBeClosed + fun retrieve( + roleId: String, + params: RoleRetrieveParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): HttpResponseFor = + retrieve(params.toBuilder().roleId(roleId).build(), requestOptions) + + /** @see retrieve */ + @MustBeClosed + fun retrieve(params: RoleRetrieveParams): HttpResponseFor = + retrieve(params, RequestOptions.none()) + + /** @see retrieve */ + @MustBeClosed + fun retrieve( + params: RoleRetrieveParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): HttpResponseFor + /** * Returns a raw HTTP response for `post /projects/{project_id}/roles/{role_id}`, but is * otherwise the same as [RoleService.update]. diff --git a/openai-java-core/src/main/kotlin/com/openai/services/blocking/admin/organization/projects/RoleServiceImpl.kt b/openai-java-core/src/main/kotlin/com/openai/services/blocking/admin/organization/projects/RoleServiceImpl.kt index a6e45783b..bb492031f 100644 --- a/openai-java-core/src/main/kotlin/com/openai/services/blocking/admin/organization/projects/RoleServiceImpl.kt +++ b/openai-java-core/src/main/kotlin/com/openai/services/blocking/admin/organization/projects/RoleServiceImpl.kt @@ -23,6 +23,7 @@ import com.openai.models.admin.organization.projects.roles.RoleDeleteResponse import com.openai.models.admin.organization.projects.roles.RoleListPage import com.openai.models.admin.organization.projects.roles.RoleListPageResponse import com.openai.models.admin.organization.projects.roles.RoleListParams +import com.openai.models.admin.organization.projects.roles.RoleRetrieveParams import com.openai.models.admin.organization.projects.roles.RoleUpdateParams import com.openai.models.admin.organization.roles.Role import java.util.function.Consumer @@ -43,6 +44,10 @@ class RoleServiceImpl internal constructor(private val clientOptions: ClientOpti // post /projects/{project_id}/roles withRawResponse().create(params, requestOptions).parse() + override fun retrieve(params: RoleRetrieveParams, requestOptions: RequestOptions): Role = + // get /projects/{project_id}/roles/{role_id} + withRawResponse().retrieve(params, requestOptions).parse() + override fun update(params: RoleUpdateParams, requestOptions: RequestOptions): Role = // post /projects/{project_id}/roles/{role_id} withRawResponse().update(params, requestOptions).parse() @@ -105,6 +110,44 @@ class RoleServiceImpl internal constructor(private val clientOptions: ClientOpti } } + private val retrieveHandler: Handler = jsonHandler(clientOptions.jsonMapper) + + override fun retrieve( + params: RoleRetrieveParams, + requestOptions: RequestOptions, + ): HttpResponseFor { + // We check here instead of in the params builder because this can be specified + // positionally or in the params class. + checkRequired("roleId", params.roleId().getOrNull()) + val request = + HttpRequest.builder() + .method(HttpMethod.GET) + .baseUrl(clientOptions.baseUrl()) + .addPathSegments( + "projects", + params._pathParam(0), + "roles", + params._pathParam(1), + ) + .build() + .prepare( + clientOptions, + params, + SecurityOptions.builder().adminApiKeyAuth(true).build(), + ) + val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) + val response = clientOptions.httpClient.execute(request, requestOptions) + return errorHandler.handle(response).parseable { + response + .use { retrieveHandler.handle(it) } + .also { + if (requestOptions.responseValidation!!) { + it.validate() + } + } + } + } + private val updateHandler: Handler = jsonHandler(clientOptions.jsonMapper) override fun update( diff --git a/openai-java-core/src/main/kotlin/com/openai/services/blocking/admin/organization/projects/ServiceAccountService.kt b/openai-java-core/src/main/kotlin/com/openai/services/blocking/admin/organization/projects/ServiceAccountService.kt index 647e478ff..5860e6c45 100644 --- a/openai-java-core/src/main/kotlin/com/openai/services/blocking/admin/organization/projects/ServiceAccountService.kt +++ b/openai-java-core/src/main/kotlin/com/openai/services/blocking/admin/organization/projects/ServiceAccountService.kt @@ -14,6 +14,7 @@ import com.openai.models.admin.organization.projects.serviceaccounts.ServiceAcco import com.openai.models.admin.organization.projects.serviceaccounts.ServiceAccountListPage import com.openai.models.admin.organization.projects.serviceaccounts.ServiceAccountListParams import com.openai.models.admin.organization.projects.serviceaccounts.ServiceAccountRetrieveParams +import com.openai.models.admin.organization.projects.serviceaccounts.ServiceAccountUpdateParams import java.util.function.Consumer interface ServiceAccountService { @@ -81,6 +82,30 @@ interface ServiceAccountService { requestOptions: RequestOptions = RequestOptions.none(), ): ProjectServiceAccount + /** Updates a service account in the project. */ + fun update( + serviceAccountId: String, + params: ServiceAccountUpdateParams, + ): ProjectServiceAccount = update(serviceAccountId, params, RequestOptions.none()) + + /** @see update */ + fun update( + serviceAccountId: String, + params: ServiceAccountUpdateParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): ProjectServiceAccount = + update(params.toBuilder().serviceAccountId(serviceAccountId).build(), requestOptions) + + /** @see update */ + fun update(params: ServiceAccountUpdateParams): ProjectServiceAccount = + update(params, RequestOptions.none()) + + /** @see update */ + fun update( + params: ServiceAccountUpdateParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): ProjectServiceAccount + /** Returns a list of service accounts in the project. */ fun list(projectId: String): ServiceAccountListPage = list(projectId, ServiceAccountListParams.none()) @@ -223,6 +248,39 @@ interface ServiceAccountService { requestOptions: RequestOptions = RequestOptions.none(), ): HttpResponseFor + /** + * Returns a raw HTTP response for `post + * /organization/projects/{project_id}/service_accounts/{service_account_id}`, but is + * otherwise the same as [ServiceAccountService.update]. + */ + @MustBeClosed + fun update( + serviceAccountId: String, + params: ServiceAccountUpdateParams, + ): HttpResponseFor = + update(serviceAccountId, params, RequestOptions.none()) + + /** @see update */ + @MustBeClosed + fun update( + serviceAccountId: String, + params: ServiceAccountUpdateParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): HttpResponseFor = + update(params.toBuilder().serviceAccountId(serviceAccountId).build(), requestOptions) + + /** @see update */ + @MustBeClosed + fun update(params: ServiceAccountUpdateParams): HttpResponseFor = + update(params, RequestOptions.none()) + + /** @see update */ + @MustBeClosed + fun update( + params: ServiceAccountUpdateParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): HttpResponseFor + /** * Returns a raw HTTP response for `get * /organization/projects/{project_id}/service_accounts`, but is otherwise the same as diff --git a/openai-java-core/src/main/kotlin/com/openai/services/blocking/admin/organization/projects/ServiceAccountServiceImpl.kt b/openai-java-core/src/main/kotlin/com/openai/services/blocking/admin/organization/projects/ServiceAccountServiceImpl.kt index 4eef3b39e..51a3e8b9c 100644 --- a/openai-java-core/src/main/kotlin/com/openai/services/blocking/admin/organization/projects/ServiceAccountServiceImpl.kt +++ b/openai-java-core/src/main/kotlin/com/openai/services/blocking/admin/organization/projects/ServiceAccountServiceImpl.kt @@ -26,6 +26,7 @@ import com.openai.models.admin.organization.projects.serviceaccounts.ServiceAcco import com.openai.models.admin.organization.projects.serviceaccounts.ServiceAccountListPageResponse import com.openai.models.admin.organization.projects.serviceaccounts.ServiceAccountListParams import com.openai.models.admin.organization.projects.serviceaccounts.ServiceAccountRetrieveParams +import com.openai.models.admin.organization.projects.serviceaccounts.ServiceAccountUpdateParams import java.util.function.Consumer import kotlin.jvm.optionals.getOrNull @@ -55,6 +56,13 @@ class ServiceAccountServiceImpl internal constructor(private val clientOptions: // get /organization/projects/{project_id}/service_accounts/{service_account_id} withRawResponse().retrieve(params, requestOptions).parse() + override fun update( + params: ServiceAccountUpdateParams, + requestOptions: RequestOptions, + ): ProjectServiceAccount = + // post /organization/projects/{project_id}/service_accounts/{service_account_id} + withRawResponse().update(params, requestOptions).parse() + override fun list( params: ServiceAccountListParams, requestOptions: RequestOptions, @@ -162,6 +170,47 @@ class ServiceAccountServiceImpl internal constructor(private val clientOptions: } } + private val updateHandler: Handler = + jsonHandler(clientOptions.jsonMapper) + + override fun update( + params: ServiceAccountUpdateParams, + requestOptions: RequestOptions, + ): HttpResponseFor { + // We check here instead of in the params builder because this can be specified + // positionally or in the params class. + checkRequired("serviceAccountId", params.serviceAccountId().getOrNull()) + val request = + HttpRequest.builder() + .method(HttpMethod.POST) + .baseUrl(clientOptions.baseUrl()) + .addPathSegments( + "organization", + "projects", + params._pathParam(0), + "service_accounts", + params._pathParam(1), + ) + .body(json(clientOptions.jsonMapper, params._body())) + .build() + .prepare( + clientOptions, + params, + SecurityOptions.builder().adminApiKeyAuth(true).build(), + ) + val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) + val response = clientOptions.httpClient.execute(request, requestOptions) + return errorHandler.handle(response).parseable { + response + .use { updateHandler.handle(it) } + .also { + if (requestOptions.responseValidation!!) { + it.validate() + } + } + } + } + private val listHandler: Handler = jsonHandler(clientOptions.jsonMapper) diff --git a/openai-java-core/src/main/kotlin/com/openai/services/blocking/admin/organization/projects/SpendAlertService.kt b/openai-java-core/src/main/kotlin/com/openai/services/blocking/admin/organization/projects/SpendAlertService.kt new file mode 100644 index 000000000..b7badc943 --- /dev/null +++ b/openai-java-core/src/main/kotlin/com/openai/services/blocking/admin/organization/projects/SpendAlertService.kt @@ -0,0 +1,277 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.services.blocking.admin.organization.projects + +import com.google.errorprone.annotations.MustBeClosed +import com.openai.core.ClientOptions +import com.openai.core.RequestOptions +import com.openai.core.http.HttpResponseFor +import com.openai.models.admin.organization.projects.spendalerts.ProjectSpendAlert +import com.openai.models.admin.organization.projects.spendalerts.ProjectSpendAlertDeleted +import com.openai.models.admin.organization.projects.spendalerts.SpendAlertCreateParams +import com.openai.models.admin.organization.projects.spendalerts.SpendAlertDeleteParams +import com.openai.models.admin.organization.projects.spendalerts.SpendAlertListPage +import com.openai.models.admin.organization.projects.spendalerts.SpendAlertListParams +import com.openai.models.admin.organization.projects.spendalerts.SpendAlertUpdateParams +import java.util.function.Consumer + +interface SpendAlertService { + + /** + * Returns a view of this service that provides access to raw HTTP responses for each method. + */ + fun withRawResponse(): WithRawResponse + + /** + * Returns a view of this service with the given option modifications applied. + * + * The original service is not modified. + */ + fun withOptions(modifier: Consumer): SpendAlertService + + /** Creates a project spend alert. */ + fun create(projectId: String, params: SpendAlertCreateParams): ProjectSpendAlert = + create(projectId, params, RequestOptions.none()) + + /** @see create */ + fun create( + projectId: String, + params: SpendAlertCreateParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): ProjectSpendAlert = create(params.toBuilder().projectId(projectId).build(), requestOptions) + + /** @see create */ + fun create(params: SpendAlertCreateParams): ProjectSpendAlert = + create(params, RequestOptions.none()) + + /** @see create */ + fun create( + params: SpendAlertCreateParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): ProjectSpendAlert + + /** Updates a project spend alert. */ + fun update(alertId: String, params: SpendAlertUpdateParams): ProjectSpendAlert = + update(alertId, params, RequestOptions.none()) + + /** @see update */ + fun update( + alertId: String, + params: SpendAlertUpdateParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): ProjectSpendAlert = update(params.toBuilder().alertId(alertId).build(), requestOptions) + + /** @see update */ + fun update(params: SpendAlertUpdateParams): ProjectSpendAlert = + update(params, RequestOptions.none()) + + /** @see update */ + fun update( + params: SpendAlertUpdateParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): ProjectSpendAlert + + /** Lists project spend alerts. */ + fun list(projectId: String): SpendAlertListPage = list(projectId, SpendAlertListParams.none()) + + /** @see list */ + fun list( + projectId: String, + params: SpendAlertListParams = SpendAlertListParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): SpendAlertListPage = list(params.toBuilder().projectId(projectId).build(), requestOptions) + + /** @see list */ + fun list( + projectId: String, + params: SpendAlertListParams = SpendAlertListParams.none(), + ): SpendAlertListPage = list(projectId, params, RequestOptions.none()) + + /** @see list */ + fun list( + params: SpendAlertListParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): SpendAlertListPage + + /** @see list */ + fun list(params: SpendAlertListParams): SpendAlertListPage = list(params, RequestOptions.none()) + + /** @see list */ + fun list(projectId: String, requestOptions: RequestOptions): SpendAlertListPage = + list(projectId, SpendAlertListParams.none(), requestOptions) + + /** Deletes a project spend alert. */ + fun delete(alertId: String, params: SpendAlertDeleteParams): ProjectSpendAlertDeleted = + delete(alertId, params, RequestOptions.none()) + + /** @see delete */ + fun delete( + alertId: String, + params: SpendAlertDeleteParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): ProjectSpendAlertDeleted = + delete(params.toBuilder().alertId(alertId).build(), requestOptions) + + /** @see delete */ + fun delete(params: SpendAlertDeleteParams): ProjectSpendAlertDeleted = + delete(params, RequestOptions.none()) + + /** @see delete */ + fun delete( + params: SpendAlertDeleteParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): ProjectSpendAlertDeleted + + /** A view of [SpendAlertService] that provides access to raw HTTP responses for each method. */ + interface WithRawResponse { + + /** + * Returns a view of this service with the given option modifications applied. + * + * The original service is not modified. + */ + fun withOptions( + modifier: Consumer + ): SpendAlertService.WithRawResponse + + /** + * Returns a raw HTTP response for `post /organization/projects/{project_id}/spend_alerts`, + * but is otherwise the same as [SpendAlertService.create]. + */ + @MustBeClosed + fun create( + projectId: String, + params: SpendAlertCreateParams, + ): HttpResponseFor = create(projectId, params, RequestOptions.none()) + + /** @see create */ + @MustBeClosed + fun create( + projectId: String, + params: SpendAlertCreateParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): HttpResponseFor = + create(params.toBuilder().projectId(projectId).build(), requestOptions) + + /** @see create */ + @MustBeClosed + fun create(params: SpendAlertCreateParams): HttpResponseFor = + create(params, RequestOptions.none()) + + /** @see create */ + @MustBeClosed + fun create( + params: SpendAlertCreateParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): HttpResponseFor + + /** + * Returns a raw HTTP response for `post + * /organization/projects/{project_id}/spend_alerts/{alert_id}`, but is otherwise the same + * as [SpendAlertService.update]. + */ + @MustBeClosed + fun update( + alertId: String, + params: SpendAlertUpdateParams, + ): HttpResponseFor = update(alertId, params, RequestOptions.none()) + + /** @see update */ + @MustBeClosed + fun update( + alertId: String, + params: SpendAlertUpdateParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): HttpResponseFor = + update(params.toBuilder().alertId(alertId).build(), requestOptions) + + /** @see update */ + @MustBeClosed + fun update(params: SpendAlertUpdateParams): HttpResponseFor = + update(params, RequestOptions.none()) + + /** @see update */ + @MustBeClosed + fun update( + params: SpendAlertUpdateParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): HttpResponseFor + + /** + * Returns a raw HTTP response for `get /organization/projects/{project_id}/spend_alerts`, + * but is otherwise the same as [SpendAlertService.list]. + */ + @MustBeClosed + fun list(projectId: String): HttpResponseFor = + list(projectId, SpendAlertListParams.none()) + + /** @see list */ + @MustBeClosed + fun list( + projectId: String, + params: SpendAlertListParams = SpendAlertListParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): HttpResponseFor = + list(params.toBuilder().projectId(projectId).build(), requestOptions) + + /** @see list */ + @MustBeClosed + fun list( + projectId: String, + params: SpendAlertListParams = SpendAlertListParams.none(), + ): HttpResponseFor = list(projectId, params, RequestOptions.none()) + + /** @see list */ + @MustBeClosed + fun list( + params: SpendAlertListParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): HttpResponseFor + + /** @see list */ + @MustBeClosed + fun list(params: SpendAlertListParams): HttpResponseFor = + list(params, RequestOptions.none()) + + /** @see list */ + @MustBeClosed + fun list( + projectId: String, + requestOptions: RequestOptions, + ): HttpResponseFor = + list(projectId, SpendAlertListParams.none(), requestOptions) + + /** + * Returns a raw HTTP response for `delete + * /organization/projects/{project_id}/spend_alerts/{alert_id}`, but is otherwise the same + * as [SpendAlertService.delete]. + */ + @MustBeClosed + fun delete( + alertId: String, + params: SpendAlertDeleteParams, + ): HttpResponseFor = + delete(alertId, params, RequestOptions.none()) + + /** @see delete */ + @MustBeClosed + fun delete( + alertId: String, + params: SpendAlertDeleteParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): HttpResponseFor = + delete(params.toBuilder().alertId(alertId).build(), requestOptions) + + /** @see delete */ + @MustBeClosed + fun delete(params: SpendAlertDeleteParams): HttpResponseFor = + delete(params, RequestOptions.none()) + + /** @see delete */ + @MustBeClosed + fun delete( + params: SpendAlertDeleteParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): HttpResponseFor + } +} diff --git a/openai-java-core/src/main/kotlin/com/openai/services/blocking/admin/organization/projects/SpendAlertServiceImpl.kt b/openai-java-core/src/main/kotlin/com/openai/services/blocking/admin/organization/projects/SpendAlertServiceImpl.kt new file mode 100644 index 000000000..9497dbd05 --- /dev/null +++ b/openai-java-core/src/main/kotlin/com/openai/services/blocking/admin/organization/projects/SpendAlertServiceImpl.kt @@ -0,0 +1,252 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.services.blocking.admin.organization.projects + +import com.openai.core.ClientOptions +import com.openai.core.RequestOptions +import com.openai.core.SecurityOptions +import com.openai.core.checkRequired +import com.openai.core.handlers.errorBodyHandler +import com.openai.core.handlers.errorHandler +import com.openai.core.handlers.jsonHandler +import com.openai.core.http.HttpMethod +import com.openai.core.http.HttpRequest +import com.openai.core.http.HttpResponse +import com.openai.core.http.HttpResponse.Handler +import com.openai.core.http.HttpResponseFor +import com.openai.core.http.json +import com.openai.core.http.parseable +import com.openai.core.prepare +import com.openai.models.admin.organization.projects.spendalerts.ProjectSpendAlert +import com.openai.models.admin.organization.projects.spendalerts.ProjectSpendAlertDeleted +import com.openai.models.admin.organization.projects.spendalerts.SpendAlertCreateParams +import com.openai.models.admin.organization.projects.spendalerts.SpendAlertDeleteParams +import com.openai.models.admin.organization.projects.spendalerts.SpendAlertListPage +import com.openai.models.admin.organization.projects.spendalerts.SpendAlertListPageResponse +import com.openai.models.admin.organization.projects.spendalerts.SpendAlertListParams +import com.openai.models.admin.organization.projects.spendalerts.SpendAlertUpdateParams +import java.util.function.Consumer +import kotlin.jvm.optionals.getOrNull + +class SpendAlertServiceImpl internal constructor(private val clientOptions: ClientOptions) : + SpendAlertService { + + private val withRawResponse: SpendAlertService.WithRawResponse by lazy { + WithRawResponseImpl(clientOptions) + } + + override fun withRawResponse(): SpendAlertService.WithRawResponse = withRawResponse + + override fun withOptions(modifier: Consumer): SpendAlertService = + SpendAlertServiceImpl(clientOptions.toBuilder().apply(modifier::accept).build()) + + override fun create( + params: SpendAlertCreateParams, + requestOptions: RequestOptions, + ): ProjectSpendAlert = + // post /organization/projects/{project_id}/spend_alerts + withRawResponse().create(params, requestOptions).parse() + + override fun update( + params: SpendAlertUpdateParams, + requestOptions: RequestOptions, + ): ProjectSpendAlert = + // post /organization/projects/{project_id}/spend_alerts/{alert_id} + withRawResponse().update(params, requestOptions).parse() + + override fun list( + params: SpendAlertListParams, + requestOptions: RequestOptions, + ): SpendAlertListPage = + // get /organization/projects/{project_id}/spend_alerts + withRawResponse().list(params, requestOptions).parse() + + override fun delete( + params: SpendAlertDeleteParams, + requestOptions: RequestOptions, + ): ProjectSpendAlertDeleted = + // delete /organization/projects/{project_id}/spend_alerts/{alert_id} + withRawResponse().delete(params, requestOptions).parse() + + class WithRawResponseImpl internal constructor(private val clientOptions: ClientOptions) : + SpendAlertService.WithRawResponse { + + private val errorHandler: Handler = + errorHandler(errorBodyHandler(clientOptions.jsonMapper)) + + override fun withOptions( + modifier: Consumer + ): SpendAlertService.WithRawResponse = + SpendAlertServiceImpl.WithRawResponseImpl( + clientOptions.toBuilder().apply(modifier::accept).build() + ) + + private val createHandler: Handler = + jsonHandler(clientOptions.jsonMapper) + + override fun create( + params: SpendAlertCreateParams, + requestOptions: RequestOptions, + ): HttpResponseFor { + // We check here instead of in the params builder because this can be specified + // positionally or in the params class. + checkRequired("projectId", params.projectId().getOrNull()) + val request = + HttpRequest.builder() + .method(HttpMethod.POST) + .baseUrl(clientOptions.baseUrl()) + .addPathSegments( + "organization", + "projects", + params._pathParam(0), + "spend_alerts", + ) + .body(json(clientOptions.jsonMapper, params._body())) + .build() + .prepare( + clientOptions, + params, + SecurityOptions.builder().adminApiKeyAuth(true).build(), + ) + val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) + val response = clientOptions.httpClient.execute(request, requestOptions) + return errorHandler.handle(response).parseable { + response + .use { createHandler.handle(it) } + .also { + if (requestOptions.responseValidation!!) { + it.validate() + } + } + } + } + + private val updateHandler: Handler = + jsonHandler(clientOptions.jsonMapper) + + override fun update( + params: SpendAlertUpdateParams, + requestOptions: RequestOptions, + ): HttpResponseFor { + // We check here instead of in the params builder because this can be specified + // positionally or in the params class. + checkRequired("alertId", params.alertId().getOrNull()) + val request = + HttpRequest.builder() + .method(HttpMethod.POST) + .baseUrl(clientOptions.baseUrl()) + .addPathSegments( + "organization", + "projects", + params._pathParam(0), + "spend_alerts", + params._pathParam(1), + ) + .body(json(clientOptions.jsonMapper, params._body())) + .build() + .prepare( + clientOptions, + params, + SecurityOptions.builder().adminApiKeyAuth(true).build(), + ) + val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) + val response = clientOptions.httpClient.execute(request, requestOptions) + return errorHandler.handle(response).parseable { + response + .use { updateHandler.handle(it) } + .also { + if (requestOptions.responseValidation!!) { + it.validate() + } + } + } + } + + private val listHandler: Handler = + jsonHandler(clientOptions.jsonMapper) + + override fun list( + params: SpendAlertListParams, + requestOptions: RequestOptions, + ): HttpResponseFor { + // We check here instead of in the params builder because this can be specified + // positionally or in the params class. + checkRequired("projectId", params.projectId().getOrNull()) + val request = + HttpRequest.builder() + .method(HttpMethod.GET) + .baseUrl(clientOptions.baseUrl()) + .addPathSegments( + "organization", + "projects", + params._pathParam(0), + "spend_alerts", + ) + .build() + .prepare( + clientOptions, + params, + SecurityOptions.builder().adminApiKeyAuth(true).build(), + ) + val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) + val response = clientOptions.httpClient.execute(request, requestOptions) + return errorHandler.handle(response).parseable { + response + .use { listHandler.handle(it) } + .also { + if (requestOptions.responseValidation!!) { + it.validate() + } + } + .let { + SpendAlertListPage.builder() + .service(SpendAlertServiceImpl(clientOptions)) + .params(params) + .response(it) + .build() + } + } + } + + private val deleteHandler: Handler = + jsonHandler(clientOptions.jsonMapper) + + override fun delete( + params: SpendAlertDeleteParams, + requestOptions: RequestOptions, + ): HttpResponseFor { + // We check here instead of in the params builder because this can be specified + // positionally or in the params class. + checkRequired("alertId", params.alertId().getOrNull()) + val request = + HttpRequest.builder() + .method(HttpMethod.DELETE) + .baseUrl(clientOptions.baseUrl()) + .addPathSegments( + "organization", + "projects", + params._pathParam(0), + "spend_alerts", + params._pathParam(1), + ) + .apply { params._body().ifPresent { body(json(clientOptions.jsonMapper, it)) } } + .build() + .prepare( + clientOptions, + params, + SecurityOptions.builder().adminApiKeyAuth(true).build(), + ) + val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) + val response = clientOptions.httpClient.execute(request, requestOptions) + return errorHandler.handle(response).parseable { + response + .use { deleteHandler.handle(it) } + .also { + if (requestOptions.responseValidation!!) { + it.validate() + } + } + } + } + } +} diff --git a/openai-java-core/src/main/kotlin/com/openai/services/blocking/admin/organization/projects/groups/RoleService.kt b/openai-java-core/src/main/kotlin/com/openai/services/blocking/admin/organization/projects/groups/RoleService.kt index 3b4ccbf97..ff1e8719b 100644 --- a/openai-java-core/src/main/kotlin/com/openai/services/blocking/admin/organization/projects/groups/RoleService.kt +++ b/openai-java-core/src/main/kotlin/com/openai/services/blocking/admin/organization/projects/groups/RoleService.kt @@ -12,6 +12,8 @@ import com.openai.models.admin.organization.projects.groups.roles.RoleDeletePara import com.openai.models.admin.organization.projects.groups.roles.RoleDeleteResponse import com.openai.models.admin.organization.projects.groups.roles.RoleListPage import com.openai.models.admin.organization.projects.groups.roles.RoleListParams +import com.openai.models.admin.organization.projects.groups.roles.RoleRetrieveParams +import com.openai.models.admin.organization.projects.groups.roles.RoleRetrieveResponse import java.util.function.Consumer interface RoleService { @@ -48,6 +50,27 @@ interface RoleService { requestOptions: RequestOptions = RequestOptions.none(), ): RoleCreateResponse + /** Retrieves a project role assigned to a group. */ + fun retrieve(roleId: String, params: RoleRetrieveParams): RoleRetrieveResponse = + retrieve(roleId, params, RequestOptions.none()) + + /** @see retrieve */ + fun retrieve( + roleId: String, + params: RoleRetrieveParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): RoleRetrieveResponse = retrieve(params.toBuilder().roleId(roleId).build(), requestOptions) + + /** @see retrieve */ + fun retrieve(params: RoleRetrieveParams): RoleRetrieveResponse = + retrieve(params, RequestOptions.none()) + + /** @see retrieve */ + fun retrieve( + params: RoleRetrieveParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): RoleRetrieveResponse + /** Lists the project roles assigned to a group within a project. */ fun list(groupId: String, params: RoleListParams): RoleListPage = list(groupId, params, RequestOptions.none()) @@ -127,6 +150,38 @@ interface RoleService { requestOptions: RequestOptions = RequestOptions.none(), ): HttpResponseFor + /** + * Returns a raw HTTP response for `get + * /projects/{project_id}/groups/{group_id}/roles/{role_id}`, but is otherwise the same as + * [RoleService.retrieve]. + */ + @MustBeClosed + fun retrieve( + roleId: String, + params: RoleRetrieveParams, + ): HttpResponseFor = retrieve(roleId, params, RequestOptions.none()) + + /** @see retrieve */ + @MustBeClosed + fun retrieve( + roleId: String, + params: RoleRetrieveParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): HttpResponseFor = + retrieve(params.toBuilder().roleId(roleId).build(), requestOptions) + + /** @see retrieve */ + @MustBeClosed + fun retrieve(params: RoleRetrieveParams): HttpResponseFor = + retrieve(params, RequestOptions.none()) + + /** @see retrieve */ + @MustBeClosed + fun retrieve( + params: RoleRetrieveParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): HttpResponseFor + /** * Returns a raw HTTP response for `get /projects/{project_id}/groups/{group_id}/roles`, but * is otherwise the same as [RoleService.list]. diff --git a/openai-java-core/src/main/kotlin/com/openai/services/blocking/admin/organization/projects/groups/RoleServiceImpl.kt b/openai-java-core/src/main/kotlin/com/openai/services/blocking/admin/organization/projects/groups/RoleServiceImpl.kt index 540194848..efa38b8cc 100644 --- a/openai-java-core/src/main/kotlin/com/openai/services/blocking/admin/organization/projects/groups/RoleServiceImpl.kt +++ b/openai-java-core/src/main/kotlin/com/openai/services/blocking/admin/organization/projects/groups/RoleServiceImpl.kt @@ -24,6 +24,8 @@ import com.openai.models.admin.organization.projects.groups.roles.RoleDeleteResp import com.openai.models.admin.organization.projects.groups.roles.RoleListPage import com.openai.models.admin.organization.projects.groups.roles.RoleListPageResponse import com.openai.models.admin.organization.projects.groups.roles.RoleListParams +import com.openai.models.admin.organization.projects.groups.roles.RoleRetrieveParams +import com.openai.models.admin.organization.projects.groups.roles.RoleRetrieveResponse import java.util.function.Consumer import kotlin.jvm.optionals.getOrNull @@ -45,6 +47,13 @@ class RoleServiceImpl internal constructor(private val clientOptions: ClientOpti // post /projects/{project_id}/groups/{group_id}/roles withRawResponse().create(params, requestOptions).parse() + override fun retrieve( + params: RoleRetrieveParams, + requestOptions: RequestOptions, + ): RoleRetrieveResponse = + // get /projects/{project_id}/groups/{group_id}/roles/{role_id} + withRawResponse().retrieve(params, requestOptions).parse() + override fun list(params: RoleListParams, requestOptions: RequestOptions): RoleListPage = // get /projects/{project_id}/groups/{group_id}/roles withRawResponse().list(params, requestOptions).parse() @@ -110,6 +119,47 @@ class RoleServiceImpl internal constructor(private val clientOptions: ClientOpti } } + private val retrieveHandler: Handler = + jsonHandler(clientOptions.jsonMapper) + + override fun retrieve( + params: RoleRetrieveParams, + requestOptions: RequestOptions, + ): HttpResponseFor { + // We check here instead of in the params builder because this can be specified + // positionally or in the params class. + checkRequired("roleId", params.roleId().getOrNull()) + val request = + HttpRequest.builder() + .method(HttpMethod.GET) + .baseUrl(clientOptions.baseUrl()) + .addPathSegments( + "projects", + params._pathParam(0), + "groups", + params._pathParam(1), + "roles", + params._pathParam(2), + ) + .build() + .prepare( + clientOptions, + params, + SecurityOptions.builder().adminApiKeyAuth(true).build(), + ) + val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) + val response = clientOptions.httpClient.execute(request, requestOptions) + return errorHandler.handle(response).parseable { + response + .use { retrieveHandler.handle(it) } + .also { + if (requestOptions.responseValidation!!) { + it.validate() + } + } + } + } + private val listHandler: Handler = jsonHandler(clientOptions.jsonMapper) diff --git a/openai-java-core/src/main/kotlin/com/openai/services/blocking/admin/organization/projects/users/RoleService.kt b/openai-java-core/src/main/kotlin/com/openai/services/blocking/admin/organization/projects/users/RoleService.kt index 00905ca25..111edf432 100644 --- a/openai-java-core/src/main/kotlin/com/openai/services/blocking/admin/organization/projects/users/RoleService.kt +++ b/openai-java-core/src/main/kotlin/com/openai/services/blocking/admin/organization/projects/users/RoleService.kt @@ -12,6 +12,8 @@ import com.openai.models.admin.organization.projects.users.roles.RoleDeleteParam import com.openai.models.admin.organization.projects.users.roles.RoleDeleteResponse import com.openai.models.admin.organization.projects.users.roles.RoleListPage import com.openai.models.admin.organization.projects.users.roles.RoleListParams +import com.openai.models.admin.organization.projects.users.roles.RoleRetrieveParams +import com.openai.models.admin.organization.projects.users.roles.RoleRetrieveResponse import java.util.function.Consumer interface RoleService { @@ -48,6 +50,27 @@ interface RoleService { requestOptions: RequestOptions = RequestOptions.none(), ): RoleCreateResponse + /** Retrieves a project role assigned to a user. */ + fun retrieve(roleId: String, params: RoleRetrieveParams): RoleRetrieveResponse = + retrieve(roleId, params, RequestOptions.none()) + + /** @see retrieve */ + fun retrieve( + roleId: String, + params: RoleRetrieveParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): RoleRetrieveResponse = retrieve(params.toBuilder().roleId(roleId).build(), requestOptions) + + /** @see retrieve */ + fun retrieve(params: RoleRetrieveParams): RoleRetrieveResponse = + retrieve(params, RequestOptions.none()) + + /** @see retrieve */ + fun retrieve( + params: RoleRetrieveParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): RoleRetrieveResponse + /** Lists the project roles assigned to a user within a project. */ fun list(userId: String, params: RoleListParams): RoleListPage = list(userId, params, RequestOptions.none()) @@ -127,6 +150,38 @@ interface RoleService { requestOptions: RequestOptions = RequestOptions.none(), ): HttpResponseFor + /** + * Returns a raw HTTP response for `get + * /projects/{project_id}/users/{user_id}/roles/{role_id}`, but is otherwise the same as + * [RoleService.retrieve]. + */ + @MustBeClosed + fun retrieve( + roleId: String, + params: RoleRetrieveParams, + ): HttpResponseFor = retrieve(roleId, params, RequestOptions.none()) + + /** @see retrieve */ + @MustBeClosed + fun retrieve( + roleId: String, + params: RoleRetrieveParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): HttpResponseFor = + retrieve(params.toBuilder().roleId(roleId).build(), requestOptions) + + /** @see retrieve */ + @MustBeClosed + fun retrieve(params: RoleRetrieveParams): HttpResponseFor = + retrieve(params, RequestOptions.none()) + + /** @see retrieve */ + @MustBeClosed + fun retrieve( + params: RoleRetrieveParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): HttpResponseFor + /** * Returns a raw HTTP response for `get /projects/{project_id}/users/{user_id}/roles`, but * is otherwise the same as [RoleService.list]. diff --git a/openai-java-core/src/main/kotlin/com/openai/services/blocking/admin/organization/projects/users/RoleServiceImpl.kt b/openai-java-core/src/main/kotlin/com/openai/services/blocking/admin/organization/projects/users/RoleServiceImpl.kt index c51078048..f36918e5a 100644 --- a/openai-java-core/src/main/kotlin/com/openai/services/blocking/admin/organization/projects/users/RoleServiceImpl.kt +++ b/openai-java-core/src/main/kotlin/com/openai/services/blocking/admin/organization/projects/users/RoleServiceImpl.kt @@ -24,6 +24,8 @@ import com.openai.models.admin.organization.projects.users.roles.RoleDeleteRespo import com.openai.models.admin.organization.projects.users.roles.RoleListPage import com.openai.models.admin.organization.projects.users.roles.RoleListPageResponse import com.openai.models.admin.organization.projects.users.roles.RoleListParams +import com.openai.models.admin.organization.projects.users.roles.RoleRetrieveParams +import com.openai.models.admin.organization.projects.users.roles.RoleRetrieveResponse import java.util.function.Consumer import kotlin.jvm.optionals.getOrNull @@ -45,6 +47,13 @@ class RoleServiceImpl internal constructor(private val clientOptions: ClientOpti // post /projects/{project_id}/users/{user_id}/roles withRawResponse().create(params, requestOptions).parse() + override fun retrieve( + params: RoleRetrieveParams, + requestOptions: RequestOptions, + ): RoleRetrieveResponse = + // get /projects/{project_id}/users/{user_id}/roles/{role_id} + withRawResponse().retrieve(params, requestOptions).parse() + override fun list(params: RoleListParams, requestOptions: RequestOptions): RoleListPage = // get /projects/{project_id}/users/{user_id}/roles withRawResponse().list(params, requestOptions).parse() @@ -110,6 +119,47 @@ class RoleServiceImpl internal constructor(private val clientOptions: ClientOpti } } + private val retrieveHandler: Handler = + jsonHandler(clientOptions.jsonMapper) + + override fun retrieve( + params: RoleRetrieveParams, + requestOptions: RequestOptions, + ): HttpResponseFor { + // We check here instead of in the params builder because this can be specified + // positionally or in the params class. + checkRequired("roleId", params.roleId().getOrNull()) + val request = + HttpRequest.builder() + .method(HttpMethod.GET) + .baseUrl(clientOptions.baseUrl()) + .addPathSegments( + "projects", + params._pathParam(0), + "users", + params._pathParam(1), + "roles", + params._pathParam(2), + ) + .build() + .prepare( + clientOptions, + params, + SecurityOptions.builder().adminApiKeyAuth(true).build(), + ) + val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) + val response = clientOptions.httpClient.execute(request, requestOptions) + return errorHandler.handle(response).parseable { + response + .use { retrieveHandler.handle(it) } + .also { + if (requestOptions.responseValidation!!) { + it.validate() + } + } + } + } + private val listHandler: Handler = jsonHandler(clientOptions.jsonMapper) diff --git a/openai-java-core/src/main/kotlin/com/openai/services/blocking/admin/organization/users/RoleService.kt b/openai-java-core/src/main/kotlin/com/openai/services/blocking/admin/organization/users/RoleService.kt index 34d0948ca..bff8b40bc 100644 --- a/openai-java-core/src/main/kotlin/com/openai/services/blocking/admin/organization/users/RoleService.kt +++ b/openai-java-core/src/main/kotlin/com/openai/services/blocking/admin/organization/users/RoleService.kt @@ -12,6 +12,8 @@ import com.openai.models.admin.organization.users.roles.RoleDeleteParams import com.openai.models.admin.organization.users.roles.RoleDeleteResponse import com.openai.models.admin.organization.users.roles.RoleListPage import com.openai.models.admin.organization.users.roles.RoleListParams +import com.openai.models.admin.organization.users.roles.RoleRetrieveParams +import com.openai.models.admin.organization.users.roles.RoleRetrieveResponse import java.util.function.Consumer interface RoleService { @@ -48,6 +50,27 @@ interface RoleService { requestOptions: RequestOptions = RequestOptions.none(), ): RoleCreateResponse + /** Retrieves an organization role assigned to a user. */ + fun retrieve(roleId: String, params: RoleRetrieveParams): RoleRetrieveResponse = + retrieve(roleId, params, RequestOptions.none()) + + /** @see retrieve */ + fun retrieve( + roleId: String, + params: RoleRetrieveParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): RoleRetrieveResponse = retrieve(params.toBuilder().roleId(roleId).build(), requestOptions) + + /** @see retrieve */ + fun retrieve(params: RoleRetrieveParams): RoleRetrieveResponse = + retrieve(params, RequestOptions.none()) + + /** @see retrieve */ + fun retrieve( + params: RoleRetrieveParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): RoleRetrieveResponse + /** Lists the organization roles assigned to a user within the organization. */ fun list(userId: String): RoleListPage = list(userId, RoleListParams.none()) @@ -134,6 +157,37 @@ interface RoleService { requestOptions: RequestOptions = RequestOptions.none(), ): HttpResponseFor + /** + * Returns a raw HTTP response for `get /organization/users/{user_id}/roles/{role_id}`, but + * is otherwise the same as [RoleService.retrieve]. + */ + @MustBeClosed + fun retrieve( + roleId: String, + params: RoleRetrieveParams, + ): HttpResponseFor = retrieve(roleId, params, RequestOptions.none()) + + /** @see retrieve */ + @MustBeClosed + fun retrieve( + roleId: String, + params: RoleRetrieveParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): HttpResponseFor = + retrieve(params.toBuilder().roleId(roleId).build(), requestOptions) + + /** @see retrieve */ + @MustBeClosed + fun retrieve(params: RoleRetrieveParams): HttpResponseFor = + retrieve(params, RequestOptions.none()) + + /** @see retrieve */ + @MustBeClosed + fun retrieve( + params: RoleRetrieveParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): HttpResponseFor + /** * Returns a raw HTTP response for `get /organization/users/{user_id}/roles`, but is * otherwise the same as [RoleService.list]. diff --git a/openai-java-core/src/main/kotlin/com/openai/services/blocking/admin/organization/users/RoleServiceImpl.kt b/openai-java-core/src/main/kotlin/com/openai/services/blocking/admin/organization/users/RoleServiceImpl.kt index ed0091e92..ff92984ea 100644 --- a/openai-java-core/src/main/kotlin/com/openai/services/blocking/admin/organization/users/RoleServiceImpl.kt +++ b/openai-java-core/src/main/kotlin/com/openai/services/blocking/admin/organization/users/RoleServiceImpl.kt @@ -24,6 +24,8 @@ import com.openai.models.admin.organization.users.roles.RoleDeleteResponse import com.openai.models.admin.organization.users.roles.RoleListPage import com.openai.models.admin.organization.users.roles.RoleListPageResponse import com.openai.models.admin.organization.users.roles.RoleListParams +import com.openai.models.admin.organization.users.roles.RoleRetrieveParams +import com.openai.models.admin.organization.users.roles.RoleRetrieveResponse import java.util.function.Consumer import kotlin.jvm.optionals.getOrNull @@ -45,6 +47,13 @@ class RoleServiceImpl internal constructor(private val clientOptions: ClientOpti // post /organization/users/{user_id}/roles withRawResponse().create(params, requestOptions).parse() + override fun retrieve( + params: RoleRetrieveParams, + requestOptions: RequestOptions, + ): RoleRetrieveResponse = + // get /organization/users/{user_id}/roles/{role_id} + withRawResponse().retrieve(params, requestOptions).parse() + override fun list(params: RoleListParams, requestOptions: RequestOptions): RoleListPage = // get /organization/users/{user_id}/roles withRawResponse().list(params, requestOptions).parse() @@ -104,6 +113,46 @@ class RoleServiceImpl internal constructor(private val clientOptions: ClientOpti } } + private val retrieveHandler: Handler = + jsonHandler(clientOptions.jsonMapper) + + override fun retrieve( + params: RoleRetrieveParams, + requestOptions: RequestOptions, + ): HttpResponseFor { + // We check here instead of in the params builder because this can be specified + // positionally or in the params class. + checkRequired("roleId", params.roleId().getOrNull()) + val request = + HttpRequest.builder() + .method(HttpMethod.GET) + .baseUrl(clientOptions.baseUrl()) + .addPathSegments( + "organization", + "users", + params._pathParam(0), + "roles", + params._pathParam(1), + ) + .build() + .prepare( + clientOptions, + params, + SecurityOptions.builder().adminApiKeyAuth(true).build(), + ) + val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) + val response = clientOptions.httpClient.execute(request, requestOptions) + return errorHandler.handle(response).parseable { + response + .use { retrieveHandler.handle(it) } + .also { + if (requestOptions.responseValidation!!) { + it.validate() + } + } + } + } + private val listHandler: Handler = jsonHandler(clientOptions.jsonMapper) diff --git a/openai-java-core/src/test/kotlin/com/openai/models/admin/organization/dataretention/DataRetentionRetrieveParamsTest.kt b/openai-java-core/src/test/kotlin/com/openai/models/admin/organization/dataretention/DataRetentionRetrieveParamsTest.kt new file mode 100644 index 000000000..f38ffcfcb --- /dev/null +++ b/openai-java-core/src/test/kotlin/com/openai/models/admin/organization/dataretention/DataRetentionRetrieveParamsTest.kt @@ -0,0 +1,13 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.models.admin.organization.dataretention + +import org.junit.jupiter.api.Test + +internal class DataRetentionRetrieveParamsTest { + + @Test + fun create() { + DataRetentionRetrieveParams.builder().build() + } +} diff --git a/openai-java-core/src/test/kotlin/com/openai/models/admin/organization/dataretention/DataRetentionUpdateParamsTest.kt b/openai-java-core/src/test/kotlin/com/openai/models/admin/organization/dataretention/DataRetentionUpdateParamsTest.kt new file mode 100644 index 000000000..69973a0a4 --- /dev/null +++ b/openai-java-core/src/test/kotlin/com/openai/models/admin/organization/dataretention/DataRetentionUpdateParamsTest.kt @@ -0,0 +1,29 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.models.admin.organization.dataretention + +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test + +internal class DataRetentionUpdateParamsTest { + + @Test + fun create() { + DataRetentionUpdateParams.builder() + .retentionType(DataRetentionUpdateParams.RetentionType.ZERO_DATA_RETENTION) + .build() + } + + @Test + fun body() { + val params = + DataRetentionUpdateParams.builder() + .retentionType(DataRetentionUpdateParams.RetentionType.ZERO_DATA_RETENTION) + .build() + + val body = params._body() + + assertThat(body.retentionType()) + .isEqualTo(DataRetentionUpdateParams.RetentionType.ZERO_DATA_RETENTION) + } +} diff --git a/openai-java-core/src/test/kotlin/com/openai/models/admin/organization/dataretention/OrganizationDataRetentionTest.kt b/openai-java-core/src/test/kotlin/com/openai/models/admin/organization/dataretention/OrganizationDataRetentionTest.kt new file mode 100644 index 000000000..7d522bdd0 --- /dev/null +++ b/openai-java-core/src/test/kotlin/com/openai/models/admin/organization/dataretention/OrganizationDataRetentionTest.kt @@ -0,0 +1,39 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.models.admin.organization.dataretention + +import com.fasterxml.jackson.module.kotlin.jacksonTypeRef +import com.openai.core.jsonMapper +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test + +internal class OrganizationDataRetentionTest { + + @Test + fun create() { + val organizationDataRetention = + OrganizationDataRetention.builder() + .type(OrganizationDataRetention.Type.ZERO_DATA_RETENTION) + .build() + + assertThat(organizationDataRetention.type()) + .isEqualTo(OrganizationDataRetention.Type.ZERO_DATA_RETENTION) + } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val organizationDataRetention = + OrganizationDataRetention.builder() + .type(OrganizationDataRetention.Type.ZERO_DATA_RETENTION) + .build() + + val roundtrippedOrganizationDataRetention = + jsonMapper.readValue( + jsonMapper.writeValueAsString(organizationDataRetention), + jacksonTypeRef(), + ) + + assertThat(roundtrippedOrganizationDataRetention).isEqualTo(organizationDataRetention) + } +} diff --git a/openai-java-core/src/test/kotlin/com/openai/models/admin/organization/groups/GroupListPageResponseTest.kt b/openai-java-core/src/test/kotlin/com/openai/models/admin/organization/groups/GroupListPageResponseTest.kt index f6d1c19f6..3371a933c 100644 --- a/openai-java-core/src/test/kotlin/com/openai/models/admin/organization/groups/GroupListPageResponseTest.kt +++ b/openai-java-core/src/test/kotlin/com/openai/models/admin/organization/groups/GroupListPageResponseTest.kt @@ -17,7 +17,7 @@ internal class GroupListPageResponseTest { Group.builder() .id("id") .createdAt(0L) - .groupType("group_type") + .groupType(Group.GroupType.GROUP) .isScimManaged(true) .name("name") .build() @@ -31,7 +31,7 @@ internal class GroupListPageResponseTest { Group.builder() .id("id") .createdAt(0L) - .groupType("group_type") + .groupType(Group.GroupType.GROUP) .isScimManaged(true) .name("name") .build() @@ -49,7 +49,7 @@ internal class GroupListPageResponseTest { Group.builder() .id("id") .createdAt(0L) - .groupType("group_type") + .groupType(Group.GroupType.GROUP) .isScimManaged(true) .name("name") .build() diff --git a/openai-java-core/src/test/kotlin/com/openai/models/admin/organization/groups/GroupRetrieveParamsTest.kt b/openai-java-core/src/test/kotlin/com/openai/models/admin/organization/groups/GroupRetrieveParamsTest.kt new file mode 100644 index 000000000..bbac05267 --- /dev/null +++ b/openai-java-core/src/test/kotlin/com/openai/models/admin/organization/groups/GroupRetrieveParamsTest.kt @@ -0,0 +1,23 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.models.admin.organization.groups + +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test + +internal class GroupRetrieveParamsTest { + + @Test + fun create() { + GroupRetrieveParams.builder().groupId("group_id").build() + } + + @Test + fun pathParams() { + val params = GroupRetrieveParams.builder().groupId("group_id").build() + + assertThat(params._pathParam(0)).isEqualTo("group_id") + // out-of-bound path param + assertThat(params._pathParam(1)).isEqualTo("") + } +} diff --git a/openai-java-core/src/test/kotlin/com/openai/models/admin/organization/groups/GroupTest.kt b/openai-java-core/src/test/kotlin/com/openai/models/admin/organization/groups/GroupTest.kt index 423e4c9ab..4d8551760 100644 --- a/openai-java-core/src/test/kotlin/com/openai/models/admin/organization/groups/GroupTest.kt +++ b/openai-java-core/src/test/kotlin/com/openai/models/admin/organization/groups/GroupTest.kt @@ -15,14 +15,14 @@ internal class GroupTest { Group.builder() .id("id") .createdAt(0L) - .groupType("group_type") + .groupType(Group.GroupType.GROUP) .isScimManaged(true) .name("name") .build() assertThat(group.id()).isEqualTo("id") assertThat(group.createdAt()).isEqualTo(0L) - assertThat(group.groupType()).isEqualTo("group_type") + assertThat(group.groupType()).isEqualTo(Group.GroupType.GROUP) assertThat(group.isScimManaged()).isEqualTo(true) assertThat(group.name()).isEqualTo("name") } @@ -34,7 +34,7 @@ internal class GroupTest { Group.builder() .id("id") .createdAt(0L) - .groupType("group_type") + .groupType(Group.GroupType.GROUP) .isScimManaged(true) .name("name") .build() diff --git a/openai-java-core/src/test/kotlin/com/openai/models/admin/organization/groups/roles/RoleListPageResponseTest.kt b/openai-java-core/src/test/kotlin/com/openai/models/admin/organization/groups/roles/RoleListPageResponseTest.kt index be4e78317..2fec8f7e8 100644 --- a/openai-java-core/src/test/kotlin/com/openai/models/admin/organization/groups/roles/RoleListPageResponseTest.kt +++ b/openai-java-core/src/test/kotlin/com/openai/models/admin/organization/groups/roles/RoleListPageResponseTest.kt @@ -17,6 +17,12 @@ internal class RoleListPageResponseTest { .addData( RoleListResponse.builder() .id("id") + .addAssignmentSource( + RoleListResponse.AssignmentSource.builder() + .principalId("principal_id") + .principalType("principal_type") + .build() + ) .createdAt(0L) .createdBy("created_by") .createdByUserObj( @@ -45,6 +51,12 @@ internal class RoleListPageResponseTest { .containsExactly( RoleListResponse.builder() .id("id") + .addAssignmentSource( + RoleListResponse.AssignmentSource.builder() + .principalId("principal_id") + .principalType("principal_type") + .build() + ) .createdAt(0L) .createdBy("created_by") .createdByUserObj( @@ -77,6 +89,12 @@ internal class RoleListPageResponseTest { .addData( RoleListResponse.builder() .id("id") + .addAssignmentSource( + RoleListResponse.AssignmentSource.builder() + .principalId("principal_id") + .principalType("principal_type") + .build() + ) .createdAt(0L) .createdBy("created_by") .createdByUserObj( diff --git a/openai-java-core/src/test/kotlin/com/openai/models/admin/organization/groups/roles/RoleListResponseTest.kt b/openai-java-core/src/test/kotlin/com/openai/models/admin/organization/groups/roles/RoleListResponseTest.kt index f24164bf7..e58cdfdf1 100644 --- a/openai-java-core/src/test/kotlin/com/openai/models/admin/organization/groups/roles/RoleListResponseTest.kt +++ b/openai-java-core/src/test/kotlin/com/openai/models/admin/organization/groups/roles/RoleListResponseTest.kt @@ -5,6 +5,7 @@ package com.openai.models.admin.organization.groups.roles import com.fasterxml.jackson.module.kotlin.jacksonTypeRef import com.openai.core.JsonValue import com.openai.core.jsonMapper +import kotlin.jvm.optionals.getOrNull import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.Test @@ -15,6 +16,12 @@ internal class RoleListResponseTest { val roleListResponse = RoleListResponse.builder() .id("id") + .addAssignmentSource( + RoleListResponse.AssignmentSource.builder() + .principalId("principal_id") + .principalType("principal_type") + .build() + ) .createdAt(0L) .createdBy("created_by") .createdByUserObj( @@ -36,6 +43,13 @@ internal class RoleListResponseTest { .build() assertThat(roleListResponse.id()).isEqualTo("id") + assertThat(roleListResponse.assignmentSources().getOrNull()) + .containsExactly( + RoleListResponse.AssignmentSource.builder() + .principalId("principal_id") + .principalType("principal_type") + .build() + ) assertThat(roleListResponse.createdAt()).contains(0L) assertThat(roleListResponse.createdBy()).contains("created_by") assertThat(roleListResponse.createdByUserObj()) @@ -64,6 +78,12 @@ internal class RoleListResponseTest { val roleListResponse = RoleListResponse.builder() .id("id") + .addAssignmentSource( + RoleListResponse.AssignmentSource.builder() + .principalId("principal_id") + .principalType("principal_type") + .build() + ) .createdAt(0L) .createdBy("created_by") .createdByUserObj( diff --git a/openai-java-core/src/test/kotlin/com/openai/models/admin/organization/groups/roles/RoleRetrieveParamsTest.kt b/openai-java-core/src/test/kotlin/com/openai/models/admin/organization/groups/roles/RoleRetrieveParamsTest.kt new file mode 100644 index 000000000..845c79d9b --- /dev/null +++ b/openai-java-core/src/test/kotlin/com/openai/models/admin/organization/groups/roles/RoleRetrieveParamsTest.kt @@ -0,0 +1,24 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.models.admin.organization.groups.roles + +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test + +internal class RoleRetrieveParamsTest { + + @Test + fun create() { + RoleRetrieveParams.builder().groupId("group_id").roleId("role_id").build() + } + + @Test + fun pathParams() { + val params = RoleRetrieveParams.builder().groupId("group_id").roleId("role_id").build() + + assertThat(params._pathParam(0)).isEqualTo("group_id") + assertThat(params._pathParam(1)).isEqualTo("role_id") + // out-of-bound path param + assertThat(params._pathParam(2)).isEqualTo("") + } +} diff --git a/openai-java-core/src/test/kotlin/com/openai/models/admin/organization/groups/roles/RoleRetrieveResponseTest.kt b/openai-java-core/src/test/kotlin/com/openai/models/admin/organization/groups/roles/RoleRetrieveResponseTest.kt new file mode 100644 index 000000000..a81e13faf --- /dev/null +++ b/openai-java-core/src/test/kotlin/com/openai/models/admin/organization/groups/roles/RoleRetrieveResponseTest.kt @@ -0,0 +1,115 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.models.admin.organization.groups.roles + +import com.fasterxml.jackson.module.kotlin.jacksonTypeRef +import com.openai.core.JsonValue +import com.openai.core.jsonMapper +import kotlin.jvm.optionals.getOrNull +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test + +internal class RoleRetrieveResponseTest { + + @Test + fun create() { + val roleRetrieveResponse = + RoleRetrieveResponse.builder() + .id("id") + .addAssignmentSource( + RoleRetrieveResponse.AssignmentSource.builder() + .principalId("principal_id") + .principalType("principal_type") + .build() + ) + .createdAt(0L) + .createdBy("created_by") + .createdByUserObj( + RoleRetrieveResponse.CreatedByUserObj.builder() + .putAdditionalProperty("foo", JsonValue.from("bar")) + .build() + ) + .description("description") + .metadata( + RoleRetrieveResponse.Metadata.builder() + .putAdditionalProperty("foo", JsonValue.from("bar")) + .build() + ) + .name("name") + .addPermission("string") + .predefinedRole(true) + .resourceType("resource_type") + .updatedAt(0L) + .build() + + assertThat(roleRetrieveResponse.id()).isEqualTo("id") + assertThat(roleRetrieveResponse.assignmentSources().getOrNull()) + .containsExactly( + RoleRetrieveResponse.AssignmentSource.builder() + .principalId("principal_id") + .principalType("principal_type") + .build() + ) + assertThat(roleRetrieveResponse.createdAt()).contains(0L) + assertThat(roleRetrieveResponse.createdBy()).contains("created_by") + assertThat(roleRetrieveResponse.createdByUserObj()) + .contains( + RoleRetrieveResponse.CreatedByUserObj.builder() + .putAdditionalProperty("foo", JsonValue.from("bar")) + .build() + ) + assertThat(roleRetrieveResponse.description()).contains("description") + assertThat(roleRetrieveResponse.metadata()) + .contains( + RoleRetrieveResponse.Metadata.builder() + .putAdditionalProperty("foo", JsonValue.from("bar")) + .build() + ) + assertThat(roleRetrieveResponse.name()).isEqualTo("name") + assertThat(roleRetrieveResponse.permissions()).containsExactly("string") + assertThat(roleRetrieveResponse.predefinedRole()).isEqualTo(true) + assertThat(roleRetrieveResponse.resourceType()).isEqualTo("resource_type") + assertThat(roleRetrieveResponse.updatedAt()).contains(0L) + } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val roleRetrieveResponse = + RoleRetrieveResponse.builder() + .id("id") + .addAssignmentSource( + RoleRetrieveResponse.AssignmentSource.builder() + .principalId("principal_id") + .principalType("principal_type") + .build() + ) + .createdAt(0L) + .createdBy("created_by") + .createdByUserObj( + RoleRetrieveResponse.CreatedByUserObj.builder() + .putAdditionalProperty("foo", JsonValue.from("bar")) + .build() + ) + .description("description") + .metadata( + RoleRetrieveResponse.Metadata.builder() + .putAdditionalProperty("foo", JsonValue.from("bar")) + .build() + ) + .name("name") + .addPermission("string") + .predefinedRole(true) + .resourceType("resource_type") + .updatedAt(0L) + .build() + + val roundtrippedRoleRetrieveResponse = + jsonMapper.readValue( + jsonMapper.writeValueAsString(roleRetrieveResponse), + jacksonTypeRef(), + ) + + assertThat(roundtrippedRoleRetrieveResponse).isEqualTo(roleRetrieveResponse) + } +} diff --git a/openai-java-core/src/test/kotlin/com/openai/models/admin/organization/groups/users/UserRetrieveParamsTest.kt b/openai-java-core/src/test/kotlin/com/openai/models/admin/organization/groups/users/UserRetrieveParamsTest.kt new file mode 100644 index 000000000..34509cea8 --- /dev/null +++ b/openai-java-core/src/test/kotlin/com/openai/models/admin/organization/groups/users/UserRetrieveParamsTest.kt @@ -0,0 +1,24 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.models.admin.organization.groups.users + +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test + +internal class UserRetrieveParamsTest { + + @Test + fun create() { + UserRetrieveParams.builder().groupId("group_id").userId("user_id").build() + } + + @Test + fun pathParams() { + val params = UserRetrieveParams.builder().groupId("group_id").userId("user_id").build() + + assertThat(params._pathParam(0)).isEqualTo("group_id") + assertThat(params._pathParam(1)).isEqualTo("user_id") + // out-of-bound path param + assertThat(params._pathParam(2)).isEqualTo("") + } +} diff --git a/openai-java-core/src/test/kotlin/com/openai/models/admin/organization/groups/users/UserRetrieveResponseTest.kt b/openai-java-core/src/test/kotlin/com/openai/models/admin/organization/groups/users/UserRetrieveResponseTest.kt new file mode 100644 index 000000000..64ebee7fc --- /dev/null +++ b/openai-java-core/src/test/kotlin/com/openai/models/admin/organization/groups/users/UserRetrieveResponseTest.kt @@ -0,0 +1,53 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.models.admin.organization.groups.users + +import com.fasterxml.jackson.module.kotlin.jacksonTypeRef +import com.openai.core.jsonMapper +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test + +internal class UserRetrieveResponseTest { + + @Test + fun create() { + val userRetrieveResponse = + UserRetrieveResponse.builder() + .id("id") + .email("email") + .isServiceAccount(true) + .name("name") + .picture("picture") + .userType(UserRetrieveResponse.UserType.USER) + .build() + + assertThat(userRetrieveResponse.id()).isEqualTo("id") + assertThat(userRetrieveResponse.email()).contains("email") + assertThat(userRetrieveResponse.isServiceAccount()).contains(true) + assertThat(userRetrieveResponse.name()).isEqualTo("name") + assertThat(userRetrieveResponse.picture()).contains("picture") + assertThat(userRetrieveResponse.userType()).isEqualTo(UserRetrieveResponse.UserType.USER) + } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val userRetrieveResponse = + UserRetrieveResponse.builder() + .id("id") + .email("email") + .isServiceAccount(true) + .name("name") + .picture("picture") + .userType(UserRetrieveResponse.UserType.USER) + .build() + + val roundtrippedUserRetrieveResponse = + jsonMapper.readValue( + jsonMapper.writeValueAsString(userRetrieveResponse), + jacksonTypeRef(), + ) + + assertThat(roundtrippedUserRetrieveResponse).isEqualTo(userRetrieveResponse) + } +} diff --git a/openai-java-core/src/test/kotlin/com/openai/models/admin/organization/projects/dataretention/DataRetentionRetrieveParamsTest.kt b/openai-java-core/src/test/kotlin/com/openai/models/admin/organization/projects/dataretention/DataRetentionRetrieveParamsTest.kt new file mode 100644 index 000000000..c823faac2 --- /dev/null +++ b/openai-java-core/src/test/kotlin/com/openai/models/admin/organization/projects/dataretention/DataRetentionRetrieveParamsTest.kt @@ -0,0 +1,23 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.models.admin.organization.projects.dataretention + +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test + +internal class DataRetentionRetrieveParamsTest { + + @Test + fun create() { + DataRetentionRetrieveParams.builder().projectId("project_id").build() + } + + @Test + fun pathParams() { + val params = DataRetentionRetrieveParams.builder().projectId("project_id").build() + + assertThat(params._pathParam(0)).isEqualTo("project_id") + // out-of-bound path param + assertThat(params._pathParam(1)).isEqualTo("") + } +} diff --git a/openai-java-core/src/test/kotlin/com/openai/models/admin/organization/projects/dataretention/DataRetentionUpdateParamsTest.kt b/openai-java-core/src/test/kotlin/com/openai/models/admin/organization/projects/dataretention/DataRetentionUpdateParamsTest.kt new file mode 100644 index 000000000..bcdbddec3 --- /dev/null +++ b/openai-java-core/src/test/kotlin/com/openai/models/admin/organization/projects/dataretention/DataRetentionUpdateParamsTest.kt @@ -0,0 +1,44 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.models.admin.organization.projects.dataretention + +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test + +internal class DataRetentionUpdateParamsTest { + + @Test + fun create() { + DataRetentionUpdateParams.builder() + .projectId("project_id") + .retentionType(DataRetentionUpdateParams.RetentionType.ORGANIZATION_DEFAULT) + .build() + } + + @Test + fun pathParams() { + val params = + DataRetentionUpdateParams.builder() + .projectId("project_id") + .retentionType(DataRetentionUpdateParams.RetentionType.ORGANIZATION_DEFAULT) + .build() + + assertThat(params._pathParam(0)).isEqualTo("project_id") + // out-of-bound path param + assertThat(params._pathParam(1)).isEqualTo("") + } + + @Test + fun body() { + val params = + DataRetentionUpdateParams.builder() + .projectId("project_id") + .retentionType(DataRetentionUpdateParams.RetentionType.ORGANIZATION_DEFAULT) + .build() + + val body = params._body() + + assertThat(body.retentionType()) + .isEqualTo(DataRetentionUpdateParams.RetentionType.ORGANIZATION_DEFAULT) + } +} diff --git a/openai-java-core/src/test/kotlin/com/openai/models/admin/organization/projects/dataretention/ProjectDataRetentionTest.kt b/openai-java-core/src/test/kotlin/com/openai/models/admin/organization/projects/dataretention/ProjectDataRetentionTest.kt new file mode 100644 index 000000000..c40108cc8 --- /dev/null +++ b/openai-java-core/src/test/kotlin/com/openai/models/admin/organization/projects/dataretention/ProjectDataRetentionTest.kt @@ -0,0 +1,39 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.models.admin.organization.projects.dataretention + +import com.fasterxml.jackson.module.kotlin.jacksonTypeRef +import com.openai.core.jsonMapper +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test + +internal class ProjectDataRetentionTest { + + @Test + fun create() { + val projectDataRetention = + ProjectDataRetention.builder() + .type(ProjectDataRetention.Type.ORGANIZATION_DEFAULT) + .build() + + assertThat(projectDataRetention.type()) + .isEqualTo(ProjectDataRetention.Type.ORGANIZATION_DEFAULT) + } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val projectDataRetention = + ProjectDataRetention.builder() + .type(ProjectDataRetention.Type.ORGANIZATION_DEFAULT) + .build() + + val roundtrippedProjectDataRetention = + jsonMapper.readValue( + jsonMapper.writeValueAsString(projectDataRetention), + jacksonTypeRef(), + ) + + assertThat(roundtrippedProjectDataRetention).isEqualTo(projectDataRetention) + } +} diff --git a/openai-java-core/src/test/kotlin/com/openai/models/admin/organization/projects/groups/GroupListPageResponseTest.kt b/openai-java-core/src/test/kotlin/com/openai/models/admin/organization/projects/groups/GroupListPageResponseTest.kt index 34668c2db..df0cae553 100644 --- a/openai-java-core/src/test/kotlin/com/openai/models/admin/organization/projects/groups/GroupListPageResponseTest.kt +++ b/openai-java-core/src/test/kotlin/com/openai/models/admin/organization/projects/groups/GroupListPageResponseTest.kt @@ -18,7 +18,7 @@ internal class GroupListPageResponseTest { .createdAt(0L) .groupId("group_id") .groupName("group_name") - .groupType("group_type") + .groupType(ProjectGroup.GroupType.GROUP) .projectId("project_id") .build() ) @@ -32,7 +32,7 @@ internal class GroupListPageResponseTest { .createdAt(0L) .groupId("group_id") .groupName("group_name") - .groupType("group_type") + .groupType(ProjectGroup.GroupType.GROUP) .projectId("project_id") .build() ) @@ -50,7 +50,7 @@ internal class GroupListPageResponseTest { .createdAt(0L) .groupId("group_id") .groupName("group_name") - .groupType("group_type") + .groupType(ProjectGroup.GroupType.GROUP) .projectId("project_id") .build() ) diff --git a/openai-java-core/src/test/kotlin/com/openai/models/admin/organization/projects/groups/GroupRetrieveParamsTest.kt b/openai-java-core/src/test/kotlin/com/openai/models/admin/organization/projects/groups/GroupRetrieveParamsTest.kt new file mode 100644 index 000000000..7eb6cb239 --- /dev/null +++ b/openai-java-core/src/test/kotlin/com/openai/models/admin/organization/projects/groups/GroupRetrieveParamsTest.kt @@ -0,0 +1,54 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.models.admin.organization.projects.groups + +import com.openai.core.http.QueryParams +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test + +internal class GroupRetrieveParamsTest { + + @Test + fun create() { + GroupRetrieveParams.builder() + .projectId("project_id") + .groupId("group_id") + .groupType(GroupRetrieveParams.GroupType.GROUP) + .build() + } + + @Test + fun pathParams() { + val params = + GroupRetrieveParams.builder().projectId("project_id").groupId("group_id").build() + + assertThat(params._pathParam(0)).isEqualTo("project_id") + assertThat(params._pathParam(1)).isEqualTo("group_id") + // out-of-bound path param + assertThat(params._pathParam(2)).isEqualTo("") + } + + @Test + fun queryParams() { + val params = + GroupRetrieveParams.builder() + .projectId("project_id") + .groupId("group_id") + .groupType(GroupRetrieveParams.GroupType.GROUP) + .build() + + val queryParams = params._queryParams() + + assertThat(queryParams).isEqualTo(QueryParams.builder().put("group_type", "group").build()) + } + + @Test + fun queryParamsWithoutOptionalFields() { + val params = + GroupRetrieveParams.builder().projectId("project_id").groupId("group_id").build() + + val queryParams = params._queryParams() + + assertThat(queryParams).isEqualTo(QueryParams.builder().build()) + } +} diff --git a/openai-java-core/src/test/kotlin/com/openai/models/admin/organization/projects/groups/ProjectGroupTest.kt b/openai-java-core/src/test/kotlin/com/openai/models/admin/organization/projects/groups/ProjectGroupTest.kt index 9d59f4deb..9cbd9cfdc 100644 --- a/openai-java-core/src/test/kotlin/com/openai/models/admin/organization/projects/groups/ProjectGroupTest.kt +++ b/openai-java-core/src/test/kotlin/com/openai/models/admin/organization/projects/groups/ProjectGroupTest.kt @@ -16,14 +16,14 @@ internal class ProjectGroupTest { .createdAt(0L) .groupId("group_id") .groupName("group_name") - .groupType("group_type") + .groupType(ProjectGroup.GroupType.GROUP) .projectId("project_id") .build() assertThat(projectGroup.createdAt()).isEqualTo(0L) assertThat(projectGroup.groupId()).isEqualTo("group_id") assertThat(projectGroup.groupName()).isEqualTo("group_name") - assertThat(projectGroup.groupType()).isEqualTo("group_type") + assertThat(projectGroup.groupType()).isEqualTo(ProjectGroup.GroupType.GROUP) assertThat(projectGroup.projectId()).isEqualTo("project_id") } @@ -35,7 +35,7 @@ internal class ProjectGroupTest { .createdAt(0L) .groupId("group_id") .groupName("group_name") - .groupType("group_type") + .groupType(ProjectGroup.GroupType.GROUP) .projectId("project_id") .build() diff --git a/openai-java-core/src/test/kotlin/com/openai/models/admin/organization/projects/groups/roles/RoleListPageResponseTest.kt b/openai-java-core/src/test/kotlin/com/openai/models/admin/organization/projects/groups/roles/RoleListPageResponseTest.kt index 8e4b5b07e..c2bc2e90e 100644 --- a/openai-java-core/src/test/kotlin/com/openai/models/admin/organization/projects/groups/roles/RoleListPageResponseTest.kt +++ b/openai-java-core/src/test/kotlin/com/openai/models/admin/organization/projects/groups/roles/RoleListPageResponseTest.kt @@ -17,6 +17,12 @@ internal class RoleListPageResponseTest { .addData( RoleListResponse.builder() .id("id") + .addAssignmentSource( + RoleListResponse.AssignmentSource.builder() + .principalId("principal_id") + .principalType("principal_type") + .build() + ) .createdAt(0L) .createdBy("created_by") .createdByUserObj( @@ -45,6 +51,12 @@ internal class RoleListPageResponseTest { .containsExactly( RoleListResponse.builder() .id("id") + .addAssignmentSource( + RoleListResponse.AssignmentSource.builder() + .principalId("principal_id") + .principalType("principal_type") + .build() + ) .createdAt(0L) .createdBy("created_by") .createdByUserObj( @@ -77,6 +89,12 @@ internal class RoleListPageResponseTest { .addData( RoleListResponse.builder() .id("id") + .addAssignmentSource( + RoleListResponse.AssignmentSource.builder() + .principalId("principal_id") + .principalType("principal_type") + .build() + ) .createdAt(0L) .createdBy("created_by") .createdByUserObj( diff --git a/openai-java-core/src/test/kotlin/com/openai/models/admin/organization/projects/groups/roles/RoleListResponseTest.kt b/openai-java-core/src/test/kotlin/com/openai/models/admin/organization/projects/groups/roles/RoleListResponseTest.kt index 4e703deae..4f2155da7 100644 --- a/openai-java-core/src/test/kotlin/com/openai/models/admin/organization/projects/groups/roles/RoleListResponseTest.kt +++ b/openai-java-core/src/test/kotlin/com/openai/models/admin/organization/projects/groups/roles/RoleListResponseTest.kt @@ -5,6 +5,7 @@ package com.openai.models.admin.organization.projects.groups.roles import com.fasterxml.jackson.module.kotlin.jacksonTypeRef import com.openai.core.JsonValue import com.openai.core.jsonMapper +import kotlin.jvm.optionals.getOrNull import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.Test @@ -15,6 +16,12 @@ internal class RoleListResponseTest { val roleListResponse = RoleListResponse.builder() .id("id") + .addAssignmentSource( + RoleListResponse.AssignmentSource.builder() + .principalId("principal_id") + .principalType("principal_type") + .build() + ) .createdAt(0L) .createdBy("created_by") .createdByUserObj( @@ -36,6 +43,13 @@ internal class RoleListResponseTest { .build() assertThat(roleListResponse.id()).isEqualTo("id") + assertThat(roleListResponse.assignmentSources().getOrNull()) + .containsExactly( + RoleListResponse.AssignmentSource.builder() + .principalId("principal_id") + .principalType("principal_type") + .build() + ) assertThat(roleListResponse.createdAt()).contains(0L) assertThat(roleListResponse.createdBy()).contains("created_by") assertThat(roleListResponse.createdByUserObj()) @@ -64,6 +78,12 @@ internal class RoleListResponseTest { val roleListResponse = RoleListResponse.builder() .id("id") + .addAssignmentSource( + RoleListResponse.AssignmentSource.builder() + .principalId("principal_id") + .principalType("principal_type") + .build() + ) .createdAt(0L) .createdBy("created_by") .createdByUserObj( diff --git a/openai-java-core/src/test/kotlin/com/openai/models/admin/organization/projects/groups/roles/RoleRetrieveParamsTest.kt b/openai-java-core/src/test/kotlin/com/openai/models/admin/organization/projects/groups/roles/RoleRetrieveParamsTest.kt new file mode 100644 index 000000000..ad882d60c --- /dev/null +++ b/openai-java-core/src/test/kotlin/com/openai/models/admin/organization/projects/groups/roles/RoleRetrieveParamsTest.kt @@ -0,0 +1,34 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.models.admin.organization.projects.groups.roles + +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test + +internal class RoleRetrieveParamsTest { + + @Test + fun create() { + RoleRetrieveParams.builder() + .projectId("project_id") + .groupId("group_id") + .roleId("role_id") + .build() + } + + @Test + fun pathParams() { + val params = + RoleRetrieveParams.builder() + .projectId("project_id") + .groupId("group_id") + .roleId("role_id") + .build() + + assertThat(params._pathParam(0)).isEqualTo("project_id") + assertThat(params._pathParam(1)).isEqualTo("group_id") + assertThat(params._pathParam(2)).isEqualTo("role_id") + // out-of-bound path param + assertThat(params._pathParam(3)).isEqualTo("") + } +} diff --git a/openai-java-core/src/test/kotlin/com/openai/models/admin/organization/projects/groups/roles/RoleRetrieveResponseTest.kt b/openai-java-core/src/test/kotlin/com/openai/models/admin/organization/projects/groups/roles/RoleRetrieveResponseTest.kt new file mode 100644 index 000000000..1f45ee8de --- /dev/null +++ b/openai-java-core/src/test/kotlin/com/openai/models/admin/organization/projects/groups/roles/RoleRetrieveResponseTest.kt @@ -0,0 +1,115 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.models.admin.organization.projects.groups.roles + +import com.fasterxml.jackson.module.kotlin.jacksonTypeRef +import com.openai.core.JsonValue +import com.openai.core.jsonMapper +import kotlin.jvm.optionals.getOrNull +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test + +internal class RoleRetrieveResponseTest { + + @Test + fun create() { + val roleRetrieveResponse = + RoleRetrieveResponse.builder() + .id("id") + .addAssignmentSource( + RoleRetrieveResponse.AssignmentSource.builder() + .principalId("principal_id") + .principalType("principal_type") + .build() + ) + .createdAt(0L) + .createdBy("created_by") + .createdByUserObj( + RoleRetrieveResponse.CreatedByUserObj.builder() + .putAdditionalProperty("foo", JsonValue.from("bar")) + .build() + ) + .description("description") + .metadata( + RoleRetrieveResponse.Metadata.builder() + .putAdditionalProperty("foo", JsonValue.from("bar")) + .build() + ) + .name("name") + .addPermission("string") + .predefinedRole(true) + .resourceType("resource_type") + .updatedAt(0L) + .build() + + assertThat(roleRetrieveResponse.id()).isEqualTo("id") + assertThat(roleRetrieveResponse.assignmentSources().getOrNull()) + .containsExactly( + RoleRetrieveResponse.AssignmentSource.builder() + .principalId("principal_id") + .principalType("principal_type") + .build() + ) + assertThat(roleRetrieveResponse.createdAt()).contains(0L) + assertThat(roleRetrieveResponse.createdBy()).contains("created_by") + assertThat(roleRetrieveResponse.createdByUserObj()) + .contains( + RoleRetrieveResponse.CreatedByUserObj.builder() + .putAdditionalProperty("foo", JsonValue.from("bar")) + .build() + ) + assertThat(roleRetrieveResponse.description()).contains("description") + assertThat(roleRetrieveResponse.metadata()) + .contains( + RoleRetrieveResponse.Metadata.builder() + .putAdditionalProperty("foo", JsonValue.from("bar")) + .build() + ) + assertThat(roleRetrieveResponse.name()).isEqualTo("name") + assertThat(roleRetrieveResponse.permissions()).containsExactly("string") + assertThat(roleRetrieveResponse.predefinedRole()).isEqualTo(true) + assertThat(roleRetrieveResponse.resourceType()).isEqualTo("resource_type") + assertThat(roleRetrieveResponse.updatedAt()).contains(0L) + } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val roleRetrieveResponse = + RoleRetrieveResponse.builder() + .id("id") + .addAssignmentSource( + RoleRetrieveResponse.AssignmentSource.builder() + .principalId("principal_id") + .principalType("principal_type") + .build() + ) + .createdAt(0L) + .createdBy("created_by") + .createdByUserObj( + RoleRetrieveResponse.CreatedByUserObj.builder() + .putAdditionalProperty("foo", JsonValue.from("bar")) + .build() + ) + .description("description") + .metadata( + RoleRetrieveResponse.Metadata.builder() + .putAdditionalProperty("foo", JsonValue.from("bar")) + .build() + ) + .name("name") + .addPermission("string") + .predefinedRole(true) + .resourceType("resource_type") + .updatedAt(0L) + .build() + + val roundtrippedRoleRetrieveResponse = + jsonMapper.readValue( + jsonMapper.writeValueAsString(roleRetrieveResponse), + jacksonTypeRef(), + ) + + assertThat(roundtrippedRoleRetrieveResponse).isEqualTo(roleRetrieveResponse) + } +} diff --git a/openai-java-core/src/test/kotlin/com/openai/models/admin/organization/projects/roles/RoleRetrieveParamsTest.kt b/openai-java-core/src/test/kotlin/com/openai/models/admin/organization/projects/roles/RoleRetrieveParamsTest.kt new file mode 100644 index 000000000..6df7b3e63 --- /dev/null +++ b/openai-java-core/src/test/kotlin/com/openai/models/admin/organization/projects/roles/RoleRetrieveParamsTest.kt @@ -0,0 +1,24 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.models.admin.organization.projects.roles + +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test + +internal class RoleRetrieveParamsTest { + + @Test + fun create() { + RoleRetrieveParams.builder().projectId("project_id").roleId("role_id").build() + } + + @Test + fun pathParams() { + val params = RoleRetrieveParams.builder().projectId("project_id").roleId("role_id").build() + + assertThat(params._pathParam(0)).isEqualTo("project_id") + assertThat(params._pathParam(1)).isEqualTo("role_id") + // out-of-bound path param + assertThat(params._pathParam(2)).isEqualTo("") + } +} diff --git a/openai-java-core/src/test/kotlin/com/openai/models/admin/organization/projects/serviceaccounts/ServiceAccountUpdateParamsTest.kt b/openai-java-core/src/test/kotlin/com/openai/models/admin/organization/projects/serviceaccounts/ServiceAccountUpdateParamsTest.kt new file mode 100644 index 000000000..4228ffa27 --- /dev/null +++ b/openai-java-core/src/test/kotlin/com/openai/models/admin/organization/projects/serviceaccounts/ServiceAccountUpdateParamsTest.kt @@ -0,0 +1,60 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.models.admin.organization.projects.serviceaccounts + +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test + +internal class ServiceAccountUpdateParamsTest { + + @Test + fun create() { + ServiceAccountUpdateParams.builder() + .projectId("project_id") + .serviceAccountId("service_account_id") + .name("name") + .role(ServiceAccountUpdateParams.Role.MEMBER) + .build() + } + + @Test + fun pathParams() { + val params = + ServiceAccountUpdateParams.builder() + .projectId("project_id") + .serviceAccountId("service_account_id") + .build() + + assertThat(params._pathParam(0)).isEqualTo("project_id") + assertThat(params._pathParam(1)).isEqualTo("service_account_id") + // out-of-bound path param + assertThat(params._pathParam(2)).isEqualTo("") + } + + @Test + fun body() { + val params = + ServiceAccountUpdateParams.builder() + .projectId("project_id") + .serviceAccountId("service_account_id") + .name("name") + .role(ServiceAccountUpdateParams.Role.MEMBER) + .build() + + val body = params._body() + + assertThat(body.name()).contains("name") + assertThat(body.role()).contains(ServiceAccountUpdateParams.Role.MEMBER) + } + + @Test + fun bodyWithoutOptionalFields() { + val params = + ServiceAccountUpdateParams.builder() + .projectId("project_id") + .serviceAccountId("service_account_id") + .build() + + val body = params._body() + } +} diff --git a/openai-java-core/src/test/kotlin/com/openai/models/admin/organization/projects/spendalerts/ProjectSpendAlertDeletedTest.kt b/openai-java-core/src/test/kotlin/com/openai/models/admin/organization/projects/spendalerts/ProjectSpendAlertDeletedTest.kt new file mode 100644 index 000000000..6e83780cb --- /dev/null +++ b/openai-java-core/src/test/kotlin/com/openai/models/admin/organization/projects/spendalerts/ProjectSpendAlertDeletedTest.kt @@ -0,0 +1,35 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.models.admin.organization.projects.spendalerts + +import com.fasterxml.jackson.module.kotlin.jacksonTypeRef +import com.openai.core.jsonMapper +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test + +internal class ProjectSpendAlertDeletedTest { + + @Test + fun create() { + val projectSpendAlertDeleted = + ProjectSpendAlertDeleted.builder().id("id").deleted(true).build() + + assertThat(projectSpendAlertDeleted.id()).isEqualTo("id") + assertThat(projectSpendAlertDeleted.deleted()).isEqualTo(true) + } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val projectSpendAlertDeleted = + ProjectSpendAlertDeleted.builder().id("id").deleted(true).build() + + val roundtrippedProjectSpendAlertDeleted = + jsonMapper.readValue( + jsonMapper.writeValueAsString(projectSpendAlertDeleted), + jacksonTypeRef(), + ) + + assertThat(roundtrippedProjectSpendAlertDeleted).isEqualTo(projectSpendAlertDeleted) + } +} diff --git a/openai-java-core/src/test/kotlin/com/openai/models/admin/organization/projects/spendalerts/ProjectSpendAlertTest.kt b/openai-java-core/src/test/kotlin/com/openai/models/admin/organization/projects/spendalerts/ProjectSpendAlertTest.kt new file mode 100644 index 000000000..e8b5cdfaf --- /dev/null +++ b/openai-java-core/src/test/kotlin/com/openai/models/admin/organization/projects/spendalerts/ProjectSpendAlertTest.kt @@ -0,0 +1,66 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.models.admin.organization.projects.spendalerts + +import com.fasterxml.jackson.module.kotlin.jacksonTypeRef +import com.openai.core.jsonMapper +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test + +internal class ProjectSpendAlertTest { + + @Test + fun create() { + val projectSpendAlert = + ProjectSpendAlert.builder() + .id("id") + .currency(ProjectSpendAlert.Currency.USD) + .interval(ProjectSpendAlert.Interval.MONTH) + .notificationChannel( + ProjectSpendAlert.NotificationChannel.builder() + .addRecipient("string") + .subjectPrefix("subject_prefix") + .build() + ) + .thresholdAmount(0L) + .build() + + assertThat(projectSpendAlert.id()).isEqualTo("id") + assertThat(projectSpendAlert.currency()).isEqualTo(ProjectSpendAlert.Currency.USD) + assertThat(projectSpendAlert.interval()).isEqualTo(ProjectSpendAlert.Interval.MONTH) + assertThat(projectSpendAlert.notificationChannel()) + .isEqualTo( + ProjectSpendAlert.NotificationChannel.builder() + .addRecipient("string") + .subjectPrefix("subject_prefix") + .build() + ) + assertThat(projectSpendAlert.thresholdAmount()).isEqualTo(0L) + } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val projectSpendAlert = + ProjectSpendAlert.builder() + .id("id") + .currency(ProjectSpendAlert.Currency.USD) + .interval(ProjectSpendAlert.Interval.MONTH) + .notificationChannel( + ProjectSpendAlert.NotificationChannel.builder() + .addRecipient("string") + .subjectPrefix("subject_prefix") + .build() + ) + .thresholdAmount(0L) + .build() + + val roundtrippedProjectSpendAlert = + jsonMapper.readValue( + jsonMapper.writeValueAsString(projectSpendAlert), + jacksonTypeRef(), + ) + + assertThat(roundtrippedProjectSpendAlert).isEqualTo(projectSpendAlert) + } +} diff --git a/openai-java-core/src/test/kotlin/com/openai/models/admin/organization/projects/spendalerts/SpendAlertCreateParamsTest.kt b/openai-java-core/src/test/kotlin/com/openai/models/admin/organization/projects/spendalerts/SpendAlertCreateParamsTest.kt new file mode 100644 index 000000000..a72151fc7 --- /dev/null +++ b/openai-java-core/src/test/kotlin/com/openai/models/admin/organization/projects/spendalerts/SpendAlertCreateParamsTest.kt @@ -0,0 +1,101 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.models.admin.organization.projects.spendalerts + +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test + +internal class SpendAlertCreateParamsTest { + + @Test + fun create() { + SpendAlertCreateParams.builder() + .projectId("project_id") + .currency(SpendAlertCreateParams.Currency.USD) + .interval(SpendAlertCreateParams.Interval.MONTH) + .notificationChannel( + SpendAlertCreateParams.NotificationChannel.builder() + .addRecipient("string") + .subjectPrefix("subject_prefix") + .build() + ) + .thresholdAmount(0L) + .build() + } + + @Test + fun pathParams() { + val params = + SpendAlertCreateParams.builder() + .projectId("project_id") + .currency(SpendAlertCreateParams.Currency.USD) + .interval(SpendAlertCreateParams.Interval.MONTH) + .notificationChannel( + SpendAlertCreateParams.NotificationChannel.builder() + .addRecipient("string") + .build() + ) + .thresholdAmount(0L) + .build() + + assertThat(params._pathParam(0)).isEqualTo("project_id") + // out-of-bound path param + assertThat(params._pathParam(1)).isEqualTo("") + } + + @Test + fun body() { + val params = + SpendAlertCreateParams.builder() + .projectId("project_id") + .currency(SpendAlertCreateParams.Currency.USD) + .interval(SpendAlertCreateParams.Interval.MONTH) + .notificationChannel( + SpendAlertCreateParams.NotificationChannel.builder() + .addRecipient("string") + .subjectPrefix("subject_prefix") + .build() + ) + .thresholdAmount(0L) + .build() + + val body = params._body() + + assertThat(body.currency()).isEqualTo(SpendAlertCreateParams.Currency.USD) + assertThat(body.interval()).isEqualTo(SpendAlertCreateParams.Interval.MONTH) + assertThat(body.notificationChannel()) + .isEqualTo( + SpendAlertCreateParams.NotificationChannel.builder() + .addRecipient("string") + .subjectPrefix("subject_prefix") + .build() + ) + assertThat(body.thresholdAmount()).isEqualTo(0L) + } + + @Test + fun bodyWithoutOptionalFields() { + val params = + SpendAlertCreateParams.builder() + .projectId("project_id") + .currency(SpendAlertCreateParams.Currency.USD) + .interval(SpendAlertCreateParams.Interval.MONTH) + .notificationChannel( + SpendAlertCreateParams.NotificationChannel.builder() + .addRecipient("string") + .build() + ) + .thresholdAmount(0L) + .build() + + val body = params._body() + + assertThat(body.currency()).isEqualTo(SpendAlertCreateParams.Currency.USD) + assertThat(body.interval()).isEqualTo(SpendAlertCreateParams.Interval.MONTH) + assertThat(body.notificationChannel()) + .isEqualTo( + SpendAlertCreateParams.NotificationChannel.builder().addRecipient("string").build() + ) + assertThat(body.thresholdAmount()).isEqualTo(0L) + } +} diff --git a/openai-java-core/src/test/kotlin/com/openai/models/admin/organization/projects/spendalerts/SpendAlertDeleteParamsTest.kt b/openai-java-core/src/test/kotlin/com/openai/models/admin/organization/projects/spendalerts/SpendAlertDeleteParamsTest.kt new file mode 100644 index 000000000..117a32132 --- /dev/null +++ b/openai-java-core/src/test/kotlin/com/openai/models/admin/organization/projects/spendalerts/SpendAlertDeleteParamsTest.kt @@ -0,0 +1,25 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.models.admin.organization.projects.spendalerts + +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test + +internal class SpendAlertDeleteParamsTest { + + @Test + fun create() { + SpendAlertDeleteParams.builder().projectId("project_id").alertId("alert_id").build() + } + + @Test + fun pathParams() { + val params = + SpendAlertDeleteParams.builder().projectId("project_id").alertId("alert_id").build() + + assertThat(params._pathParam(0)).isEqualTo("project_id") + assertThat(params._pathParam(1)).isEqualTo("alert_id") + // out-of-bound path param + assertThat(params._pathParam(2)).isEqualTo("") + } +} diff --git a/openai-java-core/src/test/kotlin/com/openai/models/admin/organization/projects/spendalerts/SpendAlertListPageResponseTest.kt b/openai-java-core/src/test/kotlin/com/openai/models/admin/organization/projects/spendalerts/SpendAlertListPageResponseTest.kt new file mode 100644 index 000000000..5e91d0019 --- /dev/null +++ b/openai-java-core/src/test/kotlin/com/openai/models/admin/organization/projects/spendalerts/SpendAlertListPageResponseTest.kt @@ -0,0 +1,87 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.models.admin.organization.projects.spendalerts + +import com.fasterxml.jackson.module.kotlin.jacksonTypeRef +import com.openai.core.jsonMapper +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test + +internal class SpendAlertListPageResponseTest { + + @Test + fun create() { + val spendAlertListPageResponse = + SpendAlertListPageResponse.builder() + .addData( + ProjectSpendAlert.builder() + .id("id") + .currency(ProjectSpendAlert.Currency.USD) + .interval(ProjectSpendAlert.Interval.MONTH) + .notificationChannel( + ProjectSpendAlert.NotificationChannel.builder() + .addRecipient("string") + .subjectPrefix("subject_prefix") + .build() + ) + .thresholdAmount(0L) + .build() + ) + .firstId("first_id") + .hasMore(true) + .lastId("last_id") + .build() + + assertThat(spendAlertListPageResponse.data()) + .containsExactly( + ProjectSpendAlert.builder() + .id("id") + .currency(ProjectSpendAlert.Currency.USD) + .interval(ProjectSpendAlert.Interval.MONTH) + .notificationChannel( + ProjectSpendAlert.NotificationChannel.builder() + .addRecipient("string") + .subjectPrefix("subject_prefix") + .build() + ) + .thresholdAmount(0L) + .build() + ) + assertThat(spendAlertListPageResponse.firstId()).contains("first_id") + assertThat(spendAlertListPageResponse.hasMore()).isEqualTo(true) + assertThat(spendAlertListPageResponse.lastId()).contains("last_id") + } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val spendAlertListPageResponse = + SpendAlertListPageResponse.builder() + .addData( + ProjectSpendAlert.builder() + .id("id") + .currency(ProjectSpendAlert.Currency.USD) + .interval(ProjectSpendAlert.Interval.MONTH) + .notificationChannel( + ProjectSpendAlert.NotificationChannel.builder() + .addRecipient("string") + .subjectPrefix("subject_prefix") + .build() + ) + .thresholdAmount(0L) + .build() + ) + .firstId("first_id") + .hasMore(true) + .lastId("last_id") + .build() + + val roundtrippedSpendAlertListPageResponse = + jsonMapper.readValue( + jsonMapper.writeValueAsString(spendAlertListPageResponse), + jacksonTypeRef(), + ) + + assertThat(roundtrippedSpendAlertListPageResponse).isEqualTo(spendAlertListPageResponse) + } +} diff --git a/openai-java-core/src/test/kotlin/com/openai/models/admin/organization/projects/spendalerts/SpendAlertListParamsTest.kt b/openai-java-core/src/test/kotlin/com/openai/models/admin/organization/projects/spendalerts/SpendAlertListParamsTest.kt new file mode 100644 index 000000000..6b6c2577d --- /dev/null +++ b/openai-java-core/src/test/kotlin/com/openai/models/admin/organization/projects/spendalerts/SpendAlertListParamsTest.kt @@ -0,0 +1,63 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.models.admin.organization.projects.spendalerts + +import com.openai.core.http.QueryParams +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test + +internal class SpendAlertListParamsTest { + + @Test + fun create() { + SpendAlertListParams.builder() + .projectId("project_id") + .after("after") + .before("before") + .limit(0L) + .order(SpendAlertListParams.Order.ASC) + .build() + } + + @Test + fun pathParams() { + val params = SpendAlertListParams.builder().projectId("project_id").build() + + assertThat(params._pathParam(0)).isEqualTo("project_id") + // out-of-bound path param + assertThat(params._pathParam(1)).isEqualTo("") + } + + @Test + fun queryParams() { + val params = + SpendAlertListParams.builder() + .projectId("project_id") + .after("after") + .before("before") + .limit(0L) + .order(SpendAlertListParams.Order.ASC) + .build() + + val queryParams = params._queryParams() + + assertThat(queryParams) + .isEqualTo( + QueryParams.builder() + .put("after", "after") + .put("before", "before") + .put("limit", "0") + .put("order", "asc") + .build() + ) + } + + @Test + fun queryParamsWithoutOptionalFields() { + val params = SpendAlertListParams.builder().projectId("project_id").build() + + val queryParams = params._queryParams() + + assertThat(queryParams).isEqualTo(QueryParams.builder().build()) + } +} diff --git a/openai-java-core/src/test/kotlin/com/openai/models/admin/organization/projects/spendalerts/SpendAlertUpdateParamsTest.kt b/openai-java-core/src/test/kotlin/com/openai/models/admin/organization/projects/spendalerts/SpendAlertUpdateParamsTest.kt new file mode 100644 index 000000000..e653eec10 --- /dev/null +++ b/openai-java-core/src/test/kotlin/com/openai/models/admin/organization/projects/spendalerts/SpendAlertUpdateParamsTest.kt @@ -0,0 +1,106 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.models.admin.organization.projects.spendalerts + +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test + +internal class SpendAlertUpdateParamsTest { + + @Test + fun create() { + SpendAlertUpdateParams.builder() + .projectId("project_id") + .alertId("alert_id") + .currency(SpendAlertUpdateParams.Currency.USD) + .interval(SpendAlertUpdateParams.Interval.MONTH) + .notificationChannel( + SpendAlertUpdateParams.NotificationChannel.builder() + .addRecipient("string") + .subjectPrefix("subject_prefix") + .build() + ) + .thresholdAmount(0L) + .build() + } + + @Test + fun pathParams() { + val params = + SpendAlertUpdateParams.builder() + .projectId("project_id") + .alertId("alert_id") + .currency(SpendAlertUpdateParams.Currency.USD) + .interval(SpendAlertUpdateParams.Interval.MONTH) + .notificationChannel( + SpendAlertUpdateParams.NotificationChannel.builder() + .addRecipient("string") + .build() + ) + .thresholdAmount(0L) + .build() + + assertThat(params._pathParam(0)).isEqualTo("project_id") + assertThat(params._pathParam(1)).isEqualTo("alert_id") + // out-of-bound path param + assertThat(params._pathParam(2)).isEqualTo("") + } + + @Test + fun body() { + val params = + SpendAlertUpdateParams.builder() + .projectId("project_id") + .alertId("alert_id") + .currency(SpendAlertUpdateParams.Currency.USD) + .interval(SpendAlertUpdateParams.Interval.MONTH) + .notificationChannel( + SpendAlertUpdateParams.NotificationChannel.builder() + .addRecipient("string") + .subjectPrefix("subject_prefix") + .build() + ) + .thresholdAmount(0L) + .build() + + val body = params._body() + + assertThat(body.currency()).isEqualTo(SpendAlertUpdateParams.Currency.USD) + assertThat(body.interval()).isEqualTo(SpendAlertUpdateParams.Interval.MONTH) + assertThat(body.notificationChannel()) + .isEqualTo( + SpendAlertUpdateParams.NotificationChannel.builder() + .addRecipient("string") + .subjectPrefix("subject_prefix") + .build() + ) + assertThat(body.thresholdAmount()).isEqualTo(0L) + } + + @Test + fun bodyWithoutOptionalFields() { + val params = + SpendAlertUpdateParams.builder() + .projectId("project_id") + .alertId("alert_id") + .currency(SpendAlertUpdateParams.Currency.USD) + .interval(SpendAlertUpdateParams.Interval.MONTH) + .notificationChannel( + SpendAlertUpdateParams.NotificationChannel.builder() + .addRecipient("string") + .build() + ) + .thresholdAmount(0L) + .build() + + val body = params._body() + + assertThat(body.currency()).isEqualTo(SpendAlertUpdateParams.Currency.USD) + assertThat(body.interval()).isEqualTo(SpendAlertUpdateParams.Interval.MONTH) + assertThat(body.notificationChannel()) + .isEqualTo( + SpendAlertUpdateParams.NotificationChannel.builder().addRecipient("string").build() + ) + assertThat(body.thresholdAmount()).isEqualTo(0L) + } +} diff --git a/openai-java-core/src/test/kotlin/com/openai/models/admin/organization/projects/users/roles/RoleListPageResponseTest.kt b/openai-java-core/src/test/kotlin/com/openai/models/admin/organization/projects/users/roles/RoleListPageResponseTest.kt index 7f861f70b..cde0b7c0d 100644 --- a/openai-java-core/src/test/kotlin/com/openai/models/admin/organization/projects/users/roles/RoleListPageResponseTest.kt +++ b/openai-java-core/src/test/kotlin/com/openai/models/admin/organization/projects/users/roles/RoleListPageResponseTest.kt @@ -17,6 +17,12 @@ internal class RoleListPageResponseTest { .addData( RoleListResponse.builder() .id("id") + .addAssignmentSource( + RoleListResponse.AssignmentSource.builder() + .principalId("principal_id") + .principalType("principal_type") + .build() + ) .createdAt(0L) .createdBy("created_by") .createdByUserObj( @@ -45,6 +51,12 @@ internal class RoleListPageResponseTest { .containsExactly( RoleListResponse.builder() .id("id") + .addAssignmentSource( + RoleListResponse.AssignmentSource.builder() + .principalId("principal_id") + .principalType("principal_type") + .build() + ) .createdAt(0L) .createdBy("created_by") .createdByUserObj( @@ -77,6 +89,12 @@ internal class RoleListPageResponseTest { .addData( RoleListResponse.builder() .id("id") + .addAssignmentSource( + RoleListResponse.AssignmentSource.builder() + .principalId("principal_id") + .principalType("principal_type") + .build() + ) .createdAt(0L) .createdBy("created_by") .createdByUserObj( diff --git a/openai-java-core/src/test/kotlin/com/openai/models/admin/organization/projects/users/roles/RoleListResponseTest.kt b/openai-java-core/src/test/kotlin/com/openai/models/admin/organization/projects/users/roles/RoleListResponseTest.kt index c6cc21d22..f408857be 100644 --- a/openai-java-core/src/test/kotlin/com/openai/models/admin/organization/projects/users/roles/RoleListResponseTest.kt +++ b/openai-java-core/src/test/kotlin/com/openai/models/admin/organization/projects/users/roles/RoleListResponseTest.kt @@ -5,6 +5,7 @@ package com.openai.models.admin.organization.projects.users.roles import com.fasterxml.jackson.module.kotlin.jacksonTypeRef import com.openai.core.JsonValue import com.openai.core.jsonMapper +import kotlin.jvm.optionals.getOrNull import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.Test @@ -15,6 +16,12 @@ internal class RoleListResponseTest { val roleListResponse = RoleListResponse.builder() .id("id") + .addAssignmentSource( + RoleListResponse.AssignmentSource.builder() + .principalId("principal_id") + .principalType("principal_type") + .build() + ) .createdAt(0L) .createdBy("created_by") .createdByUserObj( @@ -36,6 +43,13 @@ internal class RoleListResponseTest { .build() assertThat(roleListResponse.id()).isEqualTo("id") + assertThat(roleListResponse.assignmentSources().getOrNull()) + .containsExactly( + RoleListResponse.AssignmentSource.builder() + .principalId("principal_id") + .principalType("principal_type") + .build() + ) assertThat(roleListResponse.createdAt()).contains(0L) assertThat(roleListResponse.createdBy()).contains("created_by") assertThat(roleListResponse.createdByUserObj()) @@ -64,6 +78,12 @@ internal class RoleListResponseTest { val roleListResponse = RoleListResponse.builder() .id("id") + .addAssignmentSource( + RoleListResponse.AssignmentSource.builder() + .principalId("principal_id") + .principalType("principal_type") + .build() + ) .createdAt(0L) .createdBy("created_by") .createdByUserObj( diff --git a/openai-java-core/src/test/kotlin/com/openai/models/admin/organization/projects/users/roles/RoleRetrieveParamsTest.kt b/openai-java-core/src/test/kotlin/com/openai/models/admin/organization/projects/users/roles/RoleRetrieveParamsTest.kt new file mode 100644 index 000000000..9bddd41bd --- /dev/null +++ b/openai-java-core/src/test/kotlin/com/openai/models/admin/organization/projects/users/roles/RoleRetrieveParamsTest.kt @@ -0,0 +1,34 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.models.admin.organization.projects.users.roles + +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test + +internal class RoleRetrieveParamsTest { + + @Test + fun create() { + RoleRetrieveParams.builder() + .projectId("project_id") + .userId("user_id") + .roleId("role_id") + .build() + } + + @Test + fun pathParams() { + val params = + RoleRetrieveParams.builder() + .projectId("project_id") + .userId("user_id") + .roleId("role_id") + .build() + + assertThat(params._pathParam(0)).isEqualTo("project_id") + assertThat(params._pathParam(1)).isEqualTo("user_id") + assertThat(params._pathParam(2)).isEqualTo("role_id") + // out-of-bound path param + assertThat(params._pathParam(3)).isEqualTo("") + } +} diff --git a/openai-java-core/src/test/kotlin/com/openai/models/admin/organization/projects/users/roles/RoleRetrieveResponseTest.kt b/openai-java-core/src/test/kotlin/com/openai/models/admin/organization/projects/users/roles/RoleRetrieveResponseTest.kt new file mode 100644 index 000000000..711a69799 --- /dev/null +++ b/openai-java-core/src/test/kotlin/com/openai/models/admin/organization/projects/users/roles/RoleRetrieveResponseTest.kt @@ -0,0 +1,115 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.models.admin.organization.projects.users.roles + +import com.fasterxml.jackson.module.kotlin.jacksonTypeRef +import com.openai.core.JsonValue +import com.openai.core.jsonMapper +import kotlin.jvm.optionals.getOrNull +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test + +internal class RoleRetrieveResponseTest { + + @Test + fun create() { + val roleRetrieveResponse = + RoleRetrieveResponse.builder() + .id("id") + .addAssignmentSource( + RoleRetrieveResponse.AssignmentSource.builder() + .principalId("principal_id") + .principalType("principal_type") + .build() + ) + .createdAt(0L) + .createdBy("created_by") + .createdByUserObj( + RoleRetrieveResponse.CreatedByUserObj.builder() + .putAdditionalProperty("foo", JsonValue.from("bar")) + .build() + ) + .description("description") + .metadata( + RoleRetrieveResponse.Metadata.builder() + .putAdditionalProperty("foo", JsonValue.from("bar")) + .build() + ) + .name("name") + .addPermission("string") + .predefinedRole(true) + .resourceType("resource_type") + .updatedAt(0L) + .build() + + assertThat(roleRetrieveResponse.id()).isEqualTo("id") + assertThat(roleRetrieveResponse.assignmentSources().getOrNull()) + .containsExactly( + RoleRetrieveResponse.AssignmentSource.builder() + .principalId("principal_id") + .principalType("principal_type") + .build() + ) + assertThat(roleRetrieveResponse.createdAt()).contains(0L) + assertThat(roleRetrieveResponse.createdBy()).contains("created_by") + assertThat(roleRetrieveResponse.createdByUserObj()) + .contains( + RoleRetrieveResponse.CreatedByUserObj.builder() + .putAdditionalProperty("foo", JsonValue.from("bar")) + .build() + ) + assertThat(roleRetrieveResponse.description()).contains("description") + assertThat(roleRetrieveResponse.metadata()) + .contains( + RoleRetrieveResponse.Metadata.builder() + .putAdditionalProperty("foo", JsonValue.from("bar")) + .build() + ) + assertThat(roleRetrieveResponse.name()).isEqualTo("name") + assertThat(roleRetrieveResponse.permissions()).containsExactly("string") + assertThat(roleRetrieveResponse.predefinedRole()).isEqualTo(true) + assertThat(roleRetrieveResponse.resourceType()).isEqualTo("resource_type") + assertThat(roleRetrieveResponse.updatedAt()).contains(0L) + } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val roleRetrieveResponse = + RoleRetrieveResponse.builder() + .id("id") + .addAssignmentSource( + RoleRetrieveResponse.AssignmentSource.builder() + .principalId("principal_id") + .principalType("principal_type") + .build() + ) + .createdAt(0L) + .createdBy("created_by") + .createdByUserObj( + RoleRetrieveResponse.CreatedByUserObj.builder() + .putAdditionalProperty("foo", JsonValue.from("bar")) + .build() + ) + .description("description") + .metadata( + RoleRetrieveResponse.Metadata.builder() + .putAdditionalProperty("foo", JsonValue.from("bar")) + .build() + ) + .name("name") + .addPermission("string") + .predefinedRole(true) + .resourceType("resource_type") + .updatedAt(0L) + .build() + + val roundtrippedRoleRetrieveResponse = + jsonMapper.readValue( + jsonMapper.writeValueAsString(roleRetrieveResponse), + jacksonTypeRef(), + ) + + assertThat(roundtrippedRoleRetrieveResponse).isEqualTo(roleRetrieveResponse) + } +} diff --git a/openai-java-core/src/test/kotlin/com/openai/models/admin/organization/roles/RoleRetrieveParamsTest.kt b/openai-java-core/src/test/kotlin/com/openai/models/admin/organization/roles/RoleRetrieveParamsTest.kt new file mode 100644 index 000000000..a1f3a0e17 --- /dev/null +++ b/openai-java-core/src/test/kotlin/com/openai/models/admin/organization/roles/RoleRetrieveParamsTest.kt @@ -0,0 +1,23 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.models.admin.organization.roles + +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test + +internal class RoleRetrieveParamsTest { + + @Test + fun create() { + RoleRetrieveParams.builder().roleId("role_id").build() + } + + @Test + fun pathParams() { + val params = RoleRetrieveParams.builder().roleId("role_id").build() + + assertThat(params._pathParam(0)).isEqualTo("role_id") + // out-of-bound path param + assertThat(params._pathParam(1)).isEqualTo("") + } +} diff --git a/openai-java-core/src/test/kotlin/com/openai/models/admin/organization/spendalerts/OrganizationSpendAlertDeletedTest.kt b/openai-java-core/src/test/kotlin/com/openai/models/admin/organization/spendalerts/OrganizationSpendAlertDeletedTest.kt new file mode 100644 index 000000000..c57728514 --- /dev/null +++ b/openai-java-core/src/test/kotlin/com/openai/models/admin/organization/spendalerts/OrganizationSpendAlertDeletedTest.kt @@ -0,0 +1,36 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.models.admin.organization.spendalerts + +import com.fasterxml.jackson.module.kotlin.jacksonTypeRef +import com.openai.core.jsonMapper +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test + +internal class OrganizationSpendAlertDeletedTest { + + @Test + fun create() { + val organizationSpendAlertDeleted = + OrganizationSpendAlertDeleted.builder().id("id").deleted(true).build() + + assertThat(organizationSpendAlertDeleted.id()).isEqualTo("id") + assertThat(organizationSpendAlertDeleted.deleted()).isEqualTo(true) + } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val organizationSpendAlertDeleted = + OrganizationSpendAlertDeleted.builder().id("id").deleted(true).build() + + val roundtrippedOrganizationSpendAlertDeleted = + jsonMapper.readValue( + jsonMapper.writeValueAsString(organizationSpendAlertDeleted), + jacksonTypeRef(), + ) + + assertThat(roundtrippedOrganizationSpendAlertDeleted) + .isEqualTo(organizationSpendAlertDeleted) + } +} diff --git a/openai-java-core/src/test/kotlin/com/openai/models/admin/organization/spendalerts/OrganizationSpendAlertTest.kt b/openai-java-core/src/test/kotlin/com/openai/models/admin/organization/spendalerts/OrganizationSpendAlertTest.kt new file mode 100644 index 000000000..a7735e4b0 --- /dev/null +++ b/openai-java-core/src/test/kotlin/com/openai/models/admin/organization/spendalerts/OrganizationSpendAlertTest.kt @@ -0,0 +1,67 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.models.admin.organization.spendalerts + +import com.fasterxml.jackson.module.kotlin.jacksonTypeRef +import com.openai.core.jsonMapper +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test + +internal class OrganizationSpendAlertTest { + + @Test + fun create() { + val organizationSpendAlert = + OrganizationSpendAlert.builder() + .id("id") + .currency(OrganizationSpendAlert.Currency.USD) + .interval(OrganizationSpendAlert.Interval.MONTH) + .notificationChannel( + OrganizationSpendAlert.NotificationChannel.builder() + .addRecipient("string") + .subjectPrefix("subject_prefix") + .build() + ) + .thresholdAmount(0L) + .build() + + assertThat(organizationSpendAlert.id()).isEqualTo("id") + assertThat(organizationSpendAlert.currency()).isEqualTo(OrganizationSpendAlert.Currency.USD) + assertThat(organizationSpendAlert.interval()) + .isEqualTo(OrganizationSpendAlert.Interval.MONTH) + assertThat(organizationSpendAlert.notificationChannel()) + .isEqualTo( + OrganizationSpendAlert.NotificationChannel.builder() + .addRecipient("string") + .subjectPrefix("subject_prefix") + .build() + ) + assertThat(organizationSpendAlert.thresholdAmount()).isEqualTo(0L) + } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val organizationSpendAlert = + OrganizationSpendAlert.builder() + .id("id") + .currency(OrganizationSpendAlert.Currency.USD) + .interval(OrganizationSpendAlert.Interval.MONTH) + .notificationChannel( + OrganizationSpendAlert.NotificationChannel.builder() + .addRecipient("string") + .subjectPrefix("subject_prefix") + .build() + ) + .thresholdAmount(0L) + .build() + + val roundtrippedOrganizationSpendAlert = + jsonMapper.readValue( + jsonMapper.writeValueAsString(organizationSpendAlert), + jacksonTypeRef(), + ) + + assertThat(roundtrippedOrganizationSpendAlert).isEqualTo(organizationSpendAlert) + } +} diff --git a/openai-java-core/src/test/kotlin/com/openai/models/admin/organization/spendalerts/SpendAlertCreateParamsTest.kt b/openai-java-core/src/test/kotlin/com/openai/models/admin/organization/spendalerts/SpendAlertCreateParamsTest.kt new file mode 100644 index 000000000..f2e2fef57 --- /dev/null +++ b/openai-java-core/src/test/kotlin/com/openai/models/admin/organization/spendalerts/SpendAlertCreateParamsTest.kt @@ -0,0 +1,78 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.models.admin.organization.spendalerts + +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test + +internal class SpendAlertCreateParamsTest { + + @Test + fun create() { + SpendAlertCreateParams.builder() + .currency(SpendAlertCreateParams.Currency.USD) + .interval(SpendAlertCreateParams.Interval.MONTH) + .notificationChannel( + SpendAlertCreateParams.NotificationChannel.builder() + .addRecipient("string") + .subjectPrefix("subject_prefix") + .build() + ) + .thresholdAmount(0L) + .build() + } + + @Test + fun body() { + val params = + SpendAlertCreateParams.builder() + .currency(SpendAlertCreateParams.Currency.USD) + .interval(SpendAlertCreateParams.Interval.MONTH) + .notificationChannel( + SpendAlertCreateParams.NotificationChannel.builder() + .addRecipient("string") + .subjectPrefix("subject_prefix") + .build() + ) + .thresholdAmount(0L) + .build() + + val body = params._body() + + assertThat(body.currency()).isEqualTo(SpendAlertCreateParams.Currency.USD) + assertThat(body.interval()).isEqualTo(SpendAlertCreateParams.Interval.MONTH) + assertThat(body.notificationChannel()) + .isEqualTo( + SpendAlertCreateParams.NotificationChannel.builder() + .addRecipient("string") + .subjectPrefix("subject_prefix") + .build() + ) + assertThat(body.thresholdAmount()).isEqualTo(0L) + } + + @Test + fun bodyWithoutOptionalFields() { + val params = + SpendAlertCreateParams.builder() + .currency(SpendAlertCreateParams.Currency.USD) + .interval(SpendAlertCreateParams.Interval.MONTH) + .notificationChannel( + SpendAlertCreateParams.NotificationChannel.builder() + .addRecipient("string") + .build() + ) + .thresholdAmount(0L) + .build() + + val body = params._body() + + assertThat(body.currency()).isEqualTo(SpendAlertCreateParams.Currency.USD) + assertThat(body.interval()).isEqualTo(SpendAlertCreateParams.Interval.MONTH) + assertThat(body.notificationChannel()) + .isEqualTo( + SpendAlertCreateParams.NotificationChannel.builder().addRecipient("string").build() + ) + assertThat(body.thresholdAmount()).isEqualTo(0L) + } +} diff --git a/openai-java-core/src/test/kotlin/com/openai/models/admin/organization/spendalerts/SpendAlertDeleteParamsTest.kt b/openai-java-core/src/test/kotlin/com/openai/models/admin/organization/spendalerts/SpendAlertDeleteParamsTest.kt new file mode 100644 index 000000000..54ce4e380 --- /dev/null +++ b/openai-java-core/src/test/kotlin/com/openai/models/admin/organization/spendalerts/SpendAlertDeleteParamsTest.kt @@ -0,0 +1,23 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.models.admin.organization.spendalerts + +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test + +internal class SpendAlertDeleteParamsTest { + + @Test + fun create() { + SpendAlertDeleteParams.builder().alertId("alert_id").build() + } + + @Test + fun pathParams() { + val params = SpendAlertDeleteParams.builder().alertId("alert_id").build() + + assertThat(params._pathParam(0)).isEqualTo("alert_id") + // out-of-bound path param + assertThat(params._pathParam(1)).isEqualTo("") + } +} diff --git a/openai-java-core/src/test/kotlin/com/openai/models/admin/organization/spendalerts/SpendAlertListPageResponseTest.kt b/openai-java-core/src/test/kotlin/com/openai/models/admin/organization/spendalerts/SpendAlertListPageResponseTest.kt new file mode 100644 index 000000000..aabfff94a --- /dev/null +++ b/openai-java-core/src/test/kotlin/com/openai/models/admin/organization/spendalerts/SpendAlertListPageResponseTest.kt @@ -0,0 +1,87 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.models.admin.organization.spendalerts + +import com.fasterxml.jackson.module.kotlin.jacksonTypeRef +import com.openai.core.jsonMapper +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test + +internal class SpendAlertListPageResponseTest { + + @Test + fun create() { + val spendAlertListPageResponse = + SpendAlertListPageResponse.builder() + .addData( + OrganizationSpendAlert.builder() + .id("id") + .currency(OrganizationSpendAlert.Currency.USD) + .interval(OrganizationSpendAlert.Interval.MONTH) + .notificationChannel( + OrganizationSpendAlert.NotificationChannel.builder() + .addRecipient("string") + .subjectPrefix("subject_prefix") + .build() + ) + .thresholdAmount(0L) + .build() + ) + .firstId("first_id") + .hasMore(true) + .lastId("last_id") + .build() + + assertThat(spendAlertListPageResponse.data()) + .containsExactly( + OrganizationSpendAlert.builder() + .id("id") + .currency(OrganizationSpendAlert.Currency.USD) + .interval(OrganizationSpendAlert.Interval.MONTH) + .notificationChannel( + OrganizationSpendAlert.NotificationChannel.builder() + .addRecipient("string") + .subjectPrefix("subject_prefix") + .build() + ) + .thresholdAmount(0L) + .build() + ) + assertThat(spendAlertListPageResponse.firstId()).contains("first_id") + assertThat(spendAlertListPageResponse.hasMore()).isEqualTo(true) + assertThat(spendAlertListPageResponse.lastId()).contains("last_id") + } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val spendAlertListPageResponse = + SpendAlertListPageResponse.builder() + .addData( + OrganizationSpendAlert.builder() + .id("id") + .currency(OrganizationSpendAlert.Currency.USD) + .interval(OrganizationSpendAlert.Interval.MONTH) + .notificationChannel( + OrganizationSpendAlert.NotificationChannel.builder() + .addRecipient("string") + .subjectPrefix("subject_prefix") + .build() + ) + .thresholdAmount(0L) + .build() + ) + .firstId("first_id") + .hasMore(true) + .lastId("last_id") + .build() + + val roundtrippedSpendAlertListPageResponse = + jsonMapper.readValue( + jsonMapper.writeValueAsString(spendAlertListPageResponse), + jacksonTypeRef(), + ) + + assertThat(roundtrippedSpendAlertListPageResponse).isEqualTo(spendAlertListPageResponse) + } +} diff --git a/openai-java-core/src/test/kotlin/com/openai/models/admin/organization/spendalerts/SpendAlertListParamsTest.kt b/openai-java-core/src/test/kotlin/com/openai/models/admin/organization/spendalerts/SpendAlertListParamsTest.kt new file mode 100644 index 000000000..c650b5cdf --- /dev/null +++ b/openai-java-core/src/test/kotlin/com/openai/models/admin/organization/spendalerts/SpendAlertListParamsTest.kt @@ -0,0 +1,52 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.models.admin.organization.spendalerts + +import com.openai.core.http.QueryParams +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test + +internal class SpendAlertListParamsTest { + + @Test + fun create() { + SpendAlertListParams.builder() + .after("after") + .before("before") + .limit(0L) + .order(SpendAlertListParams.Order.ASC) + .build() + } + + @Test + fun queryParams() { + val params = + SpendAlertListParams.builder() + .after("after") + .before("before") + .limit(0L) + .order(SpendAlertListParams.Order.ASC) + .build() + + val queryParams = params._queryParams() + + assertThat(queryParams) + .isEqualTo( + QueryParams.builder() + .put("after", "after") + .put("before", "before") + .put("limit", "0") + .put("order", "asc") + .build() + ) + } + + @Test + fun queryParamsWithoutOptionalFields() { + val params = SpendAlertListParams.builder().build() + + val queryParams = params._queryParams() + + assertThat(queryParams).isEqualTo(QueryParams.builder().build()) + } +} diff --git a/openai-java-core/src/test/kotlin/com/openai/models/admin/organization/spendalerts/SpendAlertUpdateParamsTest.kt b/openai-java-core/src/test/kotlin/com/openai/models/admin/organization/spendalerts/SpendAlertUpdateParamsTest.kt new file mode 100644 index 000000000..98e2ee92f --- /dev/null +++ b/openai-java-core/src/test/kotlin/com/openai/models/admin/organization/spendalerts/SpendAlertUpdateParamsTest.kt @@ -0,0 +1,101 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.models.admin.organization.spendalerts + +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test + +internal class SpendAlertUpdateParamsTest { + + @Test + fun create() { + SpendAlertUpdateParams.builder() + .alertId("alert_id") + .currency(SpendAlertUpdateParams.Currency.USD) + .interval(SpendAlertUpdateParams.Interval.MONTH) + .notificationChannel( + SpendAlertUpdateParams.NotificationChannel.builder() + .addRecipient("string") + .subjectPrefix("subject_prefix") + .build() + ) + .thresholdAmount(0L) + .build() + } + + @Test + fun pathParams() { + val params = + SpendAlertUpdateParams.builder() + .alertId("alert_id") + .currency(SpendAlertUpdateParams.Currency.USD) + .interval(SpendAlertUpdateParams.Interval.MONTH) + .notificationChannel( + SpendAlertUpdateParams.NotificationChannel.builder() + .addRecipient("string") + .build() + ) + .thresholdAmount(0L) + .build() + + assertThat(params._pathParam(0)).isEqualTo("alert_id") + // out-of-bound path param + assertThat(params._pathParam(1)).isEqualTo("") + } + + @Test + fun body() { + val params = + SpendAlertUpdateParams.builder() + .alertId("alert_id") + .currency(SpendAlertUpdateParams.Currency.USD) + .interval(SpendAlertUpdateParams.Interval.MONTH) + .notificationChannel( + SpendAlertUpdateParams.NotificationChannel.builder() + .addRecipient("string") + .subjectPrefix("subject_prefix") + .build() + ) + .thresholdAmount(0L) + .build() + + val body = params._body() + + assertThat(body.currency()).isEqualTo(SpendAlertUpdateParams.Currency.USD) + assertThat(body.interval()).isEqualTo(SpendAlertUpdateParams.Interval.MONTH) + assertThat(body.notificationChannel()) + .isEqualTo( + SpendAlertUpdateParams.NotificationChannel.builder() + .addRecipient("string") + .subjectPrefix("subject_prefix") + .build() + ) + assertThat(body.thresholdAmount()).isEqualTo(0L) + } + + @Test + fun bodyWithoutOptionalFields() { + val params = + SpendAlertUpdateParams.builder() + .alertId("alert_id") + .currency(SpendAlertUpdateParams.Currency.USD) + .interval(SpendAlertUpdateParams.Interval.MONTH) + .notificationChannel( + SpendAlertUpdateParams.NotificationChannel.builder() + .addRecipient("string") + .build() + ) + .thresholdAmount(0L) + .build() + + val body = params._body() + + assertThat(body.currency()).isEqualTo(SpendAlertUpdateParams.Currency.USD) + assertThat(body.interval()).isEqualTo(SpendAlertUpdateParams.Interval.MONTH) + assertThat(body.notificationChannel()) + .isEqualTo( + SpendAlertUpdateParams.NotificationChannel.builder().addRecipient("string").build() + ) + assertThat(body.thresholdAmount()).isEqualTo(0L) + } +} diff --git a/openai-java-core/src/test/kotlin/com/openai/models/admin/organization/users/roles/RoleListPageResponseTest.kt b/openai-java-core/src/test/kotlin/com/openai/models/admin/organization/users/roles/RoleListPageResponseTest.kt index 2a0df3041..b4a9d80df 100644 --- a/openai-java-core/src/test/kotlin/com/openai/models/admin/organization/users/roles/RoleListPageResponseTest.kt +++ b/openai-java-core/src/test/kotlin/com/openai/models/admin/organization/users/roles/RoleListPageResponseTest.kt @@ -17,6 +17,12 @@ internal class RoleListPageResponseTest { .addData( RoleListResponse.builder() .id("id") + .addAssignmentSource( + RoleListResponse.AssignmentSource.builder() + .principalId("principal_id") + .principalType("principal_type") + .build() + ) .createdAt(0L) .createdBy("created_by") .createdByUserObj( @@ -45,6 +51,12 @@ internal class RoleListPageResponseTest { .containsExactly( RoleListResponse.builder() .id("id") + .addAssignmentSource( + RoleListResponse.AssignmentSource.builder() + .principalId("principal_id") + .principalType("principal_type") + .build() + ) .createdAt(0L) .createdBy("created_by") .createdByUserObj( @@ -77,6 +89,12 @@ internal class RoleListPageResponseTest { .addData( RoleListResponse.builder() .id("id") + .addAssignmentSource( + RoleListResponse.AssignmentSource.builder() + .principalId("principal_id") + .principalType("principal_type") + .build() + ) .createdAt(0L) .createdBy("created_by") .createdByUserObj( diff --git a/openai-java-core/src/test/kotlin/com/openai/models/admin/organization/users/roles/RoleListResponseTest.kt b/openai-java-core/src/test/kotlin/com/openai/models/admin/organization/users/roles/RoleListResponseTest.kt index 45ea92f38..84f863457 100644 --- a/openai-java-core/src/test/kotlin/com/openai/models/admin/organization/users/roles/RoleListResponseTest.kt +++ b/openai-java-core/src/test/kotlin/com/openai/models/admin/organization/users/roles/RoleListResponseTest.kt @@ -5,6 +5,7 @@ package com.openai.models.admin.organization.users.roles import com.fasterxml.jackson.module.kotlin.jacksonTypeRef import com.openai.core.JsonValue import com.openai.core.jsonMapper +import kotlin.jvm.optionals.getOrNull import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.Test @@ -15,6 +16,12 @@ internal class RoleListResponseTest { val roleListResponse = RoleListResponse.builder() .id("id") + .addAssignmentSource( + RoleListResponse.AssignmentSource.builder() + .principalId("principal_id") + .principalType("principal_type") + .build() + ) .createdAt(0L) .createdBy("created_by") .createdByUserObj( @@ -36,6 +43,13 @@ internal class RoleListResponseTest { .build() assertThat(roleListResponse.id()).isEqualTo("id") + assertThat(roleListResponse.assignmentSources().getOrNull()) + .containsExactly( + RoleListResponse.AssignmentSource.builder() + .principalId("principal_id") + .principalType("principal_type") + .build() + ) assertThat(roleListResponse.createdAt()).contains(0L) assertThat(roleListResponse.createdBy()).contains("created_by") assertThat(roleListResponse.createdByUserObj()) @@ -64,6 +78,12 @@ internal class RoleListResponseTest { val roleListResponse = RoleListResponse.builder() .id("id") + .addAssignmentSource( + RoleListResponse.AssignmentSource.builder() + .principalId("principal_id") + .principalType("principal_type") + .build() + ) .createdAt(0L) .createdBy("created_by") .createdByUserObj( diff --git a/openai-java-core/src/test/kotlin/com/openai/models/admin/organization/users/roles/RoleRetrieveParamsTest.kt b/openai-java-core/src/test/kotlin/com/openai/models/admin/organization/users/roles/RoleRetrieveParamsTest.kt new file mode 100644 index 000000000..ae6570473 --- /dev/null +++ b/openai-java-core/src/test/kotlin/com/openai/models/admin/organization/users/roles/RoleRetrieveParamsTest.kt @@ -0,0 +1,24 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.models.admin.organization.users.roles + +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test + +internal class RoleRetrieveParamsTest { + + @Test + fun create() { + RoleRetrieveParams.builder().userId("user_id").roleId("role_id").build() + } + + @Test + fun pathParams() { + val params = RoleRetrieveParams.builder().userId("user_id").roleId("role_id").build() + + assertThat(params._pathParam(0)).isEqualTo("user_id") + assertThat(params._pathParam(1)).isEqualTo("role_id") + // out-of-bound path param + assertThat(params._pathParam(2)).isEqualTo("") + } +} diff --git a/openai-java-core/src/test/kotlin/com/openai/models/admin/organization/users/roles/RoleRetrieveResponseTest.kt b/openai-java-core/src/test/kotlin/com/openai/models/admin/organization/users/roles/RoleRetrieveResponseTest.kt new file mode 100644 index 000000000..00dd4a0b7 --- /dev/null +++ b/openai-java-core/src/test/kotlin/com/openai/models/admin/organization/users/roles/RoleRetrieveResponseTest.kt @@ -0,0 +1,115 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.models.admin.organization.users.roles + +import com.fasterxml.jackson.module.kotlin.jacksonTypeRef +import com.openai.core.JsonValue +import com.openai.core.jsonMapper +import kotlin.jvm.optionals.getOrNull +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test + +internal class RoleRetrieveResponseTest { + + @Test + fun create() { + val roleRetrieveResponse = + RoleRetrieveResponse.builder() + .id("id") + .addAssignmentSource( + RoleRetrieveResponse.AssignmentSource.builder() + .principalId("principal_id") + .principalType("principal_type") + .build() + ) + .createdAt(0L) + .createdBy("created_by") + .createdByUserObj( + RoleRetrieveResponse.CreatedByUserObj.builder() + .putAdditionalProperty("foo", JsonValue.from("bar")) + .build() + ) + .description("description") + .metadata( + RoleRetrieveResponse.Metadata.builder() + .putAdditionalProperty("foo", JsonValue.from("bar")) + .build() + ) + .name("name") + .addPermission("string") + .predefinedRole(true) + .resourceType("resource_type") + .updatedAt(0L) + .build() + + assertThat(roleRetrieveResponse.id()).isEqualTo("id") + assertThat(roleRetrieveResponse.assignmentSources().getOrNull()) + .containsExactly( + RoleRetrieveResponse.AssignmentSource.builder() + .principalId("principal_id") + .principalType("principal_type") + .build() + ) + assertThat(roleRetrieveResponse.createdAt()).contains(0L) + assertThat(roleRetrieveResponse.createdBy()).contains("created_by") + assertThat(roleRetrieveResponse.createdByUserObj()) + .contains( + RoleRetrieveResponse.CreatedByUserObj.builder() + .putAdditionalProperty("foo", JsonValue.from("bar")) + .build() + ) + assertThat(roleRetrieveResponse.description()).contains("description") + assertThat(roleRetrieveResponse.metadata()) + .contains( + RoleRetrieveResponse.Metadata.builder() + .putAdditionalProperty("foo", JsonValue.from("bar")) + .build() + ) + assertThat(roleRetrieveResponse.name()).isEqualTo("name") + assertThat(roleRetrieveResponse.permissions()).containsExactly("string") + assertThat(roleRetrieveResponse.predefinedRole()).isEqualTo(true) + assertThat(roleRetrieveResponse.resourceType()).isEqualTo("resource_type") + assertThat(roleRetrieveResponse.updatedAt()).contains(0L) + } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val roleRetrieveResponse = + RoleRetrieveResponse.builder() + .id("id") + .addAssignmentSource( + RoleRetrieveResponse.AssignmentSource.builder() + .principalId("principal_id") + .principalType("principal_type") + .build() + ) + .createdAt(0L) + .createdBy("created_by") + .createdByUserObj( + RoleRetrieveResponse.CreatedByUserObj.builder() + .putAdditionalProperty("foo", JsonValue.from("bar")) + .build() + ) + .description("description") + .metadata( + RoleRetrieveResponse.Metadata.builder() + .putAdditionalProperty("foo", JsonValue.from("bar")) + .build() + ) + .name("name") + .addPermission("string") + .predefinedRole(true) + .resourceType("resource_type") + .updatedAt(0L) + .build() + + val roundtrippedRoleRetrieveResponse = + jsonMapper.readValue( + jsonMapper.writeValueAsString(roleRetrieveResponse), + jacksonTypeRef(), + ) + + assertThat(roundtrippedRoleRetrieveResponse).isEqualTo(roleRetrieveResponse) + } +} diff --git a/openai-java-core/src/test/kotlin/com/openai/services/async/admin/organization/DataRetentionServiceAsyncTest.kt b/openai-java-core/src/test/kotlin/com/openai/services/async/admin/organization/DataRetentionServiceAsyncTest.kt new file mode 100644 index 000000000..8f64929c9 --- /dev/null +++ b/openai-java-core/src/test/kotlin/com/openai/services/async/admin/organization/DataRetentionServiceAsyncTest.kt @@ -0,0 +1,50 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.services.async.admin.organization + +import com.openai.TestServerExtension +import com.openai.client.okhttp.OpenAIOkHttpClientAsync +import com.openai.models.admin.organization.dataretention.DataRetentionUpdateParams +import org.junit.jupiter.api.Test +import org.junit.jupiter.api.extension.ExtendWith + +@ExtendWith(TestServerExtension::class) +internal class DataRetentionServiceAsyncTest { + + @Test + fun retrieve() { + val client = + OpenAIOkHttpClientAsync.builder() + .baseUrl(TestServerExtension.BASE_URL) + .apiKey("My API Key") + .adminApiKey("My Admin API Key") + .build() + val dataRetentionServiceAsync = client.admin().organization().dataRetention() + + val organizationDataRetentionFuture = dataRetentionServiceAsync.retrieve() + + val organizationDataRetention = organizationDataRetentionFuture.get() + organizationDataRetention.validate() + } + + @Test + fun update() { + val client = + OpenAIOkHttpClientAsync.builder() + .baseUrl(TestServerExtension.BASE_URL) + .apiKey("My API Key") + .adminApiKey("My Admin API Key") + .build() + val dataRetentionServiceAsync = client.admin().organization().dataRetention() + + val organizationDataRetentionFuture = + dataRetentionServiceAsync.update( + DataRetentionUpdateParams.builder() + .retentionType(DataRetentionUpdateParams.RetentionType.ZERO_DATA_RETENTION) + .build() + ) + + val organizationDataRetention = organizationDataRetentionFuture.get() + organizationDataRetention.validate() + } +} diff --git a/openai-java-core/src/test/kotlin/com/openai/services/async/admin/organization/GroupServiceAsyncTest.kt b/openai-java-core/src/test/kotlin/com/openai/services/async/admin/organization/GroupServiceAsyncTest.kt index 3c182bf51..7518a9ca2 100644 --- a/openai-java-core/src/test/kotlin/com/openai/services/async/admin/organization/GroupServiceAsyncTest.kt +++ b/openai-java-core/src/test/kotlin/com/openai/services/async/admin/organization/GroupServiceAsyncTest.kt @@ -28,6 +28,22 @@ internal class GroupServiceAsyncTest { group.validate() } + @Test + fun retrieve() { + val client = + OpenAIOkHttpClientAsync.builder() + .baseUrl(TestServerExtension.BASE_URL) + .apiKey("My API Key") + .adminApiKey("My Admin API Key") + .build() + val groupServiceAsync = client.admin().organization().groups() + + val groupFuture = groupServiceAsync.retrieve("group_id") + + val group = groupFuture.get() + group.validate() + } + @Test fun update() { val client = diff --git a/openai-java-core/src/test/kotlin/com/openai/services/async/admin/organization/RoleServiceAsyncTest.kt b/openai-java-core/src/test/kotlin/com/openai/services/async/admin/organization/RoleServiceAsyncTest.kt index cb428ce84..a09e2c0e5 100644 --- a/openai-java-core/src/test/kotlin/com/openai/services/async/admin/organization/RoleServiceAsyncTest.kt +++ b/openai-java-core/src/test/kotlin/com/openai/services/async/admin/organization/RoleServiceAsyncTest.kt @@ -35,6 +35,22 @@ internal class RoleServiceAsyncTest { role.validate() } + @Test + fun retrieve() { + val client = + OpenAIOkHttpClientAsync.builder() + .baseUrl(TestServerExtension.BASE_URL) + .apiKey("My API Key") + .adminApiKey("My Admin API Key") + .build() + val roleServiceAsync = client.admin().organization().roles() + + val roleFuture = roleServiceAsync.retrieve("role_id") + + val role = roleFuture.get() + role.validate() + } + @Test fun update() { val client = diff --git a/openai-java-core/src/test/kotlin/com/openai/services/async/admin/organization/SpendAlertServiceAsyncTest.kt b/openai-java-core/src/test/kotlin/com/openai/services/async/admin/organization/SpendAlertServiceAsyncTest.kt new file mode 100644 index 000000000..a208e2064 --- /dev/null +++ b/openai-java-core/src/test/kotlin/com/openai/services/async/admin/organization/SpendAlertServiceAsyncTest.kt @@ -0,0 +1,105 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.services.async.admin.organization + +import com.openai.TestServerExtension +import com.openai.client.okhttp.OpenAIOkHttpClientAsync +import com.openai.models.admin.organization.spendalerts.SpendAlertCreateParams +import com.openai.models.admin.organization.spendalerts.SpendAlertUpdateParams +import org.junit.jupiter.api.Test +import org.junit.jupiter.api.extension.ExtendWith + +@ExtendWith(TestServerExtension::class) +internal class SpendAlertServiceAsyncTest { + + @Test + fun create() { + val client = + OpenAIOkHttpClientAsync.builder() + .baseUrl(TestServerExtension.BASE_URL) + .apiKey("My API Key") + .adminApiKey("My Admin API Key") + .build() + val spendAlertServiceAsync = client.admin().organization().spendAlerts() + + val organizationSpendAlertFuture = + spendAlertServiceAsync.create( + SpendAlertCreateParams.builder() + .currency(SpendAlertCreateParams.Currency.USD) + .interval(SpendAlertCreateParams.Interval.MONTH) + .notificationChannel( + SpendAlertCreateParams.NotificationChannel.builder() + .addRecipient("string") + .subjectPrefix("subject_prefix") + .build() + ) + .thresholdAmount(0L) + .build() + ) + + val organizationSpendAlert = organizationSpendAlertFuture.get() + organizationSpendAlert.validate() + } + + @Test + fun update() { + val client = + OpenAIOkHttpClientAsync.builder() + .baseUrl(TestServerExtension.BASE_URL) + .apiKey("My API Key") + .adminApiKey("My Admin API Key") + .build() + val spendAlertServiceAsync = client.admin().organization().spendAlerts() + + val organizationSpendAlertFuture = + spendAlertServiceAsync.update( + SpendAlertUpdateParams.builder() + .alertId("alert_id") + .currency(SpendAlertUpdateParams.Currency.USD) + .interval(SpendAlertUpdateParams.Interval.MONTH) + .notificationChannel( + SpendAlertUpdateParams.NotificationChannel.builder() + .addRecipient("string") + .subjectPrefix("subject_prefix") + .build() + ) + .thresholdAmount(0L) + .build() + ) + + val organizationSpendAlert = organizationSpendAlertFuture.get() + organizationSpendAlert.validate() + } + + @Test + fun list() { + val client = + OpenAIOkHttpClientAsync.builder() + .baseUrl(TestServerExtension.BASE_URL) + .apiKey("My API Key") + .adminApiKey("My Admin API Key") + .build() + val spendAlertServiceAsync = client.admin().organization().spendAlerts() + + val pageFuture = spendAlertServiceAsync.list() + + val page = pageFuture.get() + page.response().validate() + } + + @Test + fun delete() { + val client = + OpenAIOkHttpClientAsync.builder() + .baseUrl(TestServerExtension.BASE_URL) + .apiKey("My API Key") + .adminApiKey("My Admin API Key") + .build() + val spendAlertServiceAsync = client.admin().organization().spendAlerts() + + val organizationSpendAlertDeletedFuture = spendAlertServiceAsync.delete("alert_id") + + val organizationSpendAlertDeleted = organizationSpendAlertDeletedFuture.get() + organizationSpendAlertDeleted.validate() + } +} diff --git a/openai-java-core/src/test/kotlin/com/openai/services/async/admin/organization/groups/RoleServiceAsyncTest.kt b/openai-java-core/src/test/kotlin/com/openai/services/async/admin/organization/groups/RoleServiceAsyncTest.kt index bf89204bb..436c8ac2e 100644 --- a/openai-java-core/src/test/kotlin/com/openai/services/async/admin/organization/groups/RoleServiceAsyncTest.kt +++ b/openai-java-core/src/test/kotlin/com/openai/services/async/admin/organization/groups/RoleServiceAsyncTest.kt @@ -6,6 +6,7 @@ import com.openai.TestServerExtension import com.openai.client.okhttp.OpenAIOkHttpClientAsync import com.openai.models.admin.organization.groups.roles.RoleCreateParams import com.openai.models.admin.organization.groups.roles.RoleDeleteParams +import com.openai.models.admin.organization.groups.roles.RoleRetrieveParams import org.junit.jupiter.api.Test import org.junit.jupiter.api.extension.ExtendWith @@ -31,6 +32,25 @@ internal class RoleServiceAsyncTest { role.validate() } + @Test + fun retrieve() { + val client = + OpenAIOkHttpClientAsync.builder() + .baseUrl(TestServerExtension.BASE_URL) + .apiKey("My API Key") + .adminApiKey("My Admin API Key") + .build() + val roleServiceAsync = client.admin().organization().groups().roles() + + val roleFuture = + roleServiceAsync.retrieve( + RoleRetrieveParams.builder().groupId("group_id").roleId("role_id").build() + ) + + val role = roleFuture.get() + role.validate() + } + @Test fun list() { val client = diff --git a/openai-java-core/src/test/kotlin/com/openai/services/async/admin/organization/groups/UserServiceAsyncTest.kt b/openai-java-core/src/test/kotlin/com/openai/services/async/admin/organization/groups/UserServiceAsyncTest.kt index e9e0e71ab..d5756d780 100644 --- a/openai-java-core/src/test/kotlin/com/openai/services/async/admin/organization/groups/UserServiceAsyncTest.kt +++ b/openai-java-core/src/test/kotlin/com/openai/services/async/admin/organization/groups/UserServiceAsyncTest.kt @@ -6,6 +6,7 @@ import com.openai.TestServerExtension import com.openai.client.okhttp.OpenAIOkHttpClientAsync import com.openai.models.admin.organization.groups.users.UserCreateParams import com.openai.models.admin.organization.groups.users.UserDeleteParams +import com.openai.models.admin.organization.groups.users.UserRetrieveParams import org.junit.jupiter.api.Test import org.junit.jupiter.api.extension.ExtendWith @@ -31,6 +32,25 @@ internal class UserServiceAsyncTest { user.validate() } + @Test + fun retrieve() { + val client = + OpenAIOkHttpClientAsync.builder() + .baseUrl(TestServerExtension.BASE_URL) + .apiKey("My API Key") + .adminApiKey("My Admin API Key") + .build() + val userServiceAsync = client.admin().organization().groups().users() + + val userFuture = + userServiceAsync.retrieve( + UserRetrieveParams.builder().groupId("group_id").userId("user_id").build() + ) + + val user = userFuture.get() + user.validate() + } + @Test fun list() { val client = diff --git a/openai-java-core/src/test/kotlin/com/openai/services/async/admin/organization/projects/DataRetentionServiceAsyncTest.kt b/openai-java-core/src/test/kotlin/com/openai/services/async/admin/organization/projects/DataRetentionServiceAsyncTest.kt new file mode 100644 index 000000000..851f8b085 --- /dev/null +++ b/openai-java-core/src/test/kotlin/com/openai/services/async/admin/organization/projects/DataRetentionServiceAsyncTest.kt @@ -0,0 +1,51 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.services.async.admin.organization.projects + +import com.openai.TestServerExtension +import com.openai.client.okhttp.OpenAIOkHttpClientAsync +import com.openai.models.admin.organization.projects.dataretention.DataRetentionUpdateParams +import org.junit.jupiter.api.Test +import org.junit.jupiter.api.extension.ExtendWith + +@ExtendWith(TestServerExtension::class) +internal class DataRetentionServiceAsyncTest { + + @Test + fun retrieve() { + val client = + OpenAIOkHttpClientAsync.builder() + .baseUrl(TestServerExtension.BASE_URL) + .apiKey("My API Key") + .adminApiKey("My Admin API Key") + .build() + val dataRetentionServiceAsync = client.admin().organization().projects().dataRetention() + + val projectDataRetentionFuture = dataRetentionServiceAsync.retrieve("project_id") + + val projectDataRetention = projectDataRetentionFuture.get() + projectDataRetention.validate() + } + + @Test + fun update() { + val client = + OpenAIOkHttpClientAsync.builder() + .baseUrl(TestServerExtension.BASE_URL) + .apiKey("My API Key") + .adminApiKey("My Admin API Key") + .build() + val dataRetentionServiceAsync = client.admin().organization().projects().dataRetention() + + val projectDataRetentionFuture = + dataRetentionServiceAsync.update( + DataRetentionUpdateParams.builder() + .projectId("project_id") + .retentionType(DataRetentionUpdateParams.RetentionType.ORGANIZATION_DEFAULT) + .build() + ) + + val projectDataRetention = projectDataRetentionFuture.get() + projectDataRetention.validate() + } +} diff --git a/openai-java-core/src/test/kotlin/com/openai/services/async/admin/organization/projects/GroupServiceAsyncTest.kt b/openai-java-core/src/test/kotlin/com/openai/services/async/admin/organization/projects/GroupServiceAsyncTest.kt index d5217a1ec..0225a7286 100644 --- a/openai-java-core/src/test/kotlin/com/openai/services/async/admin/organization/projects/GroupServiceAsyncTest.kt +++ b/openai-java-core/src/test/kotlin/com/openai/services/async/admin/organization/projects/GroupServiceAsyncTest.kt @@ -6,6 +6,7 @@ import com.openai.TestServerExtension import com.openai.client.okhttp.OpenAIOkHttpClientAsync import com.openai.models.admin.organization.projects.groups.GroupCreateParams import com.openai.models.admin.organization.projects.groups.GroupDeleteParams +import com.openai.models.admin.organization.projects.groups.GroupRetrieveParams import org.junit.jupiter.api.Test import org.junit.jupiter.api.extension.ExtendWith @@ -35,6 +36,29 @@ internal class GroupServiceAsyncTest { projectGroup.validate() } + @Test + fun retrieve() { + val client = + OpenAIOkHttpClientAsync.builder() + .baseUrl(TestServerExtension.BASE_URL) + .apiKey("My API Key") + .adminApiKey("My Admin API Key") + .build() + val groupServiceAsync = client.admin().organization().projects().groups() + + val projectGroupFuture = + groupServiceAsync.retrieve( + GroupRetrieveParams.builder() + .projectId("project_id") + .groupId("group_id") + .groupType(GroupRetrieveParams.GroupType.GROUP) + .build() + ) + + val projectGroup = projectGroupFuture.get() + projectGroup.validate() + } + @Test fun list() { val client = diff --git a/openai-java-core/src/test/kotlin/com/openai/services/async/admin/organization/projects/RoleServiceAsyncTest.kt b/openai-java-core/src/test/kotlin/com/openai/services/async/admin/organization/projects/RoleServiceAsyncTest.kt index b25eb2890..6d87731fd 100644 --- a/openai-java-core/src/test/kotlin/com/openai/services/async/admin/organization/projects/RoleServiceAsyncTest.kt +++ b/openai-java-core/src/test/kotlin/com/openai/services/async/admin/organization/projects/RoleServiceAsyncTest.kt @@ -6,6 +6,7 @@ import com.openai.TestServerExtension import com.openai.client.okhttp.OpenAIOkHttpClientAsync import com.openai.models.admin.organization.projects.roles.RoleCreateParams import com.openai.models.admin.organization.projects.roles.RoleDeleteParams +import com.openai.models.admin.organization.projects.roles.RoleRetrieveParams import com.openai.models.admin.organization.projects.roles.RoleUpdateParams import org.junit.jupiter.api.Test import org.junit.jupiter.api.extension.ExtendWith @@ -37,6 +38,25 @@ internal class RoleServiceAsyncTest { role.validate() } + @Test + fun retrieve() { + val client = + OpenAIOkHttpClientAsync.builder() + .baseUrl(TestServerExtension.BASE_URL) + .apiKey("My API Key") + .adminApiKey("My Admin API Key") + .build() + val roleServiceAsync = client.admin().organization().projects().roles() + + val roleFuture = + roleServiceAsync.retrieve( + RoleRetrieveParams.builder().projectId("project_id").roleId("role_id").build() + ) + + val role = roleFuture.get() + role.validate() + } + @Test fun update() { val client = diff --git a/openai-java-core/src/test/kotlin/com/openai/services/async/admin/organization/projects/ServiceAccountServiceAsyncTest.kt b/openai-java-core/src/test/kotlin/com/openai/services/async/admin/organization/projects/ServiceAccountServiceAsyncTest.kt index be1b8eaca..464914456 100644 --- a/openai-java-core/src/test/kotlin/com/openai/services/async/admin/organization/projects/ServiceAccountServiceAsyncTest.kt +++ b/openai-java-core/src/test/kotlin/com/openai/services/async/admin/organization/projects/ServiceAccountServiceAsyncTest.kt @@ -7,6 +7,7 @@ import com.openai.client.okhttp.OpenAIOkHttpClientAsync import com.openai.models.admin.organization.projects.serviceaccounts.ServiceAccountCreateParams import com.openai.models.admin.organization.projects.serviceaccounts.ServiceAccountDeleteParams import com.openai.models.admin.organization.projects.serviceaccounts.ServiceAccountRetrieveParams +import com.openai.models.admin.organization.projects.serviceaccounts.ServiceAccountUpdateParams import org.junit.jupiter.api.Test import org.junit.jupiter.api.extension.ExtendWith @@ -54,6 +55,30 @@ internal class ServiceAccountServiceAsyncTest { projectServiceAccount.validate() } + @Test + fun update() { + val client = + OpenAIOkHttpClientAsync.builder() + .baseUrl(TestServerExtension.BASE_URL) + .apiKey("My API Key") + .adminApiKey("My Admin API Key") + .build() + val serviceAccountServiceAsync = client.admin().organization().projects().serviceAccounts() + + val projectServiceAccountFuture = + serviceAccountServiceAsync.update( + ServiceAccountUpdateParams.builder() + .projectId("project_id") + .serviceAccountId("service_account_id") + .name("name") + .role(ServiceAccountUpdateParams.Role.MEMBER) + .build() + ) + + val projectServiceAccount = projectServiceAccountFuture.get() + projectServiceAccount.validate() + } + @Test fun list() { val client = diff --git a/openai-java-core/src/test/kotlin/com/openai/services/async/admin/organization/projects/SpendAlertServiceAsyncTest.kt b/openai-java-core/src/test/kotlin/com/openai/services/async/admin/organization/projects/SpendAlertServiceAsyncTest.kt new file mode 100644 index 000000000..1974faa0c --- /dev/null +++ b/openai-java-core/src/test/kotlin/com/openai/services/async/admin/organization/projects/SpendAlertServiceAsyncTest.kt @@ -0,0 +1,111 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.services.async.admin.organization.projects + +import com.openai.TestServerExtension +import com.openai.client.okhttp.OpenAIOkHttpClientAsync +import com.openai.models.admin.organization.projects.spendalerts.SpendAlertCreateParams +import com.openai.models.admin.organization.projects.spendalerts.SpendAlertDeleteParams +import com.openai.models.admin.organization.projects.spendalerts.SpendAlertUpdateParams +import org.junit.jupiter.api.Test +import org.junit.jupiter.api.extension.ExtendWith + +@ExtendWith(TestServerExtension::class) +internal class SpendAlertServiceAsyncTest { + + @Test + fun create() { + val client = + OpenAIOkHttpClientAsync.builder() + .baseUrl(TestServerExtension.BASE_URL) + .apiKey("My API Key") + .adminApiKey("My Admin API Key") + .build() + val spendAlertServiceAsync = client.admin().organization().projects().spendAlerts() + + val projectSpendAlertFuture = + spendAlertServiceAsync.create( + SpendAlertCreateParams.builder() + .projectId("project_id") + .currency(SpendAlertCreateParams.Currency.USD) + .interval(SpendAlertCreateParams.Interval.MONTH) + .notificationChannel( + SpendAlertCreateParams.NotificationChannel.builder() + .addRecipient("string") + .subjectPrefix("subject_prefix") + .build() + ) + .thresholdAmount(0L) + .build() + ) + + val projectSpendAlert = projectSpendAlertFuture.get() + projectSpendAlert.validate() + } + + @Test + fun update() { + val client = + OpenAIOkHttpClientAsync.builder() + .baseUrl(TestServerExtension.BASE_URL) + .apiKey("My API Key") + .adminApiKey("My Admin API Key") + .build() + val spendAlertServiceAsync = client.admin().organization().projects().spendAlerts() + + val projectSpendAlertFuture = + spendAlertServiceAsync.update( + SpendAlertUpdateParams.builder() + .projectId("project_id") + .alertId("alert_id") + .currency(SpendAlertUpdateParams.Currency.USD) + .interval(SpendAlertUpdateParams.Interval.MONTH) + .notificationChannel( + SpendAlertUpdateParams.NotificationChannel.builder() + .addRecipient("string") + .subjectPrefix("subject_prefix") + .build() + ) + .thresholdAmount(0L) + .build() + ) + + val projectSpendAlert = projectSpendAlertFuture.get() + projectSpendAlert.validate() + } + + @Test + fun list() { + val client = + OpenAIOkHttpClientAsync.builder() + .baseUrl(TestServerExtension.BASE_URL) + .apiKey("My API Key") + .adminApiKey("My Admin API Key") + .build() + val spendAlertServiceAsync = client.admin().organization().projects().spendAlerts() + + val pageFuture = spendAlertServiceAsync.list("project_id") + + val page = pageFuture.get() + page.response().validate() + } + + @Test + fun delete() { + val client = + OpenAIOkHttpClientAsync.builder() + .baseUrl(TestServerExtension.BASE_URL) + .apiKey("My API Key") + .adminApiKey("My Admin API Key") + .build() + val spendAlertServiceAsync = client.admin().organization().projects().spendAlerts() + + val projectSpendAlertDeletedFuture = + spendAlertServiceAsync.delete( + SpendAlertDeleteParams.builder().projectId("project_id").alertId("alert_id").build() + ) + + val projectSpendAlertDeleted = projectSpendAlertDeletedFuture.get() + projectSpendAlertDeleted.validate() + } +} diff --git a/openai-java-core/src/test/kotlin/com/openai/services/async/admin/organization/projects/groups/RoleServiceAsyncTest.kt b/openai-java-core/src/test/kotlin/com/openai/services/async/admin/organization/projects/groups/RoleServiceAsyncTest.kt index 7b13a1495..18201aa8a 100644 --- a/openai-java-core/src/test/kotlin/com/openai/services/async/admin/organization/projects/groups/RoleServiceAsyncTest.kt +++ b/openai-java-core/src/test/kotlin/com/openai/services/async/admin/organization/projects/groups/RoleServiceAsyncTest.kt @@ -7,6 +7,7 @@ import com.openai.client.okhttp.OpenAIOkHttpClientAsync import com.openai.models.admin.organization.projects.groups.roles.RoleCreateParams import com.openai.models.admin.organization.projects.groups.roles.RoleDeleteParams import com.openai.models.admin.organization.projects.groups.roles.RoleListParams +import com.openai.models.admin.organization.projects.groups.roles.RoleRetrieveParams import org.junit.jupiter.api.Test import org.junit.jupiter.api.extension.ExtendWith @@ -36,6 +37,29 @@ internal class RoleServiceAsyncTest { role.validate() } + @Test + fun retrieve() { + val client = + OpenAIOkHttpClientAsync.builder() + .baseUrl(TestServerExtension.BASE_URL) + .apiKey("My API Key") + .adminApiKey("My Admin API Key") + .build() + val roleServiceAsync = client.admin().organization().projects().groups().roles() + + val roleFuture = + roleServiceAsync.retrieve( + RoleRetrieveParams.builder() + .projectId("project_id") + .groupId("group_id") + .roleId("role_id") + .build() + ) + + val role = roleFuture.get() + role.validate() + } + @Test fun list() { val client = diff --git a/openai-java-core/src/test/kotlin/com/openai/services/async/admin/organization/projects/users/RoleServiceAsyncTest.kt b/openai-java-core/src/test/kotlin/com/openai/services/async/admin/organization/projects/users/RoleServiceAsyncTest.kt index 82d6e605d..4de8a2fd3 100644 --- a/openai-java-core/src/test/kotlin/com/openai/services/async/admin/organization/projects/users/RoleServiceAsyncTest.kt +++ b/openai-java-core/src/test/kotlin/com/openai/services/async/admin/organization/projects/users/RoleServiceAsyncTest.kt @@ -7,6 +7,7 @@ import com.openai.client.okhttp.OpenAIOkHttpClientAsync import com.openai.models.admin.organization.projects.users.roles.RoleCreateParams import com.openai.models.admin.organization.projects.users.roles.RoleDeleteParams import com.openai.models.admin.organization.projects.users.roles.RoleListParams +import com.openai.models.admin.organization.projects.users.roles.RoleRetrieveParams import org.junit.jupiter.api.Test import org.junit.jupiter.api.extension.ExtendWith @@ -36,6 +37,29 @@ internal class RoleServiceAsyncTest { role.validate() } + @Test + fun retrieve() { + val client = + OpenAIOkHttpClientAsync.builder() + .baseUrl(TestServerExtension.BASE_URL) + .apiKey("My API Key") + .adminApiKey("My Admin API Key") + .build() + val roleServiceAsync = client.admin().organization().projects().users().roles() + + val roleFuture = + roleServiceAsync.retrieve( + RoleRetrieveParams.builder() + .projectId("project_id") + .userId("user_id") + .roleId("role_id") + .build() + ) + + val role = roleFuture.get() + role.validate() + } + @Test fun list() { val client = diff --git a/openai-java-core/src/test/kotlin/com/openai/services/async/admin/organization/users/RoleServiceAsyncTest.kt b/openai-java-core/src/test/kotlin/com/openai/services/async/admin/organization/users/RoleServiceAsyncTest.kt index 0616d05b6..4f42d560a 100644 --- a/openai-java-core/src/test/kotlin/com/openai/services/async/admin/organization/users/RoleServiceAsyncTest.kt +++ b/openai-java-core/src/test/kotlin/com/openai/services/async/admin/organization/users/RoleServiceAsyncTest.kt @@ -6,6 +6,7 @@ import com.openai.TestServerExtension import com.openai.client.okhttp.OpenAIOkHttpClientAsync import com.openai.models.admin.organization.users.roles.RoleCreateParams import com.openai.models.admin.organization.users.roles.RoleDeleteParams +import com.openai.models.admin.organization.users.roles.RoleRetrieveParams import org.junit.jupiter.api.Test import org.junit.jupiter.api.extension.ExtendWith @@ -31,6 +32,25 @@ internal class RoleServiceAsyncTest { role.validate() } + @Test + fun retrieve() { + val client = + OpenAIOkHttpClientAsync.builder() + .baseUrl(TestServerExtension.BASE_URL) + .apiKey("My API Key") + .adminApiKey("My Admin API Key") + .build() + val roleServiceAsync = client.admin().organization().users().roles() + + val roleFuture = + roleServiceAsync.retrieve( + RoleRetrieveParams.builder().userId("user_id").roleId("role_id").build() + ) + + val role = roleFuture.get() + role.validate() + } + @Test fun list() { val client = diff --git a/openai-java-core/src/test/kotlin/com/openai/services/blocking/admin/organization/DataRetentionServiceTest.kt b/openai-java-core/src/test/kotlin/com/openai/services/blocking/admin/organization/DataRetentionServiceTest.kt new file mode 100644 index 000000000..1f0369ef3 --- /dev/null +++ b/openai-java-core/src/test/kotlin/com/openai/services/blocking/admin/organization/DataRetentionServiceTest.kt @@ -0,0 +1,48 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.services.blocking.admin.organization + +import com.openai.TestServerExtension +import com.openai.client.okhttp.OpenAIOkHttpClient +import com.openai.models.admin.organization.dataretention.DataRetentionUpdateParams +import org.junit.jupiter.api.Test +import org.junit.jupiter.api.extension.ExtendWith + +@ExtendWith(TestServerExtension::class) +internal class DataRetentionServiceTest { + + @Test + fun retrieve() { + val client = + OpenAIOkHttpClient.builder() + .baseUrl(TestServerExtension.BASE_URL) + .apiKey("My API Key") + .adminApiKey("My Admin API Key") + .build() + val dataRetentionService = client.admin().organization().dataRetention() + + val organizationDataRetention = dataRetentionService.retrieve() + + organizationDataRetention.validate() + } + + @Test + fun update() { + val client = + OpenAIOkHttpClient.builder() + .baseUrl(TestServerExtension.BASE_URL) + .apiKey("My API Key") + .adminApiKey("My Admin API Key") + .build() + val dataRetentionService = client.admin().organization().dataRetention() + + val organizationDataRetention = + dataRetentionService.update( + DataRetentionUpdateParams.builder() + .retentionType(DataRetentionUpdateParams.RetentionType.ZERO_DATA_RETENTION) + .build() + ) + + organizationDataRetention.validate() + } +} diff --git a/openai-java-core/src/test/kotlin/com/openai/services/blocking/admin/organization/GroupServiceTest.kt b/openai-java-core/src/test/kotlin/com/openai/services/blocking/admin/organization/GroupServiceTest.kt index d2f5a4cbc..3eb4ca9f2 100644 --- a/openai-java-core/src/test/kotlin/com/openai/services/blocking/admin/organization/GroupServiceTest.kt +++ b/openai-java-core/src/test/kotlin/com/openai/services/blocking/admin/organization/GroupServiceTest.kt @@ -27,6 +27,21 @@ internal class GroupServiceTest { group.validate() } + @Test + fun retrieve() { + val client = + OpenAIOkHttpClient.builder() + .baseUrl(TestServerExtension.BASE_URL) + .apiKey("My API Key") + .adminApiKey("My Admin API Key") + .build() + val groupService = client.admin().organization().groups() + + val group = groupService.retrieve("group_id") + + group.validate() + } + @Test fun update() { val client = diff --git a/openai-java-core/src/test/kotlin/com/openai/services/blocking/admin/organization/RoleServiceTest.kt b/openai-java-core/src/test/kotlin/com/openai/services/blocking/admin/organization/RoleServiceTest.kt index 142e0c0c7..842760111 100644 --- a/openai-java-core/src/test/kotlin/com/openai/services/blocking/admin/organization/RoleServiceTest.kt +++ b/openai-java-core/src/test/kotlin/com/openai/services/blocking/admin/organization/RoleServiceTest.kt @@ -34,6 +34,21 @@ internal class RoleServiceTest { role.validate() } + @Test + fun retrieve() { + val client = + OpenAIOkHttpClient.builder() + .baseUrl(TestServerExtension.BASE_URL) + .apiKey("My API Key") + .adminApiKey("My Admin API Key") + .build() + val roleService = client.admin().organization().roles() + + val role = roleService.retrieve("role_id") + + role.validate() + } + @Test fun update() { val client = diff --git a/openai-java-core/src/test/kotlin/com/openai/services/blocking/admin/organization/SpendAlertServiceTest.kt b/openai-java-core/src/test/kotlin/com/openai/services/blocking/admin/organization/SpendAlertServiceTest.kt new file mode 100644 index 000000000..bd1d7f3c9 --- /dev/null +++ b/openai-java-core/src/test/kotlin/com/openai/services/blocking/admin/organization/SpendAlertServiceTest.kt @@ -0,0 +1,101 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.services.blocking.admin.organization + +import com.openai.TestServerExtension +import com.openai.client.okhttp.OpenAIOkHttpClient +import com.openai.models.admin.organization.spendalerts.SpendAlertCreateParams +import com.openai.models.admin.organization.spendalerts.SpendAlertUpdateParams +import org.junit.jupiter.api.Test +import org.junit.jupiter.api.extension.ExtendWith + +@ExtendWith(TestServerExtension::class) +internal class SpendAlertServiceTest { + + @Test + fun create() { + val client = + OpenAIOkHttpClient.builder() + .baseUrl(TestServerExtension.BASE_URL) + .apiKey("My API Key") + .adminApiKey("My Admin API Key") + .build() + val spendAlertService = client.admin().organization().spendAlerts() + + val organizationSpendAlert = + spendAlertService.create( + SpendAlertCreateParams.builder() + .currency(SpendAlertCreateParams.Currency.USD) + .interval(SpendAlertCreateParams.Interval.MONTH) + .notificationChannel( + SpendAlertCreateParams.NotificationChannel.builder() + .addRecipient("string") + .subjectPrefix("subject_prefix") + .build() + ) + .thresholdAmount(0L) + .build() + ) + + organizationSpendAlert.validate() + } + + @Test + fun update() { + val client = + OpenAIOkHttpClient.builder() + .baseUrl(TestServerExtension.BASE_URL) + .apiKey("My API Key") + .adminApiKey("My Admin API Key") + .build() + val spendAlertService = client.admin().organization().spendAlerts() + + val organizationSpendAlert = + spendAlertService.update( + SpendAlertUpdateParams.builder() + .alertId("alert_id") + .currency(SpendAlertUpdateParams.Currency.USD) + .interval(SpendAlertUpdateParams.Interval.MONTH) + .notificationChannel( + SpendAlertUpdateParams.NotificationChannel.builder() + .addRecipient("string") + .subjectPrefix("subject_prefix") + .build() + ) + .thresholdAmount(0L) + .build() + ) + + organizationSpendAlert.validate() + } + + @Test + fun list() { + val client = + OpenAIOkHttpClient.builder() + .baseUrl(TestServerExtension.BASE_URL) + .apiKey("My API Key") + .adminApiKey("My Admin API Key") + .build() + val spendAlertService = client.admin().organization().spendAlerts() + + val page = spendAlertService.list() + + page.response().validate() + } + + @Test + fun delete() { + val client = + OpenAIOkHttpClient.builder() + .baseUrl(TestServerExtension.BASE_URL) + .apiKey("My API Key") + .adminApiKey("My Admin API Key") + .build() + val spendAlertService = client.admin().organization().spendAlerts() + + val organizationSpendAlertDeleted = spendAlertService.delete("alert_id") + + organizationSpendAlertDeleted.validate() + } +} diff --git a/openai-java-core/src/test/kotlin/com/openai/services/blocking/admin/organization/groups/RoleServiceTest.kt b/openai-java-core/src/test/kotlin/com/openai/services/blocking/admin/organization/groups/RoleServiceTest.kt index 1d611bb19..d4e71a7b8 100644 --- a/openai-java-core/src/test/kotlin/com/openai/services/blocking/admin/organization/groups/RoleServiceTest.kt +++ b/openai-java-core/src/test/kotlin/com/openai/services/blocking/admin/organization/groups/RoleServiceTest.kt @@ -6,6 +6,7 @@ import com.openai.TestServerExtension import com.openai.client.okhttp.OpenAIOkHttpClient import com.openai.models.admin.organization.groups.roles.RoleCreateParams import com.openai.models.admin.organization.groups.roles.RoleDeleteParams +import com.openai.models.admin.organization.groups.roles.RoleRetrieveParams import org.junit.jupiter.api.Test import org.junit.jupiter.api.extension.ExtendWith @@ -30,6 +31,24 @@ internal class RoleServiceTest { role.validate() } + @Test + fun retrieve() { + val client = + OpenAIOkHttpClient.builder() + .baseUrl(TestServerExtension.BASE_URL) + .apiKey("My API Key") + .adminApiKey("My Admin API Key") + .build() + val roleService = client.admin().organization().groups().roles() + + val role = + roleService.retrieve( + RoleRetrieveParams.builder().groupId("group_id").roleId("role_id").build() + ) + + role.validate() + } + @Test fun list() { val client = diff --git a/openai-java-core/src/test/kotlin/com/openai/services/blocking/admin/organization/groups/UserServiceTest.kt b/openai-java-core/src/test/kotlin/com/openai/services/blocking/admin/organization/groups/UserServiceTest.kt index 30fc714c1..9c59d6e14 100644 --- a/openai-java-core/src/test/kotlin/com/openai/services/blocking/admin/organization/groups/UserServiceTest.kt +++ b/openai-java-core/src/test/kotlin/com/openai/services/blocking/admin/organization/groups/UserServiceTest.kt @@ -6,6 +6,7 @@ import com.openai.TestServerExtension import com.openai.client.okhttp.OpenAIOkHttpClient import com.openai.models.admin.organization.groups.users.UserCreateParams import com.openai.models.admin.organization.groups.users.UserDeleteParams +import com.openai.models.admin.organization.groups.users.UserRetrieveParams import org.junit.jupiter.api.Test import org.junit.jupiter.api.extension.ExtendWith @@ -30,6 +31,24 @@ internal class UserServiceTest { user.validate() } + @Test + fun retrieve() { + val client = + OpenAIOkHttpClient.builder() + .baseUrl(TestServerExtension.BASE_URL) + .apiKey("My API Key") + .adminApiKey("My Admin API Key") + .build() + val userService = client.admin().organization().groups().users() + + val user = + userService.retrieve( + UserRetrieveParams.builder().groupId("group_id").userId("user_id").build() + ) + + user.validate() + } + @Test fun list() { val client = diff --git a/openai-java-core/src/test/kotlin/com/openai/services/blocking/admin/organization/projects/DataRetentionServiceTest.kt b/openai-java-core/src/test/kotlin/com/openai/services/blocking/admin/organization/projects/DataRetentionServiceTest.kt new file mode 100644 index 000000000..207104a02 --- /dev/null +++ b/openai-java-core/src/test/kotlin/com/openai/services/blocking/admin/organization/projects/DataRetentionServiceTest.kt @@ -0,0 +1,49 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.services.blocking.admin.organization.projects + +import com.openai.TestServerExtension +import com.openai.client.okhttp.OpenAIOkHttpClient +import com.openai.models.admin.organization.projects.dataretention.DataRetentionUpdateParams +import org.junit.jupiter.api.Test +import org.junit.jupiter.api.extension.ExtendWith + +@ExtendWith(TestServerExtension::class) +internal class DataRetentionServiceTest { + + @Test + fun retrieve() { + val client = + OpenAIOkHttpClient.builder() + .baseUrl(TestServerExtension.BASE_URL) + .apiKey("My API Key") + .adminApiKey("My Admin API Key") + .build() + val dataRetentionService = client.admin().organization().projects().dataRetention() + + val projectDataRetention = dataRetentionService.retrieve("project_id") + + projectDataRetention.validate() + } + + @Test + fun update() { + val client = + OpenAIOkHttpClient.builder() + .baseUrl(TestServerExtension.BASE_URL) + .apiKey("My API Key") + .adminApiKey("My Admin API Key") + .build() + val dataRetentionService = client.admin().organization().projects().dataRetention() + + val projectDataRetention = + dataRetentionService.update( + DataRetentionUpdateParams.builder() + .projectId("project_id") + .retentionType(DataRetentionUpdateParams.RetentionType.ORGANIZATION_DEFAULT) + .build() + ) + + projectDataRetention.validate() + } +} diff --git a/openai-java-core/src/test/kotlin/com/openai/services/blocking/admin/organization/projects/GroupServiceTest.kt b/openai-java-core/src/test/kotlin/com/openai/services/blocking/admin/organization/projects/GroupServiceTest.kt index 35c6b6ec5..505aaa218 100644 --- a/openai-java-core/src/test/kotlin/com/openai/services/blocking/admin/organization/projects/GroupServiceTest.kt +++ b/openai-java-core/src/test/kotlin/com/openai/services/blocking/admin/organization/projects/GroupServiceTest.kt @@ -6,6 +6,7 @@ import com.openai.TestServerExtension import com.openai.client.okhttp.OpenAIOkHttpClient import com.openai.models.admin.organization.projects.groups.GroupCreateParams import com.openai.models.admin.organization.projects.groups.GroupDeleteParams +import com.openai.models.admin.organization.projects.groups.GroupRetrieveParams import org.junit.jupiter.api.Test import org.junit.jupiter.api.extension.ExtendWith @@ -34,6 +35,28 @@ internal class GroupServiceTest { projectGroup.validate() } + @Test + fun retrieve() { + val client = + OpenAIOkHttpClient.builder() + .baseUrl(TestServerExtension.BASE_URL) + .apiKey("My API Key") + .adminApiKey("My Admin API Key") + .build() + val groupService = client.admin().organization().projects().groups() + + val projectGroup = + groupService.retrieve( + GroupRetrieveParams.builder() + .projectId("project_id") + .groupId("group_id") + .groupType(GroupRetrieveParams.GroupType.GROUP) + .build() + ) + + projectGroup.validate() + } + @Test fun list() { val client = diff --git a/openai-java-core/src/test/kotlin/com/openai/services/blocking/admin/organization/projects/RoleServiceTest.kt b/openai-java-core/src/test/kotlin/com/openai/services/blocking/admin/organization/projects/RoleServiceTest.kt index dea12af37..cd7653d7f 100644 --- a/openai-java-core/src/test/kotlin/com/openai/services/blocking/admin/organization/projects/RoleServiceTest.kt +++ b/openai-java-core/src/test/kotlin/com/openai/services/blocking/admin/organization/projects/RoleServiceTest.kt @@ -6,6 +6,7 @@ import com.openai.TestServerExtension import com.openai.client.okhttp.OpenAIOkHttpClient import com.openai.models.admin.organization.projects.roles.RoleCreateParams import com.openai.models.admin.organization.projects.roles.RoleDeleteParams +import com.openai.models.admin.organization.projects.roles.RoleRetrieveParams import com.openai.models.admin.organization.projects.roles.RoleUpdateParams import org.junit.jupiter.api.Test import org.junit.jupiter.api.extension.ExtendWith @@ -36,6 +37,24 @@ internal class RoleServiceTest { role.validate() } + @Test + fun retrieve() { + val client = + OpenAIOkHttpClient.builder() + .baseUrl(TestServerExtension.BASE_URL) + .apiKey("My API Key") + .adminApiKey("My Admin API Key") + .build() + val roleService = client.admin().organization().projects().roles() + + val role = + roleService.retrieve( + RoleRetrieveParams.builder().projectId("project_id").roleId("role_id").build() + ) + + role.validate() + } + @Test fun update() { val client = diff --git a/openai-java-core/src/test/kotlin/com/openai/services/blocking/admin/organization/projects/ServiceAccountServiceTest.kt b/openai-java-core/src/test/kotlin/com/openai/services/blocking/admin/organization/projects/ServiceAccountServiceTest.kt index 6e99b3c6c..2a29c4c53 100644 --- a/openai-java-core/src/test/kotlin/com/openai/services/blocking/admin/organization/projects/ServiceAccountServiceTest.kt +++ b/openai-java-core/src/test/kotlin/com/openai/services/blocking/admin/organization/projects/ServiceAccountServiceTest.kt @@ -7,6 +7,7 @@ import com.openai.client.okhttp.OpenAIOkHttpClient import com.openai.models.admin.organization.projects.serviceaccounts.ServiceAccountCreateParams import com.openai.models.admin.organization.projects.serviceaccounts.ServiceAccountDeleteParams import com.openai.models.admin.organization.projects.serviceaccounts.ServiceAccountRetrieveParams +import com.openai.models.admin.organization.projects.serviceaccounts.ServiceAccountUpdateParams import org.junit.jupiter.api.Test import org.junit.jupiter.api.extension.ExtendWith @@ -52,6 +53,29 @@ internal class ServiceAccountServiceTest { projectServiceAccount.validate() } + @Test + fun update() { + val client = + OpenAIOkHttpClient.builder() + .baseUrl(TestServerExtension.BASE_URL) + .apiKey("My API Key") + .adminApiKey("My Admin API Key") + .build() + val serviceAccountService = client.admin().organization().projects().serviceAccounts() + + val projectServiceAccount = + serviceAccountService.update( + ServiceAccountUpdateParams.builder() + .projectId("project_id") + .serviceAccountId("service_account_id") + .name("name") + .role(ServiceAccountUpdateParams.Role.MEMBER) + .build() + ) + + projectServiceAccount.validate() + } + @Test fun list() { val client = diff --git a/openai-java-core/src/test/kotlin/com/openai/services/blocking/admin/organization/projects/SpendAlertServiceTest.kt b/openai-java-core/src/test/kotlin/com/openai/services/blocking/admin/organization/projects/SpendAlertServiceTest.kt new file mode 100644 index 000000000..d2ab41b6c --- /dev/null +++ b/openai-java-core/src/test/kotlin/com/openai/services/blocking/admin/organization/projects/SpendAlertServiceTest.kt @@ -0,0 +1,107 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.services.blocking.admin.organization.projects + +import com.openai.TestServerExtension +import com.openai.client.okhttp.OpenAIOkHttpClient +import com.openai.models.admin.organization.projects.spendalerts.SpendAlertCreateParams +import com.openai.models.admin.organization.projects.spendalerts.SpendAlertDeleteParams +import com.openai.models.admin.organization.projects.spendalerts.SpendAlertUpdateParams +import org.junit.jupiter.api.Test +import org.junit.jupiter.api.extension.ExtendWith + +@ExtendWith(TestServerExtension::class) +internal class SpendAlertServiceTest { + + @Test + fun create() { + val client = + OpenAIOkHttpClient.builder() + .baseUrl(TestServerExtension.BASE_URL) + .apiKey("My API Key") + .adminApiKey("My Admin API Key") + .build() + val spendAlertService = client.admin().organization().projects().spendAlerts() + + val projectSpendAlert = + spendAlertService.create( + SpendAlertCreateParams.builder() + .projectId("project_id") + .currency(SpendAlertCreateParams.Currency.USD) + .interval(SpendAlertCreateParams.Interval.MONTH) + .notificationChannel( + SpendAlertCreateParams.NotificationChannel.builder() + .addRecipient("string") + .subjectPrefix("subject_prefix") + .build() + ) + .thresholdAmount(0L) + .build() + ) + + projectSpendAlert.validate() + } + + @Test + fun update() { + val client = + OpenAIOkHttpClient.builder() + .baseUrl(TestServerExtension.BASE_URL) + .apiKey("My API Key") + .adminApiKey("My Admin API Key") + .build() + val spendAlertService = client.admin().organization().projects().spendAlerts() + + val projectSpendAlert = + spendAlertService.update( + SpendAlertUpdateParams.builder() + .projectId("project_id") + .alertId("alert_id") + .currency(SpendAlertUpdateParams.Currency.USD) + .interval(SpendAlertUpdateParams.Interval.MONTH) + .notificationChannel( + SpendAlertUpdateParams.NotificationChannel.builder() + .addRecipient("string") + .subjectPrefix("subject_prefix") + .build() + ) + .thresholdAmount(0L) + .build() + ) + + projectSpendAlert.validate() + } + + @Test + fun list() { + val client = + OpenAIOkHttpClient.builder() + .baseUrl(TestServerExtension.BASE_URL) + .apiKey("My API Key") + .adminApiKey("My Admin API Key") + .build() + val spendAlertService = client.admin().organization().projects().spendAlerts() + + val page = spendAlertService.list("project_id") + + page.response().validate() + } + + @Test + fun delete() { + val client = + OpenAIOkHttpClient.builder() + .baseUrl(TestServerExtension.BASE_URL) + .apiKey("My API Key") + .adminApiKey("My Admin API Key") + .build() + val spendAlertService = client.admin().organization().projects().spendAlerts() + + val projectSpendAlertDeleted = + spendAlertService.delete( + SpendAlertDeleteParams.builder().projectId("project_id").alertId("alert_id").build() + ) + + projectSpendAlertDeleted.validate() + } +} diff --git a/openai-java-core/src/test/kotlin/com/openai/services/blocking/admin/organization/projects/groups/RoleServiceTest.kt b/openai-java-core/src/test/kotlin/com/openai/services/blocking/admin/organization/projects/groups/RoleServiceTest.kt index ddd302e67..ca4e945be 100644 --- a/openai-java-core/src/test/kotlin/com/openai/services/blocking/admin/organization/projects/groups/RoleServiceTest.kt +++ b/openai-java-core/src/test/kotlin/com/openai/services/blocking/admin/organization/projects/groups/RoleServiceTest.kt @@ -7,6 +7,7 @@ import com.openai.client.okhttp.OpenAIOkHttpClient import com.openai.models.admin.organization.projects.groups.roles.RoleCreateParams import com.openai.models.admin.organization.projects.groups.roles.RoleDeleteParams import com.openai.models.admin.organization.projects.groups.roles.RoleListParams +import com.openai.models.admin.organization.projects.groups.roles.RoleRetrieveParams import org.junit.jupiter.api.Test import org.junit.jupiter.api.extension.ExtendWith @@ -35,6 +36,28 @@ internal class RoleServiceTest { role.validate() } + @Test + fun retrieve() { + val client = + OpenAIOkHttpClient.builder() + .baseUrl(TestServerExtension.BASE_URL) + .apiKey("My API Key") + .adminApiKey("My Admin API Key") + .build() + val roleService = client.admin().organization().projects().groups().roles() + + val role = + roleService.retrieve( + RoleRetrieveParams.builder() + .projectId("project_id") + .groupId("group_id") + .roleId("role_id") + .build() + ) + + role.validate() + } + @Test fun list() { val client = diff --git a/openai-java-core/src/test/kotlin/com/openai/services/blocking/admin/organization/projects/users/RoleServiceTest.kt b/openai-java-core/src/test/kotlin/com/openai/services/blocking/admin/organization/projects/users/RoleServiceTest.kt index 2a9e937aa..8569e5428 100644 --- a/openai-java-core/src/test/kotlin/com/openai/services/blocking/admin/organization/projects/users/RoleServiceTest.kt +++ b/openai-java-core/src/test/kotlin/com/openai/services/blocking/admin/organization/projects/users/RoleServiceTest.kt @@ -7,6 +7,7 @@ import com.openai.client.okhttp.OpenAIOkHttpClient import com.openai.models.admin.organization.projects.users.roles.RoleCreateParams import com.openai.models.admin.organization.projects.users.roles.RoleDeleteParams import com.openai.models.admin.organization.projects.users.roles.RoleListParams +import com.openai.models.admin.organization.projects.users.roles.RoleRetrieveParams import org.junit.jupiter.api.Test import org.junit.jupiter.api.extension.ExtendWith @@ -35,6 +36,28 @@ internal class RoleServiceTest { role.validate() } + @Test + fun retrieve() { + val client = + OpenAIOkHttpClient.builder() + .baseUrl(TestServerExtension.BASE_URL) + .apiKey("My API Key") + .adminApiKey("My Admin API Key") + .build() + val roleService = client.admin().organization().projects().users().roles() + + val role = + roleService.retrieve( + RoleRetrieveParams.builder() + .projectId("project_id") + .userId("user_id") + .roleId("role_id") + .build() + ) + + role.validate() + } + @Test fun list() { val client = diff --git a/openai-java-core/src/test/kotlin/com/openai/services/blocking/admin/organization/users/RoleServiceTest.kt b/openai-java-core/src/test/kotlin/com/openai/services/blocking/admin/organization/users/RoleServiceTest.kt index 15a9565ca..084c2418f 100644 --- a/openai-java-core/src/test/kotlin/com/openai/services/blocking/admin/organization/users/RoleServiceTest.kt +++ b/openai-java-core/src/test/kotlin/com/openai/services/blocking/admin/organization/users/RoleServiceTest.kt @@ -6,6 +6,7 @@ import com.openai.TestServerExtension import com.openai.client.okhttp.OpenAIOkHttpClient import com.openai.models.admin.organization.users.roles.RoleCreateParams import com.openai.models.admin.organization.users.roles.RoleDeleteParams +import com.openai.models.admin.organization.users.roles.RoleRetrieveParams import org.junit.jupiter.api.Test import org.junit.jupiter.api.extension.ExtendWith @@ -30,6 +31,24 @@ internal class RoleServiceTest { role.validate() } + @Test + fun retrieve() { + val client = + OpenAIOkHttpClient.builder() + .baseUrl(TestServerExtension.BASE_URL) + .apiKey("My API Key") + .adminApiKey("My Admin API Key") + .build() + val roleService = client.admin().organization().users().roles() + + val role = + roleService.retrieve( + RoleRetrieveParams.builder().userId("user_id").roleId("role_id").build() + ) + + role.validate() + } + @Test fun list() { val client = From 781bc1e308d501d7210b5235ebfca022988e1f05 Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Thu, 21 May 2026 18:03:40 +0000 Subject: [PATCH 8/8] release: 4.37.0 --- .release-please-manifest.json | 2 +- CHANGELOG.md | 15 +++++++++++++++ README.md | 14 +++++++------- build.gradle.kts | 2 +- 4 files changed, 24 insertions(+), 9 deletions(-) diff --git a/.release-please-manifest.json b/.release-please-manifest.json index ea3d667ed..0a7c04585 100644 --- a/.release-please-manifest.json +++ b/.release-please-manifest.json @@ -1,3 +1,3 @@ { - ".": "4.36.0" + ".": "4.37.0" } \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md index 18b285fb8..0a5762094 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,20 @@ # Changelog +## 4.37.0 (2026-05-21) + +Full Changelog: [v4.36.0...v4.37.0](https://github.com/openai/openai-java/compare/v4.36.0...v4.37.0) + +### Features + +* **api:** manual updates ([751f476](https://github.com/openai/openai-java/commit/751f476ae83e88dcf122aa2d34bdc16983e800b4)) +* **api:** manual updates ([1a21364](https://github.com/openai/openai-java/commit/1a21364f95933116344b0ab703796fb559eb8735)) +* **api:** update OpenAPI spec or Stainless config ([33debac](https://github.com/openai/openai-java/commit/33debacb88320787265e083cbdb91ec6e3e812f5)) + + +### Chores + +* **api:** docs updates ([704032e](https://github.com/openai/openai-java/commit/704032ebbb3244054e5e8425c82dfe45562378e9)) + ## 4.36.0 (2026-05-13) Full Changelog: [v4.35.0...v4.36.0](https://github.com/openai/openai-java/compare/v4.35.0...v4.36.0) diff --git a/README.md b/README.md index 8ed9b76a3..d2bd6c31b 100644 --- a/README.md +++ b/README.md @@ -2,8 +2,8 @@ -[![Maven Central](https://img.shields.io/maven-central/v/com.openai/openai-java)](https://central.sonatype.com/artifact/com.openai/openai-java/4.36.0) -[![javadoc](https://javadoc.io/badge2/com.openai/openai-java/4.36.0/javadoc.svg)](https://javadoc.io/doc/com.openai/openai-java/4.36.0) +[![Maven Central](https://img.shields.io/maven-central/v/com.openai/openai-java)](https://central.sonatype.com/artifact/com.openai/openai-java/4.37.0) +[![javadoc](https://javadoc.io/badge2/com.openai/openai-java/4.37.0/javadoc.svg)](https://javadoc.io/doc/com.openai/openai-java/4.37.0) @@ -11,7 +11,7 @@ The OpenAI Java SDK provides convenient access to the [OpenAI REST API](https:// -The REST API documentation can be found on [platform.openai.com](https://platform.openai.com/docs). Javadocs are available on [javadoc.io](https://javadoc.io/doc/com.openai/openai-java/4.36.0). +The REST API documentation can be found on [platform.openai.com](https://platform.openai.com/docs). Javadocs are available on [javadoc.io](https://javadoc.io/doc/com.openai/openai-java/4.37.0). @@ -24,7 +24,7 @@ The REST API documentation can be found on [platform.openai.com](https://platfor ### Gradle ```kotlin -implementation("com.openai:openai-java:4.36.0") +implementation("com.openai:openai-java:4.37.0") ``` ### Maven @@ -33,7 +33,7 @@ implementation("com.openai:openai-java:4.36.0") com.openai openai-java - 4.36.0 + 4.37.0 ``` @@ -1433,7 +1433,7 @@ If you're using Spring Boot, then you can use the SDK's [Spring Boot starter](ht #### Gradle ```kotlin -implementation("com.openai:openai-java-spring-boot-starter:4.36.0") +implementation("com.openai:openai-java-spring-boot-starter:4.37.0") ``` #### Maven @@ -1442,7 +1442,7 @@ implementation("com.openai:openai-java-spring-boot-starter:4.36.0") com.openai openai-java-spring-boot-starter - 4.36.0 + 4.37.0 ``` diff --git a/build.gradle.kts b/build.gradle.kts index 13b4e5b0b..0242a2387 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -8,7 +8,7 @@ repositories { allprojects { group = "com.openai" - version = "4.36.0" // x-release-please-version + version = "4.37.0" // x-release-please-version } subprojects {