From 88159223fd10a427d7bfabe640439c1cebea4cc3 Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Fri, 9 Jan 2026 13:26:07 +0000 Subject: [PATCH 1/2] feat(closes OPEN-8532): expose 'tests/{id}/results' endpoint --- .stats.yml | 6 +- .../testresults/TestResultListResponse.kt | 2778 +++- .../testresults/TestResultListResponse.kt | 2778 +++- .../api/models/tests/TestListResultsParams.kt | 388 + .../models/tests/TestListResultsResponse.kt | 13563 ++++++++++++++++ .../api/services/async/TestServiceAsync.kt | 81 + .../services/async/TestServiceAsyncImpl.kt | 42 + .../api/services/blocking/TestService.kt | 79 + .../api/services/blocking/TestServiceImpl.kt | 39 + .../testresults/TestResultListResponseTest.kt | 101 + .../testresults/TestResultListResponseTest.kt | 101 + .../models/tests/TestListResultsParamsTest.kt | 77 + .../tests/TestListResultsResponseTest.kt | 698 + .../services/async/TestServiceAsyncTest.kt | 29 + .../api/services/blocking/TestServiceTest.kt | 28 + 15 files changed, 20781 insertions(+), 7 deletions(-) create mode 100644 openlayer-java-core/src/main/kotlin/com/openlayer/api/models/tests/TestListResultsParams.kt create mode 100644 openlayer-java-core/src/main/kotlin/com/openlayer/api/models/tests/TestListResultsResponse.kt create mode 100644 openlayer-java-core/src/test/kotlin/com/openlayer/api/models/tests/TestListResultsParamsTest.kt create mode 100644 openlayer-java-core/src/test/kotlin/com/openlayer/api/models/tests/TestListResultsResponseTest.kt diff --git a/.stats.yml b/.stats.yml index d4e53809..f925a83b 100644 --- a/.stats.yml +++ b/.stats.yml @@ -1,3 +1,3 @@ -configured_endpoints: 24 -openapi_spec_hash: c97a5263afcc72ca5a47bc5a87683a78 -config_hash: f0743196c68fb84cbd06a95f134702b3 +configured_endpoints: 25 +openapi_spec_hash: 4eff18b3478c98a9b257ac27fdeb6b49 +config_hash: b415187e3925c414fb2597cdd0a11859 diff --git a/openlayer-java-core/src/main/kotlin/com/openlayer/api/models/commits/testresults/TestResultListResponse.kt b/openlayer-java-core/src/main/kotlin/com/openlayer/api/models/commits/testresults/TestResultListResponse.kt index ee68b7e0..a3c4dbd5 100644 --- a/openlayer-java-core/src/main/kotlin/com/openlayer/api/models/commits/testresults/TestResultListResponse.kt +++ b/openlayer-java-core/src/main/kotlin/com/openlayer/api/models/commits/testresults/TestResultListResponse.kt @@ -195,8 +195,11 @@ private constructor( private val projectVersionId: JsonField, private val status: JsonField, private val statusMessage: JsonField, + private val expectedValues: JsonField>, private val goal: JsonField, private val goalId: JsonField, + private val rows: JsonField, + private val rowsBody: JsonField, private val additionalProperties: MutableMap, ) { @@ -225,8 +228,15 @@ private constructor( @JsonProperty("statusMessage") @ExcludeMissing statusMessage: JsonField = JsonMissing.of(), + @JsonProperty("expectedValues") + @ExcludeMissing + expectedValues: JsonField> = JsonMissing.of(), @JsonProperty("goal") @ExcludeMissing goal: JsonField = JsonMissing.of(), @JsonProperty("goalId") @ExcludeMissing goalId: JsonField = JsonMissing.of(), + @JsonProperty("rows") @ExcludeMissing rows: JsonField = JsonMissing.of(), + @JsonProperty("rowsBody") + @ExcludeMissing + rowsBody: JsonField = JsonMissing.of(), ) : this( id, dateCreated, @@ -237,8 +247,11 @@ private constructor( projectVersionId, status, statusMessage, + expectedValues, goal, goalId, + rows, + rowsBody, mutableMapOf(), ) @@ -316,6 +329,13 @@ private constructor( */ fun statusMessage(): Optional = statusMessage.getOptional("statusMessage") + /** + * @throws OpenlayerInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun expectedValues(): Optional> = + expectedValues.getOptional("expectedValues") + /** * @throws OpenlayerInvalidDataException if the JSON field has an unexpected type (e.g. if * the server responded with an unexpected value). @@ -330,6 +350,22 @@ private constructor( */ fun goalId(): Optional = goalId.getOptional("goalId") + /** + * The URL to the rows of the test result. + * + * @throws OpenlayerInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun rows(): Optional = rows.getOptional("rows") + + /** + * The body of the rows request. + * + * @throws OpenlayerInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun rowsBody(): Optional = rowsBody.getOptional("rowsBody") + /** * Returns the raw JSON value of [id]. * @@ -412,6 +448,16 @@ private constructor( @ExcludeMissing fun _statusMessage(): JsonField = statusMessage + /** + * Returns the raw JSON value of [expectedValues]. + * + * Unlike [expectedValues], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("expectedValues") + @ExcludeMissing + fun _expectedValues(): JsonField> = expectedValues + /** * Returns the raw JSON value of [goal]. * @@ -426,6 +472,20 @@ private constructor( */ @JsonProperty("goalId") @ExcludeMissing fun _goalId(): JsonField = goalId + /** + * Returns the raw JSON value of [rows]. + * + * Unlike [rows], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("rows") @ExcludeMissing fun _rows(): JsonField = rows + + /** + * Returns the raw JSON value of [rowsBody]. + * + * Unlike [rowsBody], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("rowsBody") @ExcludeMissing fun _rowsBody(): JsonField = rowsBody + @JsonAnySetter private fun putAdditionalProperty(key: String, value: JsonValue) { additionalProperties.put(key, value) @@ -471,8 +531,11 @@ private constructor( private var projectVersionId: JsonField? = null private var status: JsonField? = null private var statusMessage: JsonField? = null + private var expectedValues: JsonField>? = null private var goal: JsonField = JsonMissing.of() private var goalId: JsonField = JsonMissing.of() + private var rows: JsonField = JsonMissing.of() + private var rowsBody: JsonField = JsonMissing.of() private var additionalProperties: MutableMap = mutableMapOf() @JvmSynthetic @@ -486,8 +549,11 @@ private constructor( projectVersionId = item.projectVersionId status = item.status statusMessage = item.statusMessage + expectedValues = item.expectedValues.map { it.toMutableList() } goal = item.goal goalId = item.goalId + rows = item.rows + rowsBody = item.rowsBody additionalProperties = item.additionalProperties.toMutableMap() } @@ -643,6 +709,32 @@ private constructor( this.statusMessage = statusMessage } + fun expectedValues(expectedValues: List) = + expectedValues(JsonField.of(expectedValues)) + + /** + * Sets [Builder.expectedValues] to an arbitrary JSON value. + * + * You should usually call [Builder.expectedValues] with a well-typed + * `List` value instead. This method is primarily for setting the field + * to an undocumented or not yet supported value. + */ + fun expectedValues(expectedValues: JsonField>) = apply { + this.expectedValues = expectedValues.map { it.toMutableList() } + } + + /** + * Adds a single [ExpectedValue] to [expectedValues]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addExpectedValue(expectedValue: ExpectedValue) = apply { + expectedValues = + (expectedValues ?: JsonField.of(mutableListOf())).also { + checkKnown("expectedValues", it).add(expectedValue) + } + } + fun goal(goal: Goal) = goal(JsonField.of(goal)) /** @@ -669,6 +761,33 @@ private constructor( */ fun goalId(goalId: JsonField) = apply { this.goalId = goalId } + /** The URL to the rows of the test result. */ + fun rows(rows: String) = rows(JsonField.of(rows)) + + /** + * Sets [Builder.rows] to an arbitrary JSON value. + * + * You should usually call [Builder.rows] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun rows(rows: JsonField) = apply { this.rows = rows } + + /** The body of the rows request. */ + fun rowsBody(rowsBody: RowsBody?) = rowsBody(JsonField.ofNullable(rowsBody)) + + /** Alias for calling [Builder.rowsBody] with `rowsBody.orElse(null)`. */ + fun rowsBody(rowsBody: Optional) = rowsBody(rowsBody.getOrNull()) + + /** + * Sets [Builder.rowsBody] to an arbitrary JSON value. + * + * You should usually call [Builder.rowsBody] with a well-typed [RowsBody] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun rowsBody(rowsBody: JsonField) = apply { this.rowsBody = rowsBody } + fun additionalProperties(additionalProperties: Map) = apply { this.additionalProperties.clear() putAllAdditionalProperties(additionalProperties) @@ -719,8 +838,11 @@ private constructor( checkRequired("projectVersionId", projectVersionId), checkRequired("status", status), checkRequired("statusMessage", statusMessage), + (expectedValues ?: JsonMissing.of()).map { it.toImmutable() }, goal, goalId, + rows, + rowsBody, additionalProperties.toMutableMap(), ) } @@ -741,8 +863,11 @@ private constructor( projectVersionId() status().validate() statusMessage() + expectedValues().ifPresent { it.forEach { it.validate() } } goal().ifPresent { it.validate() } goalId() + rows() + rowsBody().ifPresent { it.validate() } validated = true } @@ -771,8 +896,11 @@ private constructor( (if (projectVersionId.asKnown().isPresent) 1 else 0) + (status.asKnown().getOrNull()?.validity() ?: 0) + (if (statusMessage.asKnown().isPresent) 1 else 0) + + (expectedValues.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + (goal.asKnown().getOrNull()?.validity() ?: 0) + - (if (goalId.asKnown().isPresent) 1 else 0) + (if (goalId.asKnown().isPresent) 1 else 0) + + (if (rows.asKnown().isPresent) 1 else 0) + + (rowsBody.asKnown().getOrNull()?.validity() ?: 0) /** The status of the test. */ class Status @JsonCreator private constructor(private val value: JsonField) : Enum { @@ -922,6 +1050,277 @@ private constructor( override fun toString() = value.toString() } + class ExpectedValue + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val lowerThreshold: JsonField, + private val measurement: JsonField, + private val upperThreshold: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("lowerThreshold") + @ExcludeMissing + lowerThreshold: JsonField = JsonMissing.of(), + @JsonProperty("measurement") + @ExcludeMissing + measurement: JsonField = JsonMissing.of(), + @JsonProperty("upperThreshold") + @ExcludeMissing + upperThreshold: JsonField = JsonMissing.of(), + ) : this(lowerThreshold, measurement, upperThreshold, mutableMapOf()) + + /** + * the lower threshold for the expected value + * + * @throws OpenlayerInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun lowerThreshold(): Optional = lowerThreshold.getOptional("lowerThreshold") + + /** + * One of the `measurement` values in the test's thresholds + * + * @throws OpenlayerInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun measurement(): Optional = measurement.getOptional("measurement") + + /** + * The upper threshold for the expected value + * + * @throws OpenlayerInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun upperThreshold(): Optional = upperThreshold.getOptional("upperThreshold") + + /** + * Returns the raw JSON value of [lowerThreshold]. + * + * Unlike [lowerThreshold], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("lowerThreshold") + @ExcludeMissing + fun _lowerThreshold(): JsonField = lowerThreshold + + /** + * Returns the raw JSON value of [measurement]. + * + * Unlike [measurement], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("measurement") + @ExcludeMissing + fun _measurement(): JsonField = measurement + + /** + * Returns the raw JSON value of [upperThreshold]. + * + * Unlike [upperThreshold], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("upperThreshold") + @ExcludeMissing + fun _upperThreshold(): JsonField = upperThreshold + + @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 [ExpectedValue]. */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [ExpectedValue]. */ + class Builder internal constructor() { + + private var lowerThreshold: JsonField = JsonMissing.of() + private var measurement: JsonField = JsonMissing.of() + private var upperThreshold: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(expectedValue: ExpectedValue) = apply { + lowerThreshold = expectedValue.lowerThreshold + measurement = expectedValue.measurement + upperThreshold = expectedValue.upperThreshold + additionalProperties = expectedValue.additionalProperties.toMutableMap() + } + + /** the lower threshold for the expected value */ + fun lowerThreshold(lowerThreshold: Float?) = + lowerThreshold(JsonField.ofNullable(lowerThreshold)) + + /** + * Alias for [Builder.lowerThreshold]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun lowerThreshold(lowerThreshold: Float) = lowerThreshold(lowerThreshold as Float?) + + /** + * Alias for calling [Builder.lowerThreshold] with `lowerThreshold.orElse(null)`. + */ + fun lowerThreshold(lowerThreshold: Optional) = + lowerThreshold(lowerThreshold.getOrNull()) + + /** + * Sets [Builder.lowerThreshold] to an arbitrary JSON value. + * + * You should usually call [Builder.lowerThreshold] with a well-typed [Float] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun lowerThreshold(lowerThreshold: JsonField) = apply { + this.lowerThreshold = lowerThreshold + } + + /** One of the `measurement` values in the test's thresholds */ + fun measurement(measurement: String) = measurement(JsonField.of(measurement)) + + /** + * Sets [Builder.measurement] to an arbitrary JSON value. + * + * You should usually call [Builder.measurement] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun measurement(measurement: JsonField) = apply { + this.measurement = measurement + } + + /** The upper threshold for the expected value */ + fun upperThreshold(upperThreshold: Float?) = + upperThreshold(JsonField.ofNullable(upperThreshold)) + + /** + * Alias for [Builder.upperThreshold]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun upperThreshold(upperThreshold: Float) = upperThreshold(upperThreshold as Float?) + + /** + * Alias for calling [Builder.upperThreshold] with `upperThreshold.orElse(null)`. + */ + fun upperThreshold(upperThreshold: Optional) = + upperThreshold(upperThreshold.getOrNull()) + + /** + * Sets [Builder.upperThreshold] to an arbitrary JSON value. + * + * You should usually call [Builder.upperThreshold] with a well-typed [Float] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun upperThreshold(upperThreshold: JsonField) = apply { + this.upperThreshold = upperThreshold + } + + 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 [ExpectedValue]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): ExpectedValue = + ExpectedValue( + lowerThreshold, + measurement, + upperThreshold, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): ExpectedValue = apply { + if (validated) { + return@apply + } + + lowerThreshold() + measurement() + upperThreshold() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OpenlayerInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (if (lowerThreshold.asKnown().isPresent) 1 else 0) + + (if (measurement.asKnown().isPresent) 1 else 0) + + (if (upperThreshold.asKnown().isPresent) 1 else 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is ExpectedValue && + lowerThreshold == other.lowerThreshold && + measurement == other.measurement && + upperThreshold == other.upperThreshold && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(lowerThreshold, measurement, upperThreshold, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "ExpectedValue{lowerThreshold=$lowerThreshold, measurement=$measurement, upperThreshold=$upperThreshold, additionalProperties=$additionalProperties}" + } + class Goal @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( @@ -4022,6 +4421,2375 @@ private constructor( "Goal{id=$id, commentCount=$commentCount, creatorId=$creatorId, dateArchived=$dateArchived, dateCreated=$dateCreated, dateUpdated=$dateUpdated, description=$description, name=$name, number=$number, originProjectVersionId=$originProjectVersionId, subtype=$subtype, suggested=$suggested, thresholds=$thresholds, type=$type, archived=$archived, delayWindow=$delayWindow, evaluationWindow=$evaluationWindow, usesMlModel=$usesMlModel, usesProductionData=$usesProductionData, usesReferenceDataset=$usesReferenceDataset, usesTrainingDataset=$usesTrainingDataset, usesValidationDataset=$usesValidationDataset, additionalProperties=$additionalProperties}" } + /** The body of the rows request. */ + class RowsBody + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val columnFilters: JsonField>, + private val excludeRowIdList: JsonField>, + private val notSearchQueryAnd: JsonField>, + private val notSearchQueryOr: JsonField>, + private val rowIdList: JsonField>, + private val searchQueryAnd: JsonField>, + private val searchQueryOr: JsonField>, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("columnFilters") + @ExcludeMissing + columnFilters: JsonField> = JsonMissing.of(), + @JsonProperty("excludeRowIdList") + @ExcludeMissing + excludeRowIdList: JsonField> = JsonMissing.of(), + @JsonProperty("notSearchQueryAnd") + @ExcludeMissing + notSearchQueryAnd: JsonField> = JsonMissing.of(), + @JsonProperty("notSearchQueryOr") + @ExcludeMissing + notSearchQueryOr: JsonField> = JsonMissing.of(), + @JsonProperty("rowIdList") + @ExcludeMissing + rowIdList: JsonField> = JsonMissing.of(), + @JsonProperty("searchQueryAnd") + @ExcludeMissing + searchQueryAnd: JsonField> = JsonMissing.of(), + @JsonProperty("searchQueryOr") + @ExcludeMissing + searchQueryOr: JsonField> = JsonMissing.of(), + ) : this( + columnFilters, + excludeRowIdList, + notSearchQueryAnd, + notSearchQueryOr, + rowIdList, + searchQueryAnd, + searchQueryOr, + mutableMapOf(), + ) + + /** + * @throws OpenlayerInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun columnFilters(): Optional> = + columnFilters.getOptional("columnFilters") + + /** + * @throws OpenlayerInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun excludeRowIdList(): Optional> = + excludeRowIdList.getOptional("excludeRowIdList") + + /** + * @throws OpenlayerInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun notSearchQueryAnd(): Optional> = + notSearchQueryAnd.getOptional("notSearchQueryAnd") + + /** + * @throws OpenlayerInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun notSearchQueryOr(): Optional> = + notSearchQueryOr.getOptional("notSearchQueryOr") + + /** + * @throws OpenlayerInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun rowIdList(): Optional> = rowIdList.getOptional("rowIdList") + + /** + * @throws OpenlayerInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun searchQueryAnd(): Optional> = + searchQueryAnd.getOptional("searchQueryAnd") + + /** + * @throws OpenlayerInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun searchQueryOr(): Optional> = searchQueryOr.getOptional("searchQueryOr") + + /** + * Returns the raw JSON value of [columnFilters]. + * + * Unlike [columnFilters], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("columnFilters") + @ExcludeMissing + fun _columnFilters(): JsonField> = columnFilters + + /** + * Returns the raw JSON value of [excludeRowIdList]. + * + * Unlike [excludeRowIdList], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("excludeRowIdList") + @ExcludeMissing + fun _excludeRowIdList(): JsonField> = excludeRowIdList + + /** + * Returns the raw JSON value of [notSearchQueryAnd]. + * + * Unlike [notSearchQueryAnd], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("notSearchQueryAnd") + @ExcludeMissing + fun _notSearchQueryAnd(): JsonField> = notSearchQueryAnd + + /** + * Returns the raw JSON value of [notSearchQueryOr]. + * + * Unlike [notSearchQueryOr], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("notSearchQueryOr") + @ExcludeMissing + fun _notSearchQueryOr(): JsonField> = notSearchQueryOr + + /** + * Returns the raw JSON value of [rowIdList]. + * + * Unlike [rowIdList], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("rowIdList") + @ExcludeMissing + fun _rowIdList(): JsonField> = rowIdList + + /** + * Returns the raw JSON value of [searchQueryAnd]. + * + * Unlike [searchQueryAnd], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("searchQueryAnd") + @ExcludeMissing + fun _searchQueryAnd(): JsonField> = searchQueryAnd + + /** + * Returns the raw JSON value of [searchQueryOr]. + * + * Unlike [searchQueryOr], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("searchQueryOr") + @ExcludeMissing + fun _searchQueryOr(): JsonField> = searchQueryOr + + @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 [RowsBody]. */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [RowsBody]. */ + class Builder internal constructor() { + + private var columnFilters: JsonField>? = null + private var excludeRowIdList: JsonField>? = null + private var notSearchQueryAnd: JsonField>? = null + private var notSearchQueryOr: JsonField>? = null + private var rowIdList: JsonField>? = null + private var searchQueryAnd: JsonField>? = null + private var searchQueryOr: JsonField>? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(rowsBody: RowsBody) = apply { + columnFilters = rowsBody.columnFilters.map { it.toMutableList() } + excludeRowIdList = rowsBody.excludeRowIdList.map { it.toMutableList() } + notSearchQueryAnd = rowsBody.notSearchQueryAnd.map { it.toMutableList() } + notSearchQueryOr = rowsBody.notSearchQueryOr.map { it.toMutableList() } + rowIdList = rowsBody.rowIdList.map { it.toMutableList() } + searchQueryAnd = rowsBody.searchQueryAnd.map { it.toMutableList() } + searchQueryOr = rowsBody.searchQueryOr.map { it.toMutableList() } + additionalProperties = rowsBody.additionalProperties.toMutableMap() + } + + fun columnFilters(columnFilters: List?) = + columnFilters(JsonField.ofNullable(columnFilters)) + + /** Alias for calling [Builder.columnFilters] with `columnFilters.orElse(null)`. */ + fun columnFilters(columnFilters: Optional>) = + columnFilters(columnFilters.getOrNull()) + + /** + * Sets [Builder.columnFilters] to an arbitrary JSON value. + * + * You should usually call [Builder.columnFilters] with a well-typed + * `List` value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. + */ + fun columnFilters(columnFilters: JsonField>) = apply { + this.columnFilters = columnFilters.map { it.toMutableList() } + } + + /** + * Adds a single [ColumnFilter] to [columnFilters]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addColumnFilter(columnFilter: ColumnFilter) = apply { + columnFilters = + (columnFilters ?: JsonField.of(mutableListOf())).also { + checkKnown("columnFilters", it).add(columnFilter) + } + } + + /** Alias for calling [addColumnFilter] with `ColumnFilter.ofSet(set)`. */ + fun addColumnFilter(set: ColumnFilter.SetColumnFilter) = + addColumnFilter(ColumnFilter.ofSet(set)) + + /** Alias for calling [addColumnFilter] with `ColumnFilter.ofNumeric(numeric)`. */ + fun addColumnFilter(numeric: ColumnFilter.NumericColumnFilter) = + addColumnFilter(ColumnFilter.ofNumeric(numeric)) + + /** Alias for calling [addColumnFilter] with `ColumnFilter.ofString(string)`. */ + fun addColumnFilter(string: ColumnFilter.StringColumnFilter) = + addColumnFilter(ColumnFilter.ofString(string)) + + fun excludeRowIdList(excludeRowIdList: List?) = + excludeRowIdList(JsonField.ofNullable(excludeRowIdList)) + + /** + * Alias for calling [Builder.excludeRowIdList] with + * `excludeRowIdList.orElse(null)`. + */ + fun excludeRowIdList(excludeRowIdList: Optional>) = + excludeRowIdList(excludeRowIdList.getOrNull()) + + /** + * Sets [Builder.excludeRowIdList] to an arbitrary JSON value. + * + * You should usually call [Builder.excludeRowIdList] with a well-typed `List` + * value instead. This method is primarily for setting the field to an undocumented + * or not yet supported value. + */ + fun excludeRowIdList(excludeRowIdList: JsonField>) = apply { + this.excludeRowIdList = excludeRowIdList.map { it.toMutableList() } + } + + /** + * Adds a single [Long] to [Builder.excludeRowIdList]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addExcludeRowIdList(excludeRowIdList: Long) = apply { + this.excludeRowIdList = + (this.excludeRowIdList ?: JsonField.of(mutableListOf())).also { + checkKnown("excludeRowIdList", it).add(excludeRowIdList) + } + } + + fun notSearchQueryAnd(notSearchQueryAnd: List?) = + notSearchQueryAnd(JsonField.ofNullable(notSearchQueryAnd)) + + /** + * Alias for calling [Builder.notSearchQueryAnd] with + * `notSearchQueryAnd.orElse(null)`. + */ + fun notSearchQueryAnd(notSearchQueryAnd: Optional>) = + notSearchQueryAnd(notSearchQueryAnd.getOrNull()) + + /** + * Sets [Builder.notSearchQueryAnd] to an arbitrary JSON value. + * + * You should usually call [Builder.notSearchQueryAnd] with a well-typed + * `List` value instead. This method is primarily for setting the field to + * an undocumented or not yet supported value. + */ + fun notSearchQueryAnd(notSearchQueryAnd: JsonField>) = apply { + this.notSearchQueryAnd = notSearchQueryAnd.map { it.toMutableList() } + } + + /** + * Adds a single [String] to [Builder.notSearchQueryAnd]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addNotSearchQueryAnd(notSearchQueryAnd: String) = apply { + this.notSearchQueryAnd = + (this.notSearchQueryAnd ?: JsonField.of(mutableListOf())).also { + checkKnown("notSearchQueryAnd", it).add(notSearchQueryAnd) + } + } + + fun notSearchQueryOr(notSearchQueryOr: List?) = + notSearchQueryOr(JsonField.ofNullable(notSearchQueryOr)) + + /** + * Alias for calling [Builder.notSearchQueryOr] with + * `notSearchQueryOr.orElse(null)`. + */ + fun notSearchQueryOr(notSearchQueryOr: Optional>) = + notSearchQueryOr(notSearchQueryOr.getOrNull()) + + /** + * Sets [Builder.notSearchQueryOr] to an arbitrary JSON value. + * + * You should usually call [Builder.notSearchQueryOr] with a well-typed + * `List` value instead. This method is primarily for setting the field to + * an undocumented or not yet supported value. + */ + fun notSearchQueryOr(notSearchQueryOr: JsonField>) = apply { + this.notSearchQueryOr = notSearchQueryOr.map { it.toMutableList() } + } + + /** + * Adds a single [String] to [Builder.notSearchQueryOr]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addNotSearchQueryOr(notSearchQueryOr: String) = apply { + this.notSearchQueryOr = + (this.notSearchQueryOr ?: JsonField.of(mutableListOf())).also { + checkKnown("notSearchQueryOr", it).add(notSearchQueryOr) + } + } + + fun rowIdList(rowIdList: List?) = rowIdList(JsonField.ofNullable(rowIdList)) + + /** Alias for calling [Builder.rowIdList] with `rowIdList.orElse(null)`. */ + fun rowIdList(rowIdList: Optional>) = rowIdList(rowIdList.getOrNull()) + + /** + * Sets [Builder.rowIdList] to an arbitrary JSON value. + * + * You should usually call [Builder.rowIdList] with a well-typed `List` value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun rowIdList(rowIdList: JsonField>) = apply { + this.rowIdList = rowIdList.map { it.toMutableList() } + } + + /** + * Adds a single [Long] to [Builder.rowIdList]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addRowIdList(rowIdList: Long) = apply { + this.rowIdList = + (this.rowIdList ?: JsonField.of(mutableListOf())).also { + checkKnown("rowIdList", it).add(rowIdList) + } + } + + fun searchQueryAnd(searchQueryAnd: List?) = + searchQueryAnd(JsonField.ofNullable(searchQueryAnd)) + + /** + * Alias for calling [Builder.searchQueryAnd] with `searchQueryAnd.orElse(null)`. + */ + fun searchQueryAnd(searchQueryAnd: Optional>) = + searchQueryAnd(searchQueryAnd.getOrNull()) + + /** + * Sets [Builder.searchQueryAnd] to an arbitrary JSON value. + * + * You should usually call [Builder.searchQueryAnd] with a well-typed `List` + * value instead. This method is primarily for setting the field to an undocumented + * or not yet supported value. + */ + fun searchQueryAnd(searchQueryAnd: JsonField>) = apply { + this.searchQueryAnd = searchQueryAnd.map { it.toMutableList() } + } + + /** + * Adds a single [String] to [Builder.searchQueryAnd]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addSearchQueryAnd(searchQueryAnd: String) = apply { + this.searchQueryAnd = + (this.searchQueryAnd ?: JsonField.of(mutableListOf())).also { + checkKnown("searchQueryAnd", it).add(searchQueryAnd) + } + } + + fun searchQueryOr(searchQueryOr: List?) = + searchQueryOr(JsonField.ofNullable(searchQueryOr)) + + /** Alias for calling [Builder.searchQueryOr] with `searchQueryOr.orElse(null)`. */ + fun searchQueryOr(searchQueryOr: Optional>) = + searchQueryOr(searchQueryOr.getOrNull()) + + /** + * Sets [Builder.searchQueryOr] to an arbitrary JSON value. + * + * You should usually call [Builder.searchQueryOr] with a well-typed `List` + * value instead. This method is primarily for setting the field to an undocumented + * or not yet supported value. + */ + fun searchQueryOr(searchQueryOr: JsonField>) = apply { + this.searchQueryOr = searchQueryOr.map { it.toMutableList() } + } + + /** + * Adds a single [String] to [Builder.searchQueryOr]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addSearchQueryOr(searchQueryOr: String) = apply { + this.searchQueryOr = + (this.searchQueryOr ?: JsonField.of(mutableListOf())).also { + checkKnown("searchQueryOr", it).add(searchQueryOr) + } + } + + 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 [RowsBody]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): RowsBody = + RowsBody( + (columnFilters ?: JsonMissing.of()).map { it.toImmutable() }, + (excludeRowIdList ?: JsonMissing.of()).map { it.toImmutable() }, + (notSearchQueryAnd ?: JsonMissing.of()).map { it.toImmutable() }, + (notSearchQueryOr ?: JsonMissing.of()).map { it.toImmutable() }, + (rowIdList ?: JsonMissing.of()).map { it.toImmutable() }, + (searchQueryAnd ?: JsonMissing.of()).map { it.toImmutable() }, + (searchQueryOr ?: JsonMissing.of()).map { it.toImmutable() }, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): RowsBody = apply { + if (validated) { + return@apply + } + + columnFilters().ifPresent { it.forEach { it.validate() } } + excludeRowIdList() + notSearchQueryAnd() + notSearchQueryOr() + rowIdList() + searchQueryAnd() + searchQueryOr() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OpenlayerInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (columnFilters.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + + (excludeRowIdList.asKnown().getOrNull()?.size ?: 0) + + (notSearchQueryAnd.asKnown().getOrNull()?.size ?: 0) + + (notSearchQueryOr.asKnown().getOrNull()?.size ?: 0) + + (rowIdList.asKnown().getOrNull()?.size ?: 0) + + (searchQueryAnd.asKnown().getOrNull()?.size ?: 0) + + (searchQueryOr.asKnown().getOrNull()?.size ?: 0) + + @JsonDeserialize(using = ColumnFilter.Deserializer::class) + @JsonSerialize(using = ColumnFilter.Serializer::class) + class ColumnFilter + private constructor( + private val set: SetColumnFilter? = null, + private val numeric: NumericColumnFilter? = null, + private val string: StringColumnFilter? = null, + private val _json: JsonValue? = null, + ) { + + fun set(): Optional = Optional.ofNullable(set) + + fun numeric(): Optional = Optional.ofNullable(numeric) + + fun string(): Optional = Optional.ofNullable(string) + + fun isSet(): Boolean = set != null + + fun isNumeric(): Boolean = numeric != null + + fun isString(): Boolean = string != null + + fun asSet(): SetColumnFilter = set.getOrThrow("set") + + fun asNumeric(): NumericColumnFilter = numeric.getOrThrow("numeric") + + fun asString(): StringColumnFilter = string.getOrThrow("string") + + fun _json(): Optional = Optional.ofNullable(_json) + + fun accept(visitor: Visitor): T = + when { + set != null -> visitor.visitSet(set) + numeric != null -> visitor.visitNumeric(numeric) + string != null -> visitor.visitString(string) + else -> visitor.unknown(_json) + } + + private var validated: Boolean = false + + fun validate(): ColumnFilter = apply { + if (validated) { + return@apply + } + + accept( + object : Visitor { + override fun visitSet(set: SetColumnFilter) { + set.validate() + } + + override fun visitNumeric(numeric: NumericColumnFilter) { + numeric.validate() + } + + override fun visitString(string: StringColumnFilter) { + string.validate() + } + } + ) + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OpenlayerInvalidDataException) { + false + } + + /** + * Returns 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 visitSet(set: SetColumnFilter) = set.validity() + + override fun visitNumeric(numeric: NumericColumnFilter) = + numeric.validity() + + override fun visitString(string: StringColumnFilter) = string.validity() + + override fun unknown(json: JsonValue?) = 0 + } + ) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is ColumnFilter && + set == other.set && + numeric == other.numeric && + string == other.string + } + + override fun hashCode(): Int = Objects.hash(set, numeric, string) + + override fun toString(): String = + when { + set != null -> "ColumnFilter{set=$set}" + numeric != null -> "ColumnFilter{numeric=$numeric}" + string != null -> "ColumnFilter{string=$string}" + _json != null -> "ColumnFilter{_unknown=$_json}" + else -> throw IllegalStateException("Invalid ColumnFilter") + } + + companion object { + + @JvmStatic fun ofSet(set: SetColumnFilter) = ColumnFilter(set = set) + + @JvmStatic + fun ofNumeric(numeric: NumericColumnFilter) = ColumnFilter(numeric = numeric) + + @JvmStatic + fun ofString(string: StringColumnFilter) = ColumnFilter(string = string) + } + + /** + * An interface that defines how to map each variant of [ColumnFilter] to a value of + * type [T]. + */ + interface Visitor { + + fun visitSet(set: SetColumnFilter): T + + fun visitNumeric(numeric: NumericColumnFilter): T + + fun visitString(string: StringColumnFilter): T + + /** + * Maps an unknown variant of [ColumnFilter] to a value of type [T]. + * + * An instance of [ColumnFilter] 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 OpenlayerInvalidDataException in the default implementation. + */ + fun unknown(json: JsonValue?): T { + throw OpenlayerInvalidDataException("Unknown ColumnFilter: $json") + } + } + + internal class Deserializer : BaseDeserializer(ColumnFilter::class) { + + override fun ObjectCodec.deserialize(node: JsonNode): ColumnFilter { + val json = JsonValue.fromJsonNode(node) + + val bestMatches = + sequenceOf( + tryDeserialize(node, jacksonTypeRef())?.let { + ColumnFilter(set = it, _json = json) + }, + tryDeserialize(node, jacksonTypeRef()) + ?.let { ColumnFilter(numeric = it, _json = json) }, + tryDeserialize(node, jacksonTypeRef()) + ?.let { ColumnFilter(string = it, _json = json) }, + ) + .filterNotNull() + .allMaxBy { it.validity() } + .toList() + return when (bestMatches.size) { + // This can happen if what we're deserializing is completely + // incompatible with all the possible variants (e.g. deserializing from + // boolean). + 0 -> ColumnFilter(_json = json) + 1 -> bestMatches.single() + // If there's more than one match with the highest validity, then use + // the first completely valid match, or simply the first match if none + // are completely valid. + else -> bestMatches.firstOrNull { it.isValid() } ?: bestMatches.first() + } + } + } + + internal class Serializer : BaseSerializer(ColumnFilter::class) { + + override fun serialize( + value: ColumnFilter, + generator: JsonGenerator, + provider: SerializerProvider, + ) { + when { + value.set != null -> generator.writeObject(value.set) + value.numeric != null -> generator.writeObject(value.numeric) + value.string != null -> generator.writeObject(value.string) + value._json != null -> generator.writeObject(value._json) + else -> throw IllegalStateException("Invalid ColumnFilter") + } + } + } + + class SetColumnFilter + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val measurement: JsonField, + private val operator: JsonField, + private val value: JsonField>, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("measurement") + @ExcludeMissing + measurement: JsonField = JsonMissing.of(), + @JsonProperty("operator") + @ExcludeMissing + operator: JsonField = JsonMissing.of(), + @JsonProperty("value") + @ExcludeMissing + value: JsonField> = JsonMissing.of(), + ) : this(measurement, operator, value, mutableMapOf()) + + /** + * The name of the column. + * + * @throws OpenlayerInvalidDataException if the JSON field has an unexpected + * type or is unexpectedly missing or null (e.g. if the server responded with + * an unexpected value). + */ + fun measurement(): String = measurement.getRequired("measurement") + + /** + * @throws OpenlayerInvalidDataException if the JSON field has an unexpected + * type or is unexpectedly missing or null (e.g. if the server responded with + * an unexpected value). + */ + fun operator(): Operator = operator.getRequired("operator") + + /** + * @throws OpenlayerInvalidDataException if the JSON field has an unexpected + * type or is unexpectedly missing or null (e.g. if the server responded with + * an unexpected value). + */ + fun value(): List = value.getRequired("value") + + /** + * Returns the raw JSON value of [measurement]. + * + * Unlike [measurement], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("measurement") + @ExcludeMissing + fun _measurement(): JsonField = measurement + + /** + * Returns the raw JSON value of [operator]. + * + * Unlike [operator], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("operator") + @ExcludeMissing + fun _operator(): JsonField = operator + + /** + * 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 + * [SetColumnFilter]. + * + * The following fields are required: + * ```java + * .measurement() + * .operator() + * .value() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [SetColumnFilter]. */ + class Builder internal constructor() { + + private var measurement: JsonField? = null + private var operator: JsonField? = null + private var value: JsonField>? = null + private var additionalProperties: MutableMap = + mutableMapOf() + + @JvmSynthetic + internal fun from(setColumnFilter: SetColumnFilter) = apply { + measurement = setColumnFilter.measurement + operator = setColumnFilter.operator + value = setColumnFilter.value.map { it.toMutableList() } + additionalProperties = + setColumnFilter.additionalProperties.toMutableMap() + } + + /** The name of the column. */ + fun measurement(measurement: String) = + measurement(JsonField.of(measurement)) + + /** + * Sets [Builder.measurement] to an arbitrary JSON value. + * + * You should usually call [Builder.measurement] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun measurement(measurement: JsonField) = apply { + this.measurement = measurement + } + + fun operator(operator: Operator) = operator(JsonField.of(operator)) + + /** + * Sets [Builder.operator] to an arbitrary JSON value. + * + * You should usually call [Builder.operator] with a well-typed [Operator] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun operator(operator: JsonField) = apply { + this.operator = operator + } + + fun value(value: List) = value(JsonField.of(value)) + + /** + * Sets [Builder.value] to an arbitrary JSON value. + * + * You should usually call [Builder.value] with a well-typed `List` + * 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.map { it.toMutableList() } + } + + /** + * Adds a single [Value] to [Builder.value]. + * + * @throws IllegalStateException if the field was previously set to a + * non-list. + */ + fun addValue(value: Value) = apply { + this.value = + (this.value ?: JsonField.of(mutableListOf())).also { + checkKnown("value", it).add(value) + } + } + + /** Alias for calling [addValue] with `Value.ofString(string)`. */ + fun addValue(string: String) = addValue(Value.ofString(string)) + + /** Alias for calling [addValue] with `Value.ofNumber(number)`. */ + fun addValue(number: Double) = addValue(Value.ofNumber(number)) + + 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 [SetColumnFilter]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .measurement() + * .operator() + * .value() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): SetColumnFilter = + SetColumnFilter( + checkRequired("measurement", measurement), + checkRequired("operator", operator), + checkRequired("value", value).map { it.toImmutable() }, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): SetColumnFilter = apply { + if (validated) { + return@apply + } + + measurement() + operator().validate() + value().forEach { it.validate() } + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OpenlayerInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (if (measurement.asKnown().isPresent) 1 else 0) + + (operator.asKnown().getOrNull()?.validity() ?: 0) + + (value.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + + class Operator + @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 CONTAINS_NONE = of("contains_none") + + @JvmField val CONTAINS_ANY = of("contains_any") + + @JvmField val CONTAINS_ALL = of("contains_all") + + @JvmField val ONE_OF = of("one_of") + + @JvmField val NONE_OF = of("none_of") + + @JvmStatic fun of(value: String) = Operator(JsonField.of(value)) + } + + /** An enum containing [Operator]'s known values. */ + enum class Known { + CONTAINS_NONE, + CONTAINS_ANY, + CONTAINS_ALL, + ONE_OF, + NONE_OF, + } + + /** + * An enum containing [Operator]'s known values, as well as an [_UNKNOWN] + * member. + * + * An instance of [Operator] 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 { + CONTAINS_NONE, + CONTAINS_ANY, + CONTAINS_ALL, + ONE_OF, + NONE_OF, + /** + * An enum member indicating that [Operator] 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) { + CONTAINS_NONE -> Value.CONTAINS_NONE + CONTAINS_ANY -> Value.CONTAINS_ANY + CONTAINS_ALL -> Value.CONTAINS_ALL + ONE_OF -> Value.ONE_OF + NONE_OF -> Value.NONE_OF + 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 OpenlayerInvalidDataException if this class instance's value is a + * not a known member. + */ + fun known(): Known = + when (this) { + CONTAINS_NONE -> Known.CONTAINS_NONE + CONTAINS_ANY -> Known.CONTAINS_ANY + CONTAINS_ALL -> Known.CONTAINS_ALL + ONE_OF -> Known.ONE_OF + NONE_OF -> Known.NONE_OF + else -> + throw OpenlayerInvalidDataException("Unknown Operator: $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 OpenlayerInvalidDataException if this class instance's value does + * not have the expected primitive type. + */ + fun asString(): String = + _value().asString().orElseThrow { + OpenlayerInvalidDataException("Value is not a String") + } + + private var validated: Boolean = false + + fun validate(): Operator = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OpenlayerInvalidDataException) { + false + } + + /** + * Returns a 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 Operator && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + @JsonDeserialize(using = Value.Deserializer::class) + @JsonSerialize(using = Value.Serializer::class) + class Value + private constructor( + private val string: String? = null, + private val number: Double? = null, + private val _json: JsonValue? = null, + ) { + + fun string(): Optional = Optional.ofNullable(string) + + fun number(): Optional = Optional.ofNullable(number) + + fun isString(): Boolean = string != null + + fun isNumber(): Boolean = number != null + + fun asString(): String = string.getOrThrow("string") + + fun asNumber(): Double = number.getOrThrow("number") + + fun _json(): Optional = Optional.ofNullable(_json) + + fun accept(visitor: Visitor): T = + when { + string != null -> visitor.visitString(string) + number != null -> visitor.visitNumber(number) + else -> visitor.unknown(_json) + } + + private var validated: Boolean = false + + fun validate(): Value = apply { + if (validated) { + return@apply + } + + accept( + object : Visitor { + override fun visitString(string: String) {} + + override fun visitNumber(number: Double) {} + } + ) + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OpenlayerInvalidDataException) { + false + } + + /** + * Returns 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 visitString(string: String) = 1 + + override fun visitNumber(number: Double) = 1 + + override fun unknown(json: JsonValue?) = 0 + } + ) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Value && + string == other.string && + number == other.number + } + + override fun hashCode(): Int = Objects.hash(string, number) + + override fun toString(): String = + when { + string != null -> "Value{string=$string}" + number != null -> "Value{number=$number}" + _json != null -> "Value{_unknown=$_json}" + else -> throw IllegalStateException("Invalid Value") + } + + companion object { + + @JvmStatic fun ofString(string: String) = Value(string = string) + + @JvmStatic fun ofNumber(number: Double) = Value(number = number) + } + + /** + * An interface that defines how to map each variant of [Value] to a value + * of type [T]. + */ + interface Visitor { + + fun visitString(string: String): T + + fun visitNumber(number: Double): T + + /** + * Maps an unknown variant of [Value] to a value of type [T]. + * + * An instance of [Value] 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 OpenlayerInvalidDataException in the default implementation. + */ + fun unknown(json: JsonValue?): T { + throw OpenlayerInvalidDataException("Unknown Value: $json") + } + } + + internal class Deserializer : BaseDeserializer(Value::class) { + + override fun ObjectCodec.deserialize(node: JsonNode): Value { + val json = JsonValue.fromJsonNode(node) + + val bestMatches = + sequenceOf( + tryDeserialize(node, jacksonTypeRef())?.let { + Value(string = it, _json = json) + }, + tryDeserialize(node, jacksonTypeRef())?.let { + Value(number = it, _json = json) + }, + ) + .filterNotNull() + .allMaxBy { it.validity() } + .toList() + return when (bestMatches.size) { + // This can happen if what we're deserializing is completely + // incompatible with all the possible variants (e.g. + // deserializing from object). + 0 -> Value(_json = json) + 1 -> bestMatches.single() + // If there's more than one match with the highest validity, + // then use the first completely valid match, or simply the + // first match if none are completely valid. + else -> + bestMatches.firstOrNull { it.isValid() } + ?: bestMatches.first() + } + } + } + + internal class Serializer : BaseSerializer(Value::class) { + + override fun serialize( + value: Value, + generator: JsonGenerator, + provider: SerializerProvider, + ) { + when { + value.string != null -> generator.writeObject(value.string) + value.number != null -> generator.writeObject(value.number) + value._json != null -> generator.writeObject(value._json) + else -> throw IllegalStateException("Invalid Value") + } + } + } + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is SetColumnFilter && + measurement == other.measurement && + operator == other.operator && + value == other.value && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(measurement, operator, value, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "SetColumnFilter{measurement=$measurement, operator=$operator, value=$value, additionalProperties=$additionalProperties}" + } + + class NumericColumnFilter + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val measurement: JsonField, + private val operator: JsonField, + private val value: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("measurement") + @ExcludeMissing + measurement: JsonField = JsonMissing.of(), + @JsonProperty("operator") + @ExcludeMissing + operator: JsonField = JsonMissing.of(), + @JsonProperty("value") + @ExcludeMissing + value: JsonField = JsonMissing.of(), + ) : this(measurement, operator, value, mutableMapOf()) + + /** + * The name of the column. + * + * @throws OpenlayerInvalidDataException if the JSON field has an unexpected + * type or is unexpectedly missing or null (e.g. if the server responded with + * an unexpected value). + */ + fun measurement(): String = measurement.getRequired("measurement") + + /** + * @throws OpenlayerInvalidDataException if the JSON field has an unexpected + * type or is unexpectedly missing or null (e.g. if the server responded with + * an unexpected value). + */ + fun operator(): Operator = operator.getRequired("operator") + + /** + * @throws OpenlayerInvalidDataException 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 [measurement]. + * + * Unlike [measurement], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("measurement") + @ExcludeMissing + fun _measurement(): JsonField = measurement + + /** + * Returns the raw JSON value of [operator]. + * + * Unlike [operator], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("operator") + @ExcludeMissing + fun _operator(): JsonField = operator + + /** + * 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 + * [NumericColumnFilter]. + * + * The following fields are required: + * ```java + * .measurement() + * .operator() + * .value() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [NumericColumnFilter]. */ + class Builder internal constructor() { + + private var measurement: JsonField? = null + private var operator: JsonField? = null + private var value: JsonField? = null + private var additionalProperties: MutableMap = + mutableMapOf() + + @JvmSynthetic + internal fun from(numericColumnFilter: NumericColumnFilter) = apply { + measurement = numericColumnFilter.measurement + operator = numericColumnFilter.operator + value = numericColumnFilter.value + additionalProperties = + numericColumnFilter.additionalProperties.toMutableMap() + } + + /** The name of the column. */ + fun measurement(measurement: String) = + measurement(JsonField.of(measurement)) + + /** + * Sets [Builder.measurement] to an arbitrary JSON value. + * + * You should usually call [Builder.measurement] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun measurement(measurement: JsonField) = apply { + this.measurement = measurement + } + + fun operator(operator: Operator) = operator(JsonField.of(operator)) + + /** + * Sets [Builder.operator] to an arbitrary JSON value. + * + * You should usually call [Builder.operator] with a well-typed [Operator] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun operator(operator: JsonField) = apply { + this.operator = operator + } + + fun value(value: Float?) = value(JsonField.ofNullable(value)) + + /** + * Alias for [Builder.value]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun value(value: Float) = value(value as Float?) + + /** Alias for calling [Builder.value] with `value.orElse(null)`. */ + fun value(value: Optional) = value(value.getOrNull()) + + /** + * Sets [Builder.value] to an arbitrary JSON value. + * + * You should usually call [Builder.value] with a well-typed [Float] 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 [NumericColumnFilter]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .measurement() + * .operator() + * .value() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): NumericColumnFilter = + NumericColumnFilter( + checkRequired("measurement", measurement), + checkRequired("operator", operator), + checkRequired("value", value), + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): NumericColumnFilter = apply { + if (validated) { + return@apply + } + + measurement() + operator().validate() + value() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OpenlayerInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (if (measurement.asKnown().isPresent) 1 else 0) + + (operator.asKnown().getOrNull()?.validity() ?: 0) + + (if (value.asKnown().isPresent) 1 else 0) + + class Operator + @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 GREATER = of(">") + + @JvmField val GREATER_OR_EQUALS = of(">=") + + @JvmField val IS = of("is") + + @JvmField val LESS = of("<") + + @JvmField val LESS_OR_EQUALS = of("<=") + + @JvmField val NOT_EQUALS = of("!=") + + @JvmStatic fun of(value: String) = Operator(JsonField.of(value)) + } + + /** An enum containing [Operator]'s known values. */ + enum class Known { + GREATER, + GREATER_OR_EQUALS, + IS, + LESS, + LESS_OR_EQUALS, + NOT_EQUALS, + } + + /** + * An enum containing [Operator]'s known values, as well as an [_UNKNOWN] + * member. + * + * An instance of [Operator] 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 { + GREATER, + GREATER_OR_EQUALS, + IS, + LESS, + LESS_OR_EQUALS, + NOT_EQUALS, + /** + * An enum member indicating that [Operator] 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) { + GREATER -> Value.GREATER + GREATER_OR_EQUALS -> Value.GREATER_OR_EQUALS + IS -> Value.IS + LESS -> Value.LESS + LESS_OR_EQUALS -> Value.LESS_OR_EQUALS + NOT_EQUALS -> Value.NOT_EQUALS + 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 OpenlayerInvalidDataException if this class instance's value is a + * not a known member. + */ + fun known(): Known = + when (this) { + GREATER -> Known.GREATER + GREATER_OR_EQUALS -> Known.GREATER_OR_EQUALS + IS -> Known.IS + LESS -> Known.LESS + LESS_OR_EQUALS -> Known.LESS_OR_EQUALS + NOT_EQUALS -> Known.NOT_EQUALS + else -> + throw OpenlayerInvalidDataException("Unknown Operator: $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 OpenlayerInvalidDataException if this class instance's value does + * not have the expected primitive type. + */ + fun asString(): String = + _value().asString().orElseThrow { + OpenlayerInvalidDataException("Value is not a String") + } + + private var validated: Boolean = false + + fun validate(): Operator = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OpenlayerInvalidDataException) { + false + } + + /** + * Returns a 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 Operator && 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 NumericColumnFilter && + measurement == other.measurement && + operator == other.operator && + value == other.value && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(measurement, operator, value, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "NumericColumnFilter{measurement=$measurement, operator=$operator, value=$value, additionalProperties=$additionalProperties}" + } + + class StringColumnFilter + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val measurement: JsonField, + private val operator: JsonField, + private val value: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("measurement") + @ExcludeMissing + measurement: JsonField = JsonMissing.of(), + @JsonProperty("operator") + @ExcludeMissing + operator: JsonField = JsonMissing.of(), + @JsonProperty("value") + @ExcludeMissing + value: JsonField = JsonMissing.of(), + ) : this(measurement, operator, value, mutableMapOf()) + + /** + * The name of the column. + * + * @throws OpenlayerInvalidDataException if the JSON field has an unexpected + * type or is unexpectedly missing or null (e.g. if the server responded with + * an unexpected value). + */ + fun measurement(): String = measurement.getRequired("measurement") + + /** + * @throws OpenlayerInvalidDataException if the JSON field has an unexpected + * type or is unexpectedly missing or null (e.g. if the server responded with + * an unexpected value). + */ + fun operator(): Operator = operator.getRequired("operator") + + /** + * @throws OpenlayerInvalidDataException if the JSON field has an unexpected + * type or is unexpectedly missing or null (e.g. if the server responded with + * an unexpected value). + */ + fun value(): Value = value.getRequired("value") + + /** + * Returns the raw JSON value of [measurement]. + * + * Unlike [measurement], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("measurement") + @ExcludeMissing + fun _measurement(): JsonField = measurement + + /** + * Returns the raw JSON value of [operator]. + * + * Unlike [operator], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("operator") + @ExcludeMissing + fun _operator(): JsonField = operator + + /** + * 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 + * [StringColumnFilter]. + * + * The following fields are required: + * ```java + * .measurement() + * .operator() + * .value() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [StringColumnFilter]. */ + class Builder internal constructor() { + + private var measurement: JsonField? = null + private var operator: JsonField? = null + private var value: JsonField? = null + private var additionalProperties: MutableMap = + mutableMapOf() + + @JvmSynthetic + internal fun from(stringColumnFilter: StringColumnFilter) = apply { + measurement = stringColumnFilter.measurement + operator = stringColumnFilter.operator + value = stringColumnFilter.value + additionalProperties = + stringColumnFilter.additionalProperties.toMutableMap() + } + + /** The name of the column. */ + fun measurement(measurement: String) = + measurement(JsonField.of(measurement)) + + /** + * Sets [Builder.measurement] to an arbitrary JSON value. + * + * You should usually call [Builder.measurement] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun measurement(measurement: JsonField) = apply { + this.measurement = measurement + } + + fun operator(operator: Operator) = operator(JsonField.of(operator)) + + /** + * Sets [Builder.operator] to an arbitrary JSON value. + * + * You should usually call [Builder.operator] with a well-typed [Operator] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun operator(operator: JsonField) = apply { + this.operator = operator + } + + fun value(value: Value) = value(JsonField.of(value)) + + /** + * Sets [Builder.value] to an arbitrary JSON value. + * + * You should usually call [Builder.value] with a well-typed [Value] 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 } + + /** Alias for calling [value] with `Value.ofString(string)`. */ + fun value(string: String) = value(Value.ofString(string)) + + /** Alias for calling [value] with `Value.ofBool(bool)`. */ + fun value(bool: Boolean) = value(Value.ofBool(bool)) + + 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 [StringColumnFilter]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .measurement() + * .operator() + * .value() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): StringColumnFilter = + StringColumnFilter( + checkRequired("measurement", measurement), + checkRequired("operator", operator), + checkRequired("value", value), + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): StringColumnFilter = apply { + if (validated) { + return@apply + } + + measurement() + operator().validate() + value().validate() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OpenlayerInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (if (measurement.asKnown().isPresent) 1 else 0) + + (operator.asKnown().getOrNull()?.validity() ?: 0) + + (value.asKnown().getOrNull()?.validity() ?: 0) + + class Operator + @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 IS = of("is") + + @JvmField val NOT_EQUALS = of("!=") + + @JvmStatic fun of(value: String) = Operator(JsonField.of(value)) + } + + /** An enum containing [Operator]'s known values. */ + enum class Known { + IS, + NOT_EQUALS, + } + + /** + * An enum containing [Operator]'s known values, as well as an [_UNKNOWN] + * member. + * + * An instance of [Operator] 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 { + IS, + NOT_EQUALS, + /** + * An enum member indicating that [Operator] 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) { + IS -> Value.IS + NOT_EQUALS -> Value.NOT_EQUALS + 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 OpenlayerInvalidDataException if this class instance's value is a + * not a known member. + */ + fun known(): Known = + when (this) { + IS -> Known.IS + NOT_EQUALS -> Known.NOT_EQUALS + else -> + throw OpenlayerInvalidDataException("Unknown Operator: $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 OpenlayerInvalidDataException if this class instance's value does + * not have the expected primitive type. + */ + fun asString(): String = + _value().asString().orElseThrow { + OpenlayerInvalidDataException("Value is not a String") + } + + private var validated: Boolean = false + + fun validate(): Operator = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OpenlayerInvalidDataException) { + false + } + + /** + * Returns a 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 Operator && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + @JsonDeserialize(using = Value.Deserializer::class) + @JsonSerialize(using = Value.Serializer::class) + class Value + private constructor( + private val string: String? = null, + private val bool: Boolean? = null, + private val _json: JsonValue? = null, + ) { + + fun string(): Optional = Optional.ofNullable(string) + + fun bool(): Optional = Optional.ofNullable(bool) + + fun isString(): Boolean = string != null + + fun isBool(): Boolean = bool != null + + fun asString(): String = string.getOrThrow("string") + + fun asBool(): Boolean = bool.getOrThrow("bool") + + fun _json(): Optional = Optional.ofNullable(_json) + + fun accept(visitor: Visitor): T = + when { + string != null -> visitor.visitString(string) + bool != null -> visitor.visitBool(bool) + else -> visitor.unknown(_json) + } + + private var validated: Boolean = false + + fun validate(): Value = apply { + if (validated) { + return@apply + } + + accept( + object : Visitor { + override fun visitString(string: String) {} + + override fun visitBool(bool: Boolean) {} + } + ) + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OpenlayerInvalidDataException) { + false + } + + /** + * Returns 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 visitString(string: String) = 1 + + override fun visitBool(bool: Boolean) = 1 + + override fun unknown(json: JsonValue?) = 0 + } + ) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Value && string == other.string && bool == other.bool + } + + override fun hashCode(): Int = Objects.hash(string, bool) + + override fun toString(): String = + when { + string != null -> "Value{string=$string}" + bool != null -> "Value{bool=$bool}" + _json != null -> "Value{_unknown=$_json}" + else -> throw IllegalStateException("Invalid Value") + } + + companion object { + + @JvmStatic fun ofString(string: String) = Value(string = string) + + @JvmStatic fun ofBool(bool: Boolean) = Value(bool = bool) + } + + /** + * An interface that defines how to map each variant of [Value] to a value + * of type [T]. + */ + interface Visitor { + + fun visitString(string: String): T + + fun visitBool(bool: Boolean): T + + /** + * Maps an unknown variant of [Value] to a value of type [T]. + * + * An instance of [Value] 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 OpenlayerInvalidDataException in the default implementation. + */ + fun unknown(json: JsonValue?): T { + throw OpenlayerInvalidDataException("Unknown Value: $json") + } + } + + internal class Deserializer : BaseDeserializer(Value::class) { + + override fun ObjectCodec.deserialize(node: JsonNode): Value { + val json = JsonValue.fromJsonNode(node) + + val bestMatches = + sequenceOf( + tryDeserialize(node, jacksonTypeRef())?.let { + Value(string = it, _json = json) + }, + tryDeserialize(node, jacksonTypeRef())?.let { + Value(bool = it, _json = json) + }, + ) + .filterNotNull() + .allMaxBy { it.validity() } + .toList() + return when (bestMatches.size) { + // This can happen if what we're deserializing is completely + // incompatible with all the possible variants (e.g. + // deserializing from object). + 0 -> Value(_json = json) + 1 -> bestMatches.single() + // If there's more than one match with the highest validity, + // then use the first completely valid match, or simply the + // first match if none are completely valid. + else -> + bestMatches.firstOrNull { it.isValid() } + ?: bestMatches.first() + } + } + } + + internal class Serializer : BaseSerializer(Value::class) { + + override fun serialize( + value: Value, + generator: JsonGenerator, + provider: SerializerProvider, + ) { + when { + value.string != null -> generator.writeObject(value.string) + value.bool != null -> generator.writeObject(value.bool) + value._json != null -> generator.writeObject(value._json) + else -> throw IllegalStateException("Invalid Value") + } + } + } + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is StringColumnFilter && + measurement == other.measurement && + operator == other.operator && + value == other.value && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(measurement, operator, value, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "StringColumnFilter{measurement=$measurement, operator=$operator, value=$value, additionalProperties=$additionalProperties}" + } + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is RowsBody && + columnFilters == other.columnFilters && + excludeRowIdList == other.excludeRowIdList && + notSearchQueryAnd == other.notSearchQueryAnd && + notSearchQueryOr == other.notSearchQueryOr && + rowIdList == other.rowIdList && + searchQueryAnd == other.searchQueryAnd && + searchQueryOr == other.searchQueryOr && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + columnFilters, + excludeRowIdList, + notSearchQueryAnd, + notSearchQueryOr, + rowIdList, + searchQueryAnd, + searchQueryOr, + additionalProperties, + ) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "RowsBody{columnFilters=$columnFilters, excludeRowIdList=$excludeRowIdList, notSearchQueryAnd=$notSearchQueryAnd, notSearchQueryOr=$notSearchQueryOr, rowIdList=$rowIdList, searchQueryAnd=$searchQueryAnd, searchQueryOr=$searchQueryOr, additionalProperties=$additionalProperties}" + } + override fun equals(other: Any?): Boolean { if (this === other) { return true @@ -4037,8 +6805,11 @@ private constructor( projectVersionId == other.projectVersionId && status == other.status && statusMessage == other.statusMessage && + expectedValues == other.expectedValues && goal == other.goal && goalId == other.goalId && + rows == other.rows && + rowsBody == other.rowsBody && additionalProperties == other.additionalProperties } @@ -4053,8 +6824,11 @@ private constructor( projectVersionId, status, statusMessage, + expectedValues, goal, goalId, + rows, + rowsBody, additionalProperties, ) } @@ -4062,7 +6836,7 @@ private constructor( override fun hashCode(): Int = hashCode override fun toString() = - "Item{id=$id, dateCreated=$dateCreated, dateDataEnds=$dateDataEnds, dateDataStarts=$dateDataStarts, dateUpdated=$dateUpdated, inferencePipelineId=$inferencePipelineId, projectVersionId=$projectVersionId, status=$status, statusMessage=$statusMessage, goal=$goal, goalId=$goalId, additionalProperties=$additionalProperties}" + "Item{id=$id, dateCreated=$dateCreated, dateDataEnds=$dateDataEnds, dateDataStarts=$dateDataStarts, dateUpdated=$dateUpdated, inferencePipelineId=$inferencePipelineId, projectVersionId=$projectVersionId, status=$status, statusMessage=$statusMessage, expectedValues=$expectedValues, goal=$goal, goalId=$goalId, rows=$rows, rowsBody=$rowsBody, additionalProperties=$additionalProperties}" } override fun equals(other: Any?): Boolean { diff --git a/openlayer-java-core/src/main/kotlin/com/openlayer/api/models/inferencepipelines/testresults/TestResultListResponse.kt b/openlayer-java-core/src/main/kotlin/com/openlayer/api/models/inferencepipelines/testresults/TestResultListResponse.kt index 29eb854d..309d2e41 100644 --- a/openlayer-java-core/src/main/kotlin/com/openlayer/api/models/inferencepipelines/testresults/TestResultListResponse.kt +++ b/openlayer-java-core/src/main/kotlin/com/openlayer/api/models/inferencepipelines/testresults/TestResultListResponse.kt @@ -195,8 +195,11 @@ private constructor( private val projectVersionId: JsonField, private val status: JsonField, private val statusMessage: JsonField, + private val expectedValues: JsonField>, private val goal: JsonField, private val goalId: JsonField, + private val rows: JsonField, + private val rowsBody: JsonField, private val additionalProperties: MutableMap, ) { @@ -225,8 +228,15 @@ private constructor( @JsonProperty("statusMessage") @ExcludeMissing statusMessage: JsonField = JsonMissing.of(), + @JsonProperty("expectedValues") + @ExcludeMissing + expectedValues: JsonField> = JsonMissing.of(), @JsonProperty("goal") @ExcludeMissing goal: JsonField = JsonMissing.of(), @JsonProperty("goalId") @ExcludeMissing goalId: JsonField = JsonMissing.of(), + @JsonProperty("rows") @ExcludeMissing rows: JsonField = JsonMissing.of(), + @JsonProperty("rowsBody") + @ExcludeMissing + rowsBody: JsonField = JsonMissing.of(), ) : this( id, dateCreated, @@ -237,8 +247,11 @@ private constructor( projectVersionId, status, statusMessage, + expectedValues, goal, goalId, + rows, + rowsBody, mutableMapOf(), ) @@ -316,6 +329,13 @@ private constructor( */ fun statusMessage(): Optional = statusMessage.getOptional("statusMessage") + /** + * @throws OpenlayerInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun expectedValues(): Optional> = + expectedValues.getOptional("expectedValues") + /** * @throws OpenlayerInvalidDataException if the JSON field has an unexpected type (e.g. if * the server responded with an unexpected value). @@ -330,6 +350,22 @@ private constructor( */ fun goalId(): Optional = goalId.getOptional("goalId") + /** + * The URL to the rows of the test result. + * + * @throws OpenlayerInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun rows(): Optional = rows.getOptional("rows") + + /** + * The body of the rows request. + * + * @throws OpenlayerInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun rowsBody(): Optional = rowsBody.getOptional("rowsBody") + /** * Returns the raw JSON value of [id]. * @@ -412,6 +448,16 @@ private constructor( @ExcludeMissing fun _statusMessage(): JsonField = statusMessage + /** + * Returns the raw JSON value of [expectedValues]. + * + * Unlike [expectedValues], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("expectedValues") + @ExcludeMissing + fun _expectedValues(): JsonField> = expectedValues + /** * Returns the raw JSON value of [goal]. * @@ -426,6 +472,20 @@ private constructor( */ @JsonProperty("goalId") @ExcludeMissing fun _goalId(): JsonField = goalId + /** + * Returns the raw JSON value of [rows]. + * + * Unlike [rows], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("rows") @ExcludeMissing fun _rows(): JsonField = rows + + /** + * Returns the raw JSON value of [rowsBody]. + * + * Unlike [rowsBody], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("rowsBody") @ExcludeMissing fun _rowsBody(): JsonField = rowsBody + @JsonAnySetter private fun putAdditionalProperty(key: String, value: JsonValue) { additionalProperties.put(key, value) @@ -471,8 +531,11 @@ private constructor( private var projectVersionId: JsonField? = null private var status: JsonField? = null private var statusMessage: JsonField? = null + private var expectedValues: JsonField>? = null private var goal: JsonField = JsonMissing.of() private var goalId: JsonField = JsonMissing.of() + private var rows: JsonField = JsonMissing.of() + private var rowsBody: JsonField = JsonMissing.of() private var additionalProperties: MutableMap = mutableMapOf() @JvmSynthetic @@ -486,8 +549,11 @@ private constructor( projectVersionId = item.projectVersionId status = item.status statusMessage = item.statusMessage + expectedValues = item.expectedValues.map { it.toMutableList() } goal = item.goal goalId = item.goalId + rows = item.rows + rowsBody = item.rowsBody additionalProperties = item.additionalProperties.toMutableMap() } @@ -643,6 +709,32 @@ private constructor( this.statusMessage = statusMessage } + fun expectedValues(expectedValues: List) = + expectedValues(JsonField.of(expectedValues)) + + /** + * Sets [Builder.expectedValues] to an arbitrary JSON value. + * + * You should usually call [Builder.expectedValues] with a well-typed + * `List` value instead. This method is primarily for setting the field + * to an undocumented or not yet supported value. + */ + fun expectedValues(expectedValues: JsonField>) = apply { + this.expectedValues = expectedValues.map { it.toMutableList() } + } + + /** + * Adds a single [ExpectedValue] to [expectedValues]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addExpectedValue(expectedValue: ExpectedValue) = apply { + expectedValues = + (expectedValues ?: JsonField.of(mutableListOf())).also { + checkKnown("expectedValues", it).add(expectedValue) + } + } + fun goal(goal: Goal) = goal(JsonField.of(goal)) /** @@ -669,6 +761,33 @@ private constructor( */ fun goalId(goalId: JsonField) = apply { this.goalId = goalId } + /** The URL to the rows of the test result. */ + fun rows(rows: String) = rows(JsonField.of(rows)) + + /** + * Sets [Builder.rows] to an arbitrary JSON value. + * + * You should usually call [Builder.rows] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun rows(rows: JsonField) = apply { this.rows = rows } + + /** The body of the rows request. */ + fun rowsBody(rowsBody: RowsBody?) = rowsBody(JsonField.ofNullable(rowsBody)) + + /** Alias for calling [Builder.rowsBody] with `rowsBody.orElse(null)`. */ + fun rowsBody(rowsBody: Optional) = rowsBody(rowsBody.getOrNull()) + + /** + * Sets [Builder.rowsBody] to an arbitrary JSON value. + * + * You should usually call [Builder.rowsBody] with a well-typed [RowsBody] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun rowsBody(rowsBody: JsonField) = apply { this.rowsBody = rowsBody } + fun additionalProperties(additionalProperties: Map) = apply { this.additionalProperties.clear() putAllAdditionalProperties(additionalProperties) @@ -719,8 +838,11 @@ private constructor( checkRequired("projectVersionId", projectVersionId), checkRequired("status", status), checkRequired("statusMessage", statusMessage), + (expectedValues ?: JsonMissing.of()).map { it.toImmutable() }, goal, goalId, + rows, + rowsBody, additionalProperties.toMutableMap(), ) } @@ -741,8 +863,11 @@ private constructor( projectVersionId() status().validate() statusMessage() + expectedValues().ifPresent { it.forEach { it.validate() } } goal().ifPresent { it.validate() } goalId() + rows() + rowsBody().ifPresent { it.validate() } validated = true } @@ -771,8 +896,11 @@ private constructor( (if (projectVersionId.asKnown().isPresent) 1 else 0) + (status.asKnown().getOrNull()?.validity() ?: 0) + (if (statusMessage.asKnown().isPresent) 1 else 0) + + (expectedValues.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + (goal.asKnown().getOrNull()?.validity() ?: 0) + - (if (goalId.asKnown().isPresent) 1 else 0) + (if (goalId.asKnown().isPresent) 1 else 0) + + (if (rows.asKnown().isPresent) 1 else 0) + + (rowsBody.asKnown().getOrNull()?.validity() ?: 0) /** The status of the test. */ class Status @JsonCreator private constructor(private val value: JsonField) : Enum { @@ -922,6 +1050,277 @@ private constructor( override fun toString() = value.toString() } + class ExpectedValue + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val lowerThreshold: JsonField, + private val measurement: JsonField, + private val upperThreshold: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("lowerThreshold") + @ExcludeMissing + lowerThreshold: JsonField = JsonMissing.of(), + @JsonProperty("measurement") + @ExcludeMissing + measurement: JsonField = JsonMissing.of(), + @JsonProperty("upperThreshold") + @ExcludeMissing + upperThreshold: JsonField = JsonMissing.of(), + ) : this(lowerThreshold, measurement, upperThreshold, mutableMapOf()) + + /** + * the lower threshold for the expected value + * + * @throws OpenlayerInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun lowerThreshold(): Optional = lowerThreshold.getOptional("lowerThreshold") + + /** + * One of the `measurement` values in the test's thresholds + * + * @throws OpenlayerInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun measurement(): Optional = measurement.getOptional("measurement") + + /** + * The upper threshold for the expected value + * + * @throws OpenlayerInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun upperThreshold(): Optional = upperThreshold.getOptional("upperThreshold") + + /** + * Returns the raw JSON value of [lowerThreshold]. + * + * Unlike [lowerThreshold], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("lowerThreshold") + @ExcludeMissing + fun _lowerThreshold(): JsonField = lowerThreshold + + /** + * Returns the raw JSON value of [measurement]. + * + * Unlike [measurement], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("measurement") + @ExcludeMissing + fun _measurement(): JsonField = measurement + + /** + * Returns the raw JSON value of [upperThreshold]. + * + * Unlike [upperThreshold], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("upperThreshold") + @ExcludeMissing + fun _upperThreshold(): JsonField = upperThreshold + + @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 [ExpectedValue]. */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [ExpectedValue]. */ + class Builder internal constructor() { + + private var lowerThreshold: JsonField = JsonMissing.of() + private var measurement: JsonField = JsonMissing.of() + private var upperThreshold: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(expectedValue: ExpectedValue) = apply { + lowerThreshold = expectedValue.lowerThreshold + measurement = expectedValue.measurement + upperThreshold = expectedValue.upperThreshold + additionalProperties = expectedValue.additionalProperties.toMutableMap() + } + + /** the lower threshold for the expected value */ + fun lowerThreshold(lowerThreshold: Float?) = + lowerThreshold(JsonField.ofNullable(lowerThreshold)) + + /** + * Alias for [Builder.lowerThreshold]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun lowerThreshold(lowerThreshold: Float) = lowerThreshold(lowerThreshold as Float?) + + /** + * Alias for calling [Builder.lowerThreshold] with `lowerThreshold.orElse(null)`. + */ + fun lowerThreshold(lowerThreshold: Optional) = + lowerThreshold(lowerThreshold.getOrNull()) + + /** + * Sets [Builder.lowerThreshold] to an arbitrary JSON value. + * + * You should usually call [Builder.lowerThreshold] with a well-typed [Float] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun lowerThreshold(lowerThreshold: JsonField) = apply { + this.lowerThreshold = lowerThreshold + } + + /** One of the `measurement` values in the test's thresholds */ + fun measurement(measurement: String) = measurement(JsonField.of(measurement)) + + /** + * Sets [Builder.measurement] to an arbitrary JSON value. + * + * You should usually call [Builder.measurement] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun measurement(measurement: JsonField) = apply { + this.measurement = measurement + } + + /** The upper threshold for the expected value */ + fun upperThreshold(upperThreshold: Float?) = + upperThreshold(JsonField.ofNullable(upperThreshold)) + + /** + * Alias for [Builder.upperThreshold]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun upperThreshold(upperThreshold: Float) = upperThreshold(upperThreshold as Float?) + + /** + * Alias for calling [Builder.upperThreshold] with `upperThreshold.orElse(null)`. + */ + fun upperThreshold(upperThreshold: Optional) = + upperThreshold(upperThreshold.getOrNull()) + + /** + * Sets [Builder.upperThreshold] to an arbitrary JSON value. + * + * You should usually call [Builder.upperThreshold] with a well-typed [Float] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun upperThreshold(upperThreshold: JsonField) = apply { + this.upperThreshold = upperThreshold + } + + 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 [ExpectedValue]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): ExpectedValue = + ExpectedValue( + lowerThreshold, + measurement, + upperThreshold, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): ExpectedValue = apply { + if (validated) { + return@apply + } + + lowerThreshold() + measurement() + upperThreshold() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OpenlayerInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (if (lowerThreshold.asKnown().isPresent) 1 else 0) + + (if (measurement.asKnown().isPresent) 1 else 0) + + (if (upperThreshold.asKnown().isPresent) 1 else 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is ExpectedValue && + lowerThreshold == other.lowerThreshold && + measurement == other.measurement && + upperThreshold == other.upperThreshold && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(lowerThreshold, measurement, upperThreshold, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "ExpectedValue{lowerThreshold=$lowerThreshold, measurement=$measurement, upperThreshold=$upperThreshold, additionalProperties=$additionalProperties}" + } + class Goal @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( @@ -4022,6 +4421,2375 @@ private constructor( "Goal{id=$id, commentCount=$commentCount, creatorId=$creatorId, dateArchived=$dateArchived, dateCreated=$dateCreated, dateUpdated=$dateUpdated, description=$description, name=$name, number=$number, originProjectVersionId=$originProjectVersionId, subtype=$subtype, suggested=$suggested, thresholds=$thresholds, type=$type, archived=$archived, delayWindow=$delayWindow, evaluationWindow=$evaluationWindow, usesMlModel=$usesMlModel, usesProductionData=$usesProductionData, usesReferenceDataset=$usesReferenceDataset, usesTrainingDataset=$usesTrainingDataset, usesValidationDataset=$usesValidationDataset, additionalProperties=$additionalProperties}" } + /** The body of the rows request. */ + class RowsBody + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val columnFilters: JsonField>, + private val excludeRowIdList: JsonField>, + private val notSearchQueryAnd: JsonField>, + private val notSearchQueryOr: JsonField>, + private val rowIdList: JsonField>, + private val searchQueryAnd: JsonField>, + private val searchQueryOr: JsonField>, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("columnFilters") + @ExcludeMissing + columnFilters: JsonField> = JsonMissing.of(), + @JsonProperty("excludeRowIdList") + @ExcludeMissing + excludeRowIdList: JsonField> = JsonMissing.of(), + @JsonProperty("notSearchQueryAnd") + @ExcludeMissing + notSearchQueryAnd: JsonField> = JsonMissing.of(), + @JsonProperty("notSearchQueryOr") + @ExcludeMissing + notSearchQueryOr: JsonField> = JsonMissing.of(), + @JsonProperty("rowIdList") + @ExcludeMissing + rowIdList: JsonField> = JsonMissing.of(), + @JsonProperty("searchQueryAnd") + @ExcludeMissing + searchQueryAnd: JsonField> = JsonMissing.of(), + @JsonProperty("searchQueryOr") + @ExcludeMissing + searchQueryOr: JsonField> = JsonMissing.of(), + ) : this( + columnFilters, + excludeRowIdList, + notSearchQueryAnd, + notSearchQueryOr, + rowIdList, + searchQueryAnd, + searchQueryOr, + mutableMapOf(), + ) + + /** + * @throws OpenlayerInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun columnFilters(): Optional> = + columnFilters.getOptional("columnFilters") + + /** + * @throws OpenlayerInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun excludeRowIdList(): Optional> = + excludeRowIdList.getOptional("excludeRowIdList") + + /** + * @throws OpenlayerInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun notSearchQueryAnd(): Optional> = + notSearchQueryAnd.getOptional("notSearchQueryAnd") + + /** + * @throws OpenlayerInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun notSearchQueryOr(): Optional> = + notSearchQueryOr.getOptional("notSearchQueryOr") + + /** + * @throws OpenlayerInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun rowIdList(): Optional> = rowIdList.getOptional("rowIdList") + + /** + * @throws OpenlayerInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun searchQueryAnd(): Optional> = + searchQueryAnd.getOptional("searchQueryAnd") + + /** + * @throws OpenlayerInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun searchQueryOr(): Optional> = searchQueryOr.getOptional("searchQueryOr") + + /** + * Returns the raw JSON value of [columnFilters]. + * + * Unlike [columnFilters], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("columnFilters") + @ExcludeMissing + fun _columnFilters(): JsonField> = columnFilters + + /** + * Returns the raw JSON value of [excludeRowIdList]. + * + * Unlike [excludeRowIdList], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("excludeRowIdList") + @ExcludeMissing + fun _excludeRowIdList(): JsonField> = excludeRowIdList + + /** + * Returns the raw JSON value of [notSearchQueryAnd]. + * + * Unlike [notSearchQueryAnd], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("notSearchQueryAnd") + @ExcludeMissing + fun _notSearchQueryAnd(): JsonField> = notSearchQueryAnd + + /** + * Returns the raw JSON value of [notSearchQueryOr]. + * + * Unlike [notSearchQueryOr], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("notSearchQueryOr") + @ExcludeMissing + fun _notSearchQueryOr(): JsonField> = notSearchQueryOr + + /** + * Returns the raw JSON value of [rowIdList]. + * + * Unlike [rowIdList], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("rowIdList") + @ExcludeMissing + fun _rowIdList(): JsonField> = rowIdList + + /** + * Returns the raw JSON value of [searchQueryAnd]. + * + * Unlike [searchQueryAnd], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("searchQueryAnd") + @ExcludeMissing + fun _searchQueryAnd(): JsonField> = searchQueryAnd + + /** + * Returns the raw JSON value of [searchQueryOr]. + * + * Unlike [searchQueryOr], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("searchQueryOr") + @ExcludeMissing + fun _searchQueryOr(): JsonField> = searchQueryOr + + @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 [RowsBody]. */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [RowsBody]. */ + class Builder internal constructor() { + + private var columnFilters: JsonField>? = null + private var excludeRowIdList: JsonField>? = null + private var notSearchQueryAnd: JsonField>? = null + private var notSearchQueryOr: JsonField>? = null + private var rowIdList: JsonField>? = null + private var searchQueryAnd: JsonField>? = null + private var searchQueryOr: JsonField>? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(rowsBody: RowsBody) = apply { + columnFilters = rowsBody.columnFilters.map { it.toMutableList() } + excludeRowIdList = rowsBody.excludeRowIdList.map { it.toMutableList() } + notSearchQueryAnd = rowsBody.notSearchQueryAnd.map { it.toMutableList() } + notSearchQueryOr = rowsBody.notSearchQueryOr.map { it.toMutableList() } + rowIdList = rowsBody.rowIdList.map { it.toMutableList() } + searchQueryAnd = rowsBody.searchQueryAnd.map { it.toMutableList() } + searchQueryOr = rowsBody.searchQueryOr.map { it.toMutableList() } + additionalProperties = rowsBody.additionalProperties.toMutableMap() + } + + fun columnFilters(columnFilters: List?) = + columnFilters(JsonField.ofNullable(columnFilters)) + + /** Alias for calling [Builder.columnFilters] with `columnFilters.orElse(null)`. */ + fun columnFilters(columnFilters: Optional>) = + columnFilters(columnFilters.getOrNull()) + + /** + * Sets [Builder.columnFilters] to an arbitrary JSON value. + * + * You should usually call [Builder.columnFilters] with a well-typed + * `List` value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. + */ + fun columnFilters(columnFilters: JsonField>) = apply { + this.columnFilters = columnFilters.map { it.toMutableList() } + } + + /** + * Adds a single [ColumnFilter] to [columnFilters]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addColumnFilter(columnFilter: ColumnFilter) = apply { + columnFilters = + (columnFilters ?: JsonField.of(mutableListOf())).also { + checkKnown("columnFilters", it).add(columnFilter) + } + } + + /** Alias for calling [addColumnFilter] with `ColumnFilter.ofSet(set)`. */ + fun addColumnFilter(set: ColumnFilter.SetColumnFilter) = + addColumnFilter(ColumnFilter.ofSet(set)) + + /** Alias for calling [addColumnFilter] with `ColumnFilter.ofNumeric(numeric)`. */ + fun addColumnFilter(numeric: ColumnFilter.NumericColumnFilter) = + addColumnFilter(ColumnFilter.ofNumeric(numeric)) + + /** Alias for calling [addColumnFilter] with `ColumnFilter.ofString(string)`. */ + fun addColumnFilter(string: ColumnFilter.StringColumnFilter) = + addColumnFilter(ColumnFilter.ofString(string)) + + fun excludeRowIdList(excludeRowIdList: List?) = + excludeRowIdList(JsonField.ofNullable(excludeRowIdList)) + + /** + * Alias for calling [Builder.excludeRowIdList] with + * `excludeRowIdList.orElse(null)`. + */ + fun excludeRowIdList(excludeRowIdList: Optional>) = + excludeRowIdList(excludeRowIdList.getOrNull()) + + /** + * Sets [Builder.excludeRowIdList] to an arbitrary JSON value. + * + * You should usually call [Builder.excludeRowIdList] with a well-typed `List` + * value instead. This method is primarily for setting the field to an undocumented + * or not yet supported value. + */ + fun excludeRowIdList(excludeRowIdList: JsonField>) = apply { + this.excludeRowIdList = excludeRowIdList.map { it.toMutableList() } + } + + /** + * Adds a single [Long] to [Builder.excludeRowIdList]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addExcludeRowIdList(excludeRowIdList: Long) = apply { + this.excludeRowIdList = + (this.excludeRowIdList ?: JsonField.of(mutableListOf())).also { + checkKnown("excludeRowIdList", it).add(excludeRowIdList) + } + } + + fun notSearchQueryAnd(notSearchQueryAnd: List?) = + notSearchQueryAnd(JsonField.ofNullable(notSearchQueryAnd)) + + /** + * Alias for calling [Builder.notSearchQueryAnd] with + * `notSearchQueryAnd.orElse(null)`. + */ + fun notSearchQueryAnd(notSearchQueryAnd: Optional>) = + notSearchQueryAnd(notSearchQueryAnd.getOrNull()) + + /** + * Sets [Builder.notSearchQueryAnd] to an arbitrary JSON value. + * + * You should usually call [Builder.notSearchQueryAnd] with a well-typed + * `List` value instead. This method is primarily for setting the field to + * an undocumented or not yet supported value. + */ + fun notSearchQueryAnd(notSearchQueryAnd: JsonField>) = apply { + this.notSearchQueryAnd = notSearchQueryAnd.map { it.toMutableList() } + } + + /** + * Adds a single [String] to [Builder.notSearchQueryAnd]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addNotSearchQueryAnd(notSearchQueryAnd: String) = apply { + this.notSearchQueryAnd = + (this.notSearchQueryAnd ?: JsonField.of(mutableListOf())).also { + checkKnown("notSearchQueryAnd", it).add(notSearchQueryAnd) + } + } + + fun notSearchQueryOr(notSearchQueryOr: List?) = + notSearchQueryOr(JsonField.ofNullable(notSearchQueryOr)) + + /** + * Alias for calling [Builder.notSearchQueryOr] with + * `notSearchQueryOr.orElse(null)`. + */ + fun notSearchQueryOr(notSearchQueryOr: Optional>) = + notSearchQueryOr(notSearchQueryOr.getOrNull()) + + /** + * Sets [Builder.notSearchQueryOr] to an arbitrary JSON value. + * + * You should usually call [Builder.notSearchQueryOr] with a well-typed + * `List` value instead. This method is primarily for setting the field to + * an undocumented or not yet supported value. + */ + fun notSearchQueryOr(notSearchQueryOr: JsonField>) = apply { + this.notSearchQueryOr = notSearchQueryOr.map { it.toMutableList() } + } + + /** + * Adds a single [String] to [Builder.notSearchQueryOr]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addNotSearchQueryOr(notSearchQueryOr: String) = apply { + this.notSearchQueryOr = + (this.notSearchQueryOr ?: JsonField.of(mutableListOf())).also { + checkKnown("notSearchQueryOr", it).add(notSearchQueryOr) + } + } + + fun rowIdList(rowIdList: List?) = rowIdList(JsonField.ofNullable(rowIdList)) + + /** Alias for calling [Builder.rowIdList] with `rowIdList.orElse(null)`. */ + fun rowIdList(rowIdList: Optional>) = rowIdList(rowIdList.getOrNull()) + + /** + * Sets [Builder.rowIdList] to an arbitrary JSON value. + * + * You should usually call [Builder.rowIdList] with a well-typed `List` value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun rowIdList(rowIdList: JsonField>) = apply { + this.rowIdList = rowIdList.map { it.toMutableList() } + } + + /** + * Adds a single [Long] to [Builder.rowIdList]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addRowIdList(rowIdList: Long) = apply { + this.rowIdList = + (this.rowIdList ?: JsonField.of(mutableListOf())).also { + checkKnown("rowIdList", it).add(rowIdList) + } + } + + fun searchQueryAnd(searchQueryAnd: List?) = + searchQueryAnd(JsonField.ofNullable(searchQueryAnd)) + + /** + * Alias for calling [Builder.searchQueryAnd] with `searchQueryAnd.orElse(null)`. + */ + fun searchQueryAnd(searchQueryAnd: Optional>) = + searchQueryAnd(searchQueryAnd.getOrNull()) + + /** + * Sets [Builder.searchQueryAnd] to an arbitrary JSON value. + * + * You should usually call [Builder.searchQueryAnd] with a well-typed `List` + * value instead. This method is primarily for setting the field to an undocumented + * or not yet supported value. + */ + fun searchQueryAnd(searchQueryAnd: JsonField>) = apply { + this.searchQueryAnd = searchQueryAnd.map { it.toMutableList() } + } + + /** + * Adds a single [String] to [Builder.searchQueryAnd]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addSearchQueryAnd(searchQueryAnd: String) = apply { + this.searchQueryAnd = + (this.searchQueryAnd ?: JsonField.of(mutableListOf())).also { + checkKnown("searchQueryAnd", it).add(searchQueryAnd) + } + } + + fun searchQueryOr(searchQueryOr: List?) = + searchQueryOr(JsonField.ofNullable(searchQueryOr)) + + /** Alias for calling [Builder.searchQueryOr] with `searchQueryOr.orElse(null)`. */ + fun searchQueryOr(searchQueryOr: Optional>) = + searchQueryOr(searchQueryOr.getOrNull()) + + /** + * Sets [Builder.searchQueryOr] to an arbitrary JSON value. + * + * You should usually call [Builder.searchQueryOr] with a well-typed `List` + * value instead. This method is primarily for setting the field to an undocumented + * or not yet supported value. + */ + fun searchQueryOr(searchQueryOr: JsonField>) = apply { + this.searchQueryOr = searchQueryOr.map { it.toMutableList() } + } + + /** + * Adds a single [String] to [Builder.searchQueryOr]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addSearchQueryOr(searchQueryOr: String) = apply { + this.searchQueryOr = + (this.searchQueryOr ?: JsonField.of(mutableListOf())).also { + checkKnown("searchQueryOr", it).add(searchQueryOr) + } + } + + 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 [RowsBody]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): RowsBody = + RowsBody( + (columnFilters ?: JsonMissing.of()).map { it.toImmutable() }, + (excludeRowIdList ?: JsonMissing.of()).map { it.toImmutable() }, + (notSearchQueryAnd ?: JsonMissing.of()).map { it.toImmutable() }, + (notSearchQueryOr ?: JsonMissing.of()).map { it.toImmutable() }, + (rowIdList ?: JsonMissing.of()).map { it.toImmutable() }, + (searchQueryAnd ?: JsonMissing.of()).map { it.toImmutable() }, + (searchQueryOr ?: JsonMissing.of()).map { it.toImmutable() }, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): RowsBody = apply { + if (validated) { + return@apply + } + + columnFilters().ifPresent { it.forEach { it.validate() } } + excludeRowIdList() + notSearchQueryAnd() + notSearchQueryOr() + rowIdList() + searchQueryAnd() + searchQueryOr() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OpenlayerInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (columnFilters.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + + (excludeRowIdList.asKnown().getOrNull()?.size ?: 0) + + (notSearchQueryAnd.asKnown().getOrNull()?.size ?: 0) + + (notSearchQueryOr.asKnown().getOrNull()?.size ?: 0) + + (rowIdList.asKnown().getOrNull()?.size ?: 0) + + (searchQueryAnd.asKnown().getOrNull()?.size ?: 0) + + (searchQueryOr.asKnown().getOrNull()?.size ?: 0) + + @JsonDeserialize(using = ColumnFilter.Deserializer::class) + @JsonSerialize(using = ColumnFilter.Serializer::class) + class ColumnFilter + private constructor( + private val set: SetColumnFilter? = null, + private val numeric: NumericColumnFilter? = null, + private val string: StringColumnFilter? = null, + private val _json: JsonValue? = null, + ) { + + fun set(): Optional = Optional.ofNullable(set) + + fun numeric(): Optional = Optional.ofNullable(numeric) + + fun string(): Optional = Optional.ofNullable(string) + + fun isSet(): Boolean = set != null + + fun isNumeric(): Boolean = numeric != null + + fun isString(): Boolean = string != null + + fun asSet(): SetColumnFilter = set.getOrThrow("set") + + fun asNumeric(): NumericColumnFilter = numeric.getOrThrow("numeric") + + fun asString(): StringColumnFilter = string.getOrThrow("string") + + fun _json(): Optional = Optional.ofNullable(_json) + + fun accept(visitor: Visitor): T = + when { + set != null -> visitor.visitSet(set) + numeric != null -> visitor.visitNumeric(numeric) + string != null -> visitor.visitString(string) + else -> visitor.unknown(_json) + } + + private var validated: Boolean = false + + fun validate(): ColumnFilter = apply { + if (validated) { + return@apply + } + + accept( + object : Visitor { + override fun visitSet(set: SetColumnFilter) { + set.validate() + } + + override fun visitNumeric(numeric: NumericColumnFilter) { + numeric.validate() + } + + override fun visitString(string: StringColumnFilter) { + string.validate() + } + } + ) + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OpenlayerInvalidDataException) { + false + } + + /** + * Returns 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 visitSet(set: SetColumnFilter) = set.validity() + + override fun visitNumeric(numeric: NumericColumnFilter) = + numeric.validity() + + override fun visitString(string: StringColumnFilter) = string.validity() + + override fun unknown(json: JsonValue?) = 0 + } + ) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is ColumnFilter && + set == other.set && + numeric == other.numeric && + string == other.string + } + + override fun hashCode(): Int = Objects.hash(set, numeric, string) + + override fun toString(): String = + when { + set != null -> "ColumnFilter{set=$set}" + numeric != null -> "ColumnFilter{numeric=$numeric}" + string != null -> "ColumnFilter{string=$string}" + _json != null -> "ColumnFilter{_unknown=$_json}" + else -> throw IllegalStateException("Invalid ColumnFilter") + } + + companion object { + + @JvmStatic fun ofSet(set: SetColumnFilter) = ColumnFilter(set = set) + + @JvmStatic + fun ofNumeric(numeric: NumericColumnFilter) = ColumnFilter(numeric = numeric) + + @JvmStatic + fun ofString(string: StringColumnFilter) = ColumnFilter(string = string) + } + + /** + * An interface that defines how to map each variant of [ColumnFilter] to a value of + * type [T]. + */ + interface Visitor { + + fun visitSet(set: SetColumnFilter): T + + fun visitNumeric(numeric: NumericColumnFilter): T + + fun visitString(string: StringColumnFilter): T + + /** + * Maps an unknown variant of [ColumnFilter] to a value of type [T]. + * + * An instance of [ColumnFilter] 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 OpenlayerInvalidDataException in the default implementation. + */ + fun unknown(json: JsonValue?): T { + throw OpenlayerInvalidDataException("Unknown ColumnFilter: $json") + } + } + + internal class Deserializer : BaseDeserializer(ColumnFilter::class) { + + override fun ObjectCodec.deserialize(node: JsonNode): ColumnFilter { + val json = JsonValue.fromJsonNode(node) + + val bestMatches = + sequenceOf( + tryDeserialize(node, jacksonTypeRef())?.let { + ColumnFilter(set = it, _json = json) + }, + tryDeserialize(node, jacksonTypeRef()) + ?.let { ColumnFilter(numeric = it, _json = json) }, + tryDeserialize(node, jacksonTypeRef()) + ?.let { ColumnFilter(string = it, _json = json) }, + ) + .filterNotNull() + .allMaxBy { it.validity() } + .toList() + return when (bestMatches.size) { + // This can happen if what we're deserializing is completely + // incompatible with all the possible variants (e.g. deserializing from + // boolean). + 0 -> ColumnFilter(_json = json) + 1 -> bestMatches.single() + // If there's more than one match with the highest validity, then use + // the first completely valid match, or simply the first match if none + // are completely valid. + else -> bestMatches.firstOrNull { it.isValid() } ?: bestMatches.first() + } + } + } + + internal class Serializer : BaseSerializer(ColumnFilter::class) { + + override fun serialize( + value: ColumnFilter, + generator: JsonGenerator, + provider: SerializerProvider, + ) { + when { + value.set != null -> generator.writeObject(value.set) + value.numeric != null -> generator.writeObject(value.numeric) + value.string != null -> generator.writeObject(value.string) + value._json != null -> generator.writeObject(value._json) + else -> throw IllegalStateException("Invalid ColumnFilter") + } + } + } + + class SetColumnFilter + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val measurement: JsonField, + private val operator: JsonField, + private val value: JsonField>, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("measurement") + @ExcludeMissing + measurement: JsonField = JsonMissing.of(), + @JsonProperty("operator") + @ExcludeMissing + operator: JsonField = JsonMissing.of(), + @JsonProperty("value") + @ExcludeMissing + value: JsonField> = JsonMissing.of(), + ) : this(measurement, operator, value, mutableMapOf()) + + /** + * The name of the column. + * + * @throws OpenlayerInvalidDataException if the JSON field has an unexpected + * type or is unexpectedly missing or null (e.g. if the server responded with + * an unexpected value). + */ + fun measurement(): String = measurement.getRequired("measurement") + + /** + * @throws OpenlayerInvalidDataException if the JSON field has an unexpected + * type or is unexpectedly missing or null (e.g. if the server responded with + * an unexpected value). + */ + fun operator(): Operator = operator.getRequired("operator") + + /** + * @throws OpenlayerInvalidDataException if the JSON field has an unexpected + * type or is unexpectedly missing or null (e.g. if the server responded with + * an unexpected value). + */ + fun value(): List = value.getRequired("value") + + /** + * Returns the raw JSON value of [measurement]. + * + * Unlike [measurement], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("measurement") + @ExcludeMissing + fun _measurement(): JsonField = measurement + + /** + * Returns the raw JSON value of [operator]. + * + * Unlike [operator], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("operator") + @ExcludeMissing + fun _operator(): JsonField = operator + + /** + * 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 + * [SetColumnFilter]. + * + * The following fields are required: + * ```java + * .measurement() + * .operator() + * .value() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [SetColumnFilter]. */ + class Builder internal constructor() { + + private var measurement: JsonField? = null + private var operator: JsonField? = null + private var value: JsonField>? = null + private var additionalProperties: MutableMap = + mutableMapOf() + + @JvmSynthetic + internal fun from(setColumnFilter: SetColumnFilter) = apply { + measurement = setColumnFilter.measurement + operator = setColumnFilter.operator + value = setColumnFilter.value.map { it.toMutableList() } + additionalProperties = + setColumnFilter.additionalProperties.toMutableMap() + } + + /** The name of the column. */ + fun measurement(measurement: String) = + measurement(JsonField.of(measurement)) + + /** + * Sets [Builder.measurement] to an arbitrary JSON value. + * + * You should usually call [Builder.measurement] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun measurement(measurement: JsonField) = apply { + this.measurement = measurement + } + + fun operator(operator: Operator) = operator(JsonField.of(operator)) + + /** + * Sets [Builder.operator] to an arbitrary JSON value. + * + * You should usually call [Builder.operator] with a well-typed [Operator] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun operator(operator: JsonField) = apply { + this.operator = operator + } + + fun value(value: List) = value(JsonField.of(value)) + + /** + * Sets [Builder.value] to an arbitrary JSON value. + * + * You should usually call [Builder.value] with a well-typed `List` + * 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.map { it.toMutableList() } + } + + /** + * Adds a single [Value] to [Builder.value]. + * + * @throws IllegalStateException if the field was previously set to a + * non-list. + */ + fun addValue(value: Value) = apply { + this.value = + (this.value ?: JsonField.of(mutableListOf())).also { + checkKnown("value", it).add(value) + } + } + + /** Alias for calling [addValue] with `Value.ofString(string)`. */ + fun addValue(string: String) = addValue(Value.ofString(string)) + + /** Alias for calling [addValue] with `Value.ofNumber(number)`. */ + fun addValue(number: Double) = addValue(Value.ofNumber(number)) + + 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 [SetColumnFilter]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .measurement() + * .operator() + * .value() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): SetColumnFilter = + SetColumnFilter( + checkRequired("measurement", measurement), + checkRequired("operator", operator), + checkRequired("value", value).map { it.toImmutable() }, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): SetColumnFilter = apply { + if (validated) { + return@apply + } + + measurement() + operator().validate() + value().forEach { it.validate() } + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OpenlayerInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (if (measurement.asKnown().isPresent) 1 else 0) + + (operator.asKnown().getOrNull()?.validity() ?: 0) + + (value.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + + class Operator + @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 CONTAINS_NONE = of("contains_none") + + @JvmField val CONTAINS_ANY = of("contains_any") + + @JvmField val CONTAINS_ALL = of("contains_all") + + @JvmField val ONE_OF = of("one_of") + + @JvmField val NONE_OF = of("none_of") + + @JvmStatic fun of(value: String) = Operator(JsonField.of(value)) + } + + /** An enum containing [Operator]'s known values. */ + enum class Known { + CONTAINS_NONE, + CONTAINS_ANY, + CONTAINS_ALL, + ONE_OF, + NONE_OF, + } + + /** + * An enum containing [Operator]'s known values, as well as an [_UNKNOWN] + * member. + * + * An instance of [Operator] 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 { + CONTAINS_NONE, + CONTAINS_ANY, + CONTAINS_ALL, + ONE_OF, + NONE_OF, + /** + * An enum member indicating that [Operator] 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) { + CONTAINS_NONE -> Value.CONTAINS_NONE + CONTAINS_ANY -> Value.CONTAINS_ANY + CONTAINS_ALL -> Value.CONTAINS_ALL + ONE_OF -> Value.ONE_OF + NONE_OF -> Value.NONE_OF + 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 OpenlayerInvalidDataException if this class instance's value is a + * not a known member. + */ + fun known(): Known = + when (this) { + CONTAINS_NONE -> Known.CONTAINS_NONE + CONTAINS_ANY -> Known.CONTAINS_ANY + CONTAINS_ALL -> Known.CONTAINS_ALL + ONE_OF -> Known.ONE_OF + NONE_OF -> Known.NONE_OF + else -> + throw OpenlayerInvalidDataException("Unknown Operator: $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 OpenlayerInvalidDataException if this class instance's value does + * not have the expected primitive type. + */ + fun asString(): String = + _value().asString().orElseThrow { + OpenlayerInvalidDataException("Value is not a String") + } + + private var validated: Boolean = false + + fun validate(): Operator = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OpenlayerInvalidDataException) { + false + } + + /** + * Returns a 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 Operator && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + @JsonDeserialize(using = Value.Deserializer::class) + @JsonSerialize(using = Value.Serializer::class) + class Value + private constructor( + private val string: String? = null, + private val number: Double? = null, + private val _json: JsonValue? = null, + ) { + + fun string(): Optional = Optional.ofNullable(string) + + fun number(): Optional = Optional.ofNullable(number) + + fun isString(): Boolean = string != null + + fun isNumber(): Boolean = number != null + + fun asString(): String = string.getOrThrow("string") + + fun asNumber(): Double = number.getOrThrow("number") + + fun _json(): Optional = Optional.ofNullable(_json) + + fun accept(visitor: Visitor): T = + when { + string != null -> visitor.visitString(string) + number != null -> visitor.visitNumber(number) + else -> visitor.unknown(_json) + } + + private var validated: Boolean = false + + fun validate(): Value = apply { + if (validated) { + return@apply + } + + accept( + object : Visitor { + override fun visitString(string: String) {} + + override fun visitNumber(number: Double) {} + } + ) + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OpenlayerInvalidDataException) { + false + } + + /** + * Returns 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 visitString(string: String) = 1 + + override fun visitNumber(number: Double) = 1 + + override fun unknown(json: JsonValue?) = 0 + } + ) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Value && + string == other.string && + number == other.number + } + + override fun hashCode(): Int = Objects.hash(string, number) + + override fun toString(): String = + when { + string != null -> "Value{string=$string}" + number != null -> "Value{number=$number}" + _json != null -> "Value{_unknown=$_json}" + else -> throw IllegalStateException("Invalid Value") + } + + companion object { + + @JvmStatic fun ofString(string: String) = Value(string = string) + + @JvmStatic fun ofNumber(number: Double) = Value(number = number) + } + + /** + * An interface that defines how to map each variant of [Value] to a value + * of type [T]. + */ + interface Visitor { + + fun visitString(string: String): T + + fun visitNumber(number: Double): T + + /** + * Maps an unknown variant of [Value] to a value of type [T]. + * + * An instance of [Value] 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 OpenlayerInvalidDataException in the default implementation. + */ + fun unknown(json: JsonValue?): T { + throw OpenlayerInvalidDataException("Unknown Value: $json") + } + } + + internal class Deserializer : BaseDeserializer(Value::class) { + + override fun ObjectCodec.deserialize(node: JsonNode): Value { + val json = JsonValue.fromJsonNode(node) + + val bestMatches = + sequenceOf( + tryDeserialize(node, jacksonTypeRef())?.let { + Value(string = it, _json = json) + }, + tryDeserialize(node, jacksonTypeRef())?.let { + Value(number = it, _json = json) + }, + ) + .filterNotNull() + .allMaxBy { it.validity() } + .toList() + return when (bestMatches.size) { + // This can happen if what we're deserializing is completely + // incompatible with all the possible variants (e.g. + // deserializing from object). + 0 -> Value(_json = json) + 1 -> bestMatches.single() + // If there's more than one match with the highest validity, + // then use the first completely valid match, or simply the + // first match if none are completely valid. + else -> + bestMatches.firstOrNull { it.isValid() } + ?: bestMatches.first() + } + } + } + + internal class Serializer : BaseSerializer(Value::class) { + + override fun serialize( + value: Value, + generator: JsonGenerator, + provider: SerializerProvider, + ) { + when { + value.string != null -> generator.writeObject(value.string) + value.number != null -> generator.writeObject(value.number) + value._json != null -> generator.writeObject(value._json) + else -> throw IllegalStateException("Invalid Value") + } + } + } + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is SetColumnFilter && + measurement == other.measurement && + operator == other.operator && + value == other.value && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(measurement, operator, value, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "SetColumnFilter{measurement=$measurement, operator=$operator, value=$value, additionalProperties=$additionalProperties}" + } + + class NumericColumnFilter + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val measurement: JsonField, + private val operator: JsonField, + private val value: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("measurement") + @ExcludeMissing + measurement: JsonField = JsonMissing.of(), + @JsonProperty("operator") + @ExcludeMissing + operator: JsonField = JsonMissing.of(), + @JsonProperty("value") + @ExcludeMissing + value: JsonField = JsonMissing.of(), + ) : this(measurement, operator, value, mutableMapOf()) + + /** + * The name of the column. + * + * @throws OpenlayerInvalidDataException if the JSON field has an unexpected + * type or is unexpectedly missing or null (e.g. if the server responded with + * an unexpected value). + */ + fun measurement(): String = measurement.getRequired("measurement") + + /** + * @throws OpenlayerInvalidDataException if the JSON field has an unexpected + * type or is unexpectedly missing or null (e.g. if the server responded with + * an unexpected value). + */ + fun operator(): Operator = operator.getRequired("operator") + + /** + * @throws OpenlayerInvalidDataException 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 [measurement]. + * + * Unlike [measurement], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("measurement") + @ExcludeMissing + fun _measurement(): JsonField = measurement + + /** + * Returns the raw JSON value of [operator]. + * + * Unlike [operator], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("operator") + @ExcludeMissing + fun _operator(): JsonField = operator + + /** + * 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 + * [NumericColumnFilter]. + * + * The following fields are required: + * ```java + * .measurement() + * .operator() + * .value() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [NumericColumnFilter]. */ + class Builder internal constructor() { + + private var measurement: JsonField? = null + private var operator: JsonField? = null + private var value: JsonField? = null + private var additionalProperties: MutableMap = + mutableMapOf() + + @JvmSynthetic + internal fun from(numericColumnFilter: NumericColumnFilter) = apply { + measurement = numericColumnFilter.measurement + operator = numericColumnFilter.operator + value = numericColumnFilter.value + additionalProperties = + numericColumnFilter.additionalProperties.toMutableMap() + } + + /** The name of the column. */ + fun measurement(measurement: String) = + measurement(JsonField.of(measurement)) + + /** + * Sets [Builder.measurement] to an arbitrary JSON value. + * + * You should usually call [Builder.measurement] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun measurement(measurement: JsonField) = apply { + this.measurement = measurement + } + + fun operator(operator: Operator) = operator(JsonField.of(operator)) + + /** + * Sets [Builder.operator] to an arbitrary JSON value. + * + * You should usually call [Builder.operator] with a well-typed [Operator] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun operator(operator: JsonField) = apply { + this.operator = operator + } + + fun value(value: Float?) = value(JsonField.ofNullable(value)) + + /** + * Alias for [Builder.value]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun value(value: Float) = value(value as Float?) + + /** Alias for calling [Builder.value] with `value.orElse(null)`. */ + fun value(value: Optional) = value(value.getOrNull()) + + /** + * Sets [Builder.value] to an arbitrary JSON value. + * + * You should usually call [Builder.value] with a well-typed [Float] 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 [NumericColumnFilter]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .measurement() + * .operator() + * .value() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): NumericColumnFilter = + NumericColumnFilter( + checkRequired("measurement", measurement), + checkRequired("operator", operator), + checkRequired("value", value), + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): NumericColumnFilter = apply { + if (validated) { + return@apply + } + + measurement() + operator().validate() + value() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OpenlayerInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (if (measurement.asKnown().isPresent) 1 else 0) + + (operator.asKnown().getOrNull()?.validity() ?: 0) + + (if (value.asKnown().isPresent) 1 else 0) + + class Operator + @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 GREATER = of(">") + + @JvmField val GREATER_OR_EQUALS = of(">=") + + @JvmField val IS = of("is") + + @JvmField val LESS = of("<") + + @JvmField val LESS_OR_EQUALS = of("<=") + + @JvmField val NOT_EQUALS = of("!=") + + @JvmStatic fun of(value: String) = Operator(JsonField.of(value)) + } + + /** An enum containing [Operator]'s known values. */ + enum class Known { + GREATER, + GREATER_OR_EQUALS, + IS, + LESS, + LESS_OR_EQUALS, + NOT_EQUALS, + } + + /** + * An enum containing [Operator]'s known values, as well as an [_UNKNOWN] + * member. + * + * An instance of [Operator] 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 { + GREATER, + GREATER_OR_EQUALS, + IS, + LESS, + LESS_OR_EQUALS, + NOT_EQUALS, + /** + * An enum member indicating that [Operator] 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) { + GREATER -> Value.GREATER + GREATER_OR_EQUALS -> Value.GREATER_OR_EQUALS + IS -> Value.IS + LESS -> Value.LESS + LESS_OR_EQUALS -> Value.LESS_OR_EQUALS + NOT_EQUALS -> Value.NOT_EQUALS + 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 OpenlayerInvalidDataException if this class instance's value is a + * not a known member. + */ + fun known(): Known = + when (this) { + GREATER -> Known.GREATER + GREATER_OR_EQUALS -> Known.GREATER_OR_EQUALS + IS -> Known.IS + LESS -> Known.LESS + LESS_OR_EQUALS -> Known.LESS_OR_EQUALS + NOT_EQUALS -> Known.NOT_EQUALS + else -> + throw OpenlayerInvalidDataException("Unknown Operator: $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 OpenlayerInvalidDataException if this class instance's value does + * not have the expected primitive type. + */ + fun asString(): String = + _value().asString().orElseThrow { + OpenlayerInvalidDataException("Value is not a String") + } + + private var validated: Boolean = false + + fun validate(): Operator = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OpenlayerInvalidDataException) { + false + } + + /** + * Returns a 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 Operator && 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 NumericColumnFilter && + measurement == other.measurement && + operator == other.operator && + value == other.value && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(measurement, operator, value, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "NumericColumnFilter{measurement=$measurement, operator=$operator, value=$value, additionalProperties=$additionalProperties}" + } + + class StringColumnFilter + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val measurement: JsonField, + private val operator: JsonField, + private val value: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("measurement") + @ExcludeMissing + measurement: JsonField = JsonMissing.of(), + @JsonProperty("operator") + @ExcludeMissing + operator: JsonField = JsonMissing.of(), + @JsonProperty("value") + @ExcludeMissing + value: JsonField = JsonMissing.of(), + ) : this(measurement, operator, value, mutableMapOf()) + + /** + * The name of the column. + * + * @throws OpenlayerInvalidDataException if the JSON field has an unexpected + * type or is unexpectedly missing or null (e.g. if the server responded with + * an unexpected value). + */ + fun measurement(): String = measurement.getRequired("measurement") + + /** + * @throws OpenlayerInvalidDataException if the JSON field has an unexpected + * type or is unexpectedly missing or null (e.g. if the server responded with + * an unexpected value). + */ + fun operator(): Operator = operator.getRequired("operator") + + /** + * @throws OpenlayerInvalidDataException if the JSON field has an unexpected + * type or is unexpectedly missing or null (e.g. if the server responded with + * an unexpected value). + */ + fun value(): Value = value.getRequired("value") + + /** + * Returns the raw JSON value of [measurement]. + * + * Unlike [measurement], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("measurement") + @ExcludeMissing + fun _measurement(): JsonField = measurement + + /** + * Returns the raw JSON value of [operator]. + * + * Unlike [operator], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("operator") + @ExcludeMissing + fun _operator(): JsonField = operator + + /** + * 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 + * [StringColumnFilter]. + * + * The following fields are required: + * ```java + * .measurement() + * .operator() + * .value() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [StringColumnFilter]. */ + class Builder internal constructor() { + + private var measurement: JsonField? = null + private var operator: JsonField? = null + private var value: JsonField? = null + private var additionalProperties: MutableMap = + mutableMapOf() + + @JvmSynthetic + internal fun from(stringColumnFilter: StringColumnFilter) = apply { + measurement = stringColumnFilter.measurement + operator = stringColumnFilter.operator + value = stringColumnFilter.value + additionalProperties = + stringColumnFilter.additionalProperties.toMutableMap() + } + + /** The name of the column. */ + fun measurement(measurement: String) = + measurement(JsonField.of(measurement)) + + /** + * Sets [Builder.measurement] to an arbitrary JSON value. + * + * You should usually call [Builder.measurement] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun measurement(measurement: JsonField) = apply { + this.measurement = measurement + } + + fun operator(operator: Operator) = operator(JsonField.of(operator)) + + /** + * Sets [Builder.operator] to an arbitrary JSON value. + * + * You should usually call [Builder.operator] with a well-typed [Operator] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun operator(operator: JsonField) = apply { + this.operator = operator + } + + fun value(value: Value) = value(JsonField.of(value)) + + /** + * Sets [Builder.value] to an arbitrary JSON value. + * + * You should usually call [Builder.value] with a well-typed [Value] 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 } + + /** Alias for calling [value] with `Value.ofString(string)`. */ + fun value(string: String) = value(Value.ofString(string)) + + /** Alias for calling [value] with `Value.ofBool(bool)`. */ + fun value(bool: Boolean) = value(Value.ofBool(bool)) + + 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 [StringColumnFilter]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .measurement() + * .operator() + * .value() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): StringColumnFilter = + StringColumnFilter( + checkRequired("measurement", measurement), + checkRequired("operator", operator), + checkRequired("value", value), + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): StringColumnFilter = apply { + if (validated) { + return@apply + } + + measurement() + operator().validate() + value().validate() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OpenlayerInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (if (measurement.asKnown().isPresent) 1 else 0) + + (operator.asKnown().getOrNull()?.validity() ?: 0) + + (value.asKnown().getOrNull()?.validity() ?: 0) + + class Operator + @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 IS = of("is") + + @JvmField val NOT_EQUALS = of("!=") + + @JvmStatic fun of(value: String) = Operator(JsonField.of(value)) + } + + /** An enum containing [Operator]'s known values. */ + enum class Known { + IS, + NOT_EQUALS, + } + + /** + * An enum containing [Operator]'s known values, as well as an [_UNKNOWN] + * member. + * + * An instance of [Operator] 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 { + IS, + NOT_EQUALS, + /** + * An enum member indicating that [Operator] 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) { + IS -> Value.IS + NOT_EQUALS -> Value.NOT_EQUALS + 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 OpenlayerInvalidDataException if this class instance's value is a + * not a known member. + */ + fun known(): Known = + when (this) { + IS -> Known.IS + NOT_EQUALS -> Known.NOT_EQUALS + else -> + throw OpenlayerInvalidDataException("Unknown Operator: $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 OpenlayerInvalidDataException if this class instance's value does + * not have the expected primitive type. + */ + fun asString(): String = + _value().asString().orElseThrow { + OpenlayerInvalidDataException("Value is not a String") + } + + private var validated: Boolean = false + + fun validate(): Operator = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OpenlayerInvalidDataException) { + false + } + + /** + * Returns a 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 Operator && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + @JsonDeserialize(using = Value.Deserializer::class) + @JsonSerialize(using = Value.Serializer::class) + class Value + private constructor( + private val string: String? = null, + private val bool: Boolean? = null, + private val _json: JsonValue? = null, + ) { + + fun string(): Optional = Optional.ofNullable(string) + + fun bool(): Optional = Optional.ofNullable(bool) + + fun isString(): Boolean = string != null + + fun isBool(): Boolean = bool != null + + fun asString(): String = string.getOrThrow("string") + + fun asBool(): Boolean = bool.getOrThrow("bool") + + fun _json(): Optional = Optional.ofNullable(_json) + + fun accept(visitor: Visitor): T = + when { + string != null -> visitor.visitString(string) + bool != null -> visitor.visitBool(bool) + else -> visitor.unknown(_json) + } + + private var validated: Boolean = false + + fun validate(): Value = apply { + if (validated) { + return@apply + } + + accept( + object : Visitor { + override fun visitString(string: String) {} + + override fun visitBool(bool: Boolean) {} + } + ) + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OpenlayerInvalidDataException) { + false + } + + /** + * Returns 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 visitString(string: String) = 1 + + override fun visitBool(bool: Boolean) = 1 + + override fun unknown(json: JsonValue?) = 0 + } + ) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Value && string == other.string && bool == other.bool + } + + override fun hashCode(): Int = Objects.hash(string, bool) + + override fun toString(): String = + when { + string != null -> "Value{string=$string}" + bool != null -> "Value{bool=$bool}" + _json != null -> "Value{_unknown=$_json}" + else -> throw IllegalStateException("Invalid Value") + } + + companion object { + + @JvmStatic fun ofString(string: String) = Value(string = string) + + @JvmStatic fun ofBool(bool: Boolean) = Value(bool = bool) + } + + /** + * An interface that defines how to map each variant of [Value] to a value + * of type [T]. + */ + interface Visitor { + + fun visitString(string: String): T + + fun visitBool(bool: Boolean): T + + /** + * Maps an unknown variant of [Value] to a value of type [T]. + * + * An instance of [Value] 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 OpenlayerInvalidDataException in the default implementation. + */ + fun unknown(json: JsonValue?): T { + throw OpenlayerInvalidDataException("Unknown Value: $json") + } + } + + internal class Deserializer : BaseDeserializer(Value::class) { + + override fun ObjectCodec.deserialize(node: JsonNode): Value { + val json = JsonValue.fromJsonNode(node) + + val bestMatches = + sequenceOf( + tryDeserialize(node, jacksonTypeRef())?.let { + Value(string = it, _json = json) + }, + tryDeserialize(node, jacksonTypeRef())?.let { + Value(bool = it, _json = json) + }, + ) + .filterNotNull() + .allMaxBy { it.validity() } + .toList() + return when (bestMatches.size) { + // This can happen if what we're deserializing is completely + // incompatible with all the possible variants (e.g. + // deserializing from object). + 0 -> Value(_json = json) + 1 -> bestMatches.single() + // If there's more than one match with the highest validity, + // then use the first completely valid match, or simply the + // first match if none are completely valid. + else -> + bestMatches.firstOrNull { it.isValid() } + ?: bestMatches.first() + } + } + } + + internal class Serializer : BaseSerializer(Value::class) { + + override fun serialize( + value: Value, + generator: JsonGenerator, + provider: SerializerProvider, + ) { + when { + value.string != null -> generator.writeObject(value.string) + value.bool != null -> generator.writeObject(value.bool) + value._json != null -> generator.writeObject(value._json) + else -> throw IllegalStateException("Invalid Value") + } + } + } + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is StringColumnFilter && + measurement == other.measurement && + operator == other.operator && + value == other.value && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(measurement, operator, value, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "StringColumnFilter{measurement=$measurement, operator=$operator, value=$value, additionalProperties=$additionalProperties}" + } + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is RowsBody && + columnFilters == other.columnFilters && + excludeRowIdList == other.excludeRowIdList && + notSearchQueryAnd == other.notSearchQueryAnd && + notSearchQueryOr == other.notSearchQueryOr && + rowIdList == other.rowIdList && + searchQueryAnd == other.searchQueryAnd && + searchQueryOr == other.searchQueryOr && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + columnFilters, + excludeRowIdList, + notSearchQueryAnd, + notSearchQueryOr, + rowIdList, + searchQueryAnd, + searchQueryOr, + additionalProperties, + ) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "RowsBody{columnFilters=$columnFilters, excludeRowIdList=$excludeRowIdList, notSearchQueryAnd=$notSearchQueryAnd, notSearchQueryOr=$notSearchQueryOr, rowIdList=$rowIdList, searchQueryAnd=$searchQueryAnd, searchQueryOr=$searchQueryOr, additionalProperties=$additionalProperties}" + } + override fun equals(other: Any?): Boolean { if (this === other) { return true @@ -4037,8 +6805,11 @@ private constructor( projectVersionId == other.projectVersionId && status == other.status && statusMessage == other.statusMessage && + expectedValues == other.expectedValues && goal == other.goal && goalId == other.goalId && + rows == other.rows && + rowsBody == other.rowsBody && additionalProperties == other.additionalProperties } @@ -4053,8 +6824,11 @@ private constructor( projectVersionId, status, statusMessage, + expectedValues, goal, goalId, + rows, + rowsBody, additionalProperties, ) } @@ -4062,7 +6836,7 @@ private constructor( override fun hashCode(): Int = hashCode override fun toString() = - "Item{id=$id, dateCreated=$dateCreated, dateDataEnds=$dateDataEnds, dateDataStarts=$dateDataStarts, dateUpdated=$dateUpdated, inferencePipelineId=$inferencePipelineId, projectVersionId=$projectVersionId, status=$status, statusMessage=$statusMessage, goal=$goal, goalId=$goalId, additionalProperties=$additionalProperties}" + "Item{id=$id, dateCreated=$dateCreated, dateDataEnds=$dateDataEnds, dateDataStarts=$dateDataStarts, dateUpdated=$dateUpdated, inferencePipelineId=$inferencePipelineId, projectVersionId=$projectVersionId, status=$status, statusMessage=$statusMessage, expectedValues=$expectedValues, goal=$goal, goalId=$goalId, rows=$rows, rowsBody=$rowsBody, additionalProperties=$additionalProperties}" } override fun equals(other: Any?): Boolean { diff --git a/openlayer-java-core/src/main/kotlin/com/openlayer/api/models/tests/TestListResultsParams.kt b/openlayer-java-core/src/main/kotlin/com/openlayer/api/models/tests/TestListResultsParams.kt new file mode 100644 index 00000000..8c8a860e --- /dev/null +++ b/openlayer-java-core/src/main/kotlin/com/openlayer/api/models/tests/TestListResultsParams.kt @@ -0,0 +1,388 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openlayer.api.models.tests + +import com.openlayer.api.core.Params +import com.openlayer.api.core.http.Headers +import com.openlayer.api.core.http.QueryParams +import com.openlayer.api.core.toImmutable +import java.util.Objects +import java.util.Optional +import kotlin.jvm.optionals.getOrNull + +/** List the test results for a test. */ +class TestListResultsParams +private constructor( + private val testId: String?, + private val endTimestamp: Double?, + private val includeInsights: Boolean?, + private val inferencePipelineId: String?, + private val page: Long?, + private val perPage: Long?, + private val projectVersionId: String?, + private val startTimestamp: Double?, + private val status: List?, + private val additionalHeaders: Headers, + private val additionalQueryParams: QueryParams, +) : Params { + + fun testId(): Optional = Optional.ofNullable(testId) + + /** Filter for results that use data starting before the end timestamp. */ + fun endTimestamp(): Optional = Optional.ofNullable(endTimestamp) + + /** Include the insights linked to each test result */ + fun includeInsights(): Optional = Optional.ofNullable(includeInsights) + + /** Retrive test results for a specific inference pipeline. */ + fun inferencePipelineId(): Optional = Optional.ofNullable(inferencePipelineId) + + /** The page to return in a paginated query. */ + fun page(): Optional = Optional.ofNullable(page) + + /** Maximum number of items to return per page. */ + fun perPage(): Optional = Optional.ofNullable(perPage) + + /** Retrive test results for a specific project version. */ + fun projectVersionId(): Optional = Optional.ofNullable(projectVersionId) + + /** Filter for results that use data ending after the start timestamp. */ + fun startTimestamp(): Optional = Optional.ofNullable(startTimestamp) + + /** Filter by status(es). */ + fun status(): Optional> = Optional.ofNullable(status) + + /** 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(): TestListResultsParams = builder().build() + + /** Returns a mutable builder for constructing an instance of [TestListResultsParams]. */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [TestListResultsParams]. */ + class Builder internal constructor() { + + private var testId: String? = null + private var endTimestamp: Double? = null + private var includeInsights: Boolean? = null + private var inferencePipelineId: String? = null + private var page: Long? = null + private var perPage: Long? = null + private var projectVersionId: String? = null + private var startTimestamp: Double? = null + private var status: MutableList? = null + private var additionalHeaders: Headers.Builder = Headers.builder() + private var additionalQueryParams: QueryParams.Builder = QueryParams.builder() + + @JvmSynthetic + internal fun from(testListResultsParams: TestListResultsParams) = apply { + testId = testListResultsParams.testId + endTimestamp = testListResultsParams.endTimestamp + includeInsights = testListResultsParams.includeInsights + inferencePipelineId = testListResultsParams.inferencePipelineId + page = testListResultsParams.page + perPage = testListResultsParams.perPage + projectVersionId = testListResultsParams.projectVersionId + startTimestamp = testListResultsParams.startTimestamp + status = testListResultsParams.status?.toMutableList() + additionalHeaders = testListResultsParams.additionalHeaders.toBuilder() + additionalQueryParams = testListResultsParams.additionalQueryParams.toBuilder() + } + + fun testId(testId: String?) = apply { this.testId = testId } + + /** Alias for calling [Builder.testId] with `testId.orElse(null)`. */ + fun testId(testId: Optional) = testId(testId.getOrNull()) + + /** Filter for results that use data starting before the end timestamp. */ + fun endTimestamp(endTimestamp: Double?) = apply { this.endTimestamp = endTimestamp } + + /** + * Alias for [Builder.endTimestamp]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun endTimestamp(endTimestamp: Double) = endTimestamp(endTimestamp as Double?) + + /** Alias for calling [Builder.endTimestamp] with `endTimestamp.orElse(null)`. */ + fun endTimestamp(endTimestamp: Optional) = endTimestamp(endTimestamp.getOrNull()) + + /** Include the insights linked to each test result */ + fun includeInsights(includeInsights: Boolean?) = apply { + this.includeInsights = includeInsights + } + + /** + * Alias for [Builder.includeInsights]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun includeInsights(includeInsights: Boolean) = includeInsights(includeInsights as Boolean?) + + /** Alias for calling [Builder.includeInsights] with `includeInsights.orElse(null)`. */ + fun includeInsights(includeInsights: Optional) = + includeInsights(includeInsights.getOrNull()) + + /** Retrive test results for a specific inference pipeline. */ + fun inferencePipelineId(inferencePipelineId: String?) = apply { + this.inferencePipelineId = inferencePipelineId + } + + /** + * Alias for calling [Builder.inferencePipelineId] with `inferencePipelineId.orElse(null)`. + */ + fun inferencePipelineId(inferencePipelineId: Optional) = + inferencePipelineId(inferencePipelineId.getOrNull()) + + /** The page to return in a paginated query. */ + fun page(page: Long?) = apply { this.page = page } + + /** + * Alias for [Builder.page]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun page(page: Long) = page(page as Long?) + + /** Alias for calling [Builder.page] with `page.orElse(null)`. */ + fun page(page: Optional) = page(page.getOrNull()) + + /** Maximum number of items to return per page. */ + fun perPage(perPage: Long?) = apply { this.perPage = perPage } + + /** + * Alias for [Builder.perPage]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun perPage(perPage: Long) = perPage(perPage as Long?) + + /** Alias for calling [Builder.perPage] with `perPage.orElse(null)`. */ + fun perPage(perPage: Optional) = perPage(perPage.getOrNull()) + + /** Retrive test results for a specific project version. */ + fun projectVersionId(projectVersionId: String?) = apply { + this.projectVersionId = projectVersionId + } + + /** Alias for calling [Builder.projectVersionId] with `projectVersionId.orElse(null)`. */ + fun projectVersionId(projectVersionId: Optional) = + projectVersionId(projectVersionId.getOrNull()) + + /** Filter for results that use data ending after the start timestamp. */ + fun startTimestamp(startTimestamp: Double?) = apply { this.startTimestamp = startTimestamp } + + /** + * Alias for [Builder.startTimestamp]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun startTimestamp(startTimestamp: Double) = startTimestamp(startTimestamp as Double?) + + /** Alias for calling [Builder.startTimestamp] with `startTimestamp.orElse(null)`. */ + fun startTimestamp(startTimestamp: Optional) = + startTimestamp(startTimestamp.getOrNull()) + + /** Filter by status(es). */ + fun status(status: List?) = apply { this.status = status?.toMutableList() } + + /** Alias for calling [Builder.status] with `status.orElse(null)`. */ + fun status(status: Optional>) = status(status.getOrNull()) + + /** + * Adds a single [String] to [Builder.status]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addStatus(status: String) = apply { + this.status = (this.status ?: mutableListOf()).apply { add(status) } + } + + 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 [TestListResultsParams]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): TestListResultsParams = + TestListResultsParams( + testId, + endTimestamp, + includeInsights, + inferencePipelineId, + page, + perPage, + projectVersionId, + startTimestamp, + status?.toImmutable(), + additionalHeaders.build(), + additionalQueryParams.build(), + ) + } + + fun _pathParam(index: Int): String = + when (index) { + 0 -> testId ?: "" + else -> "" + } + + override fun _headers(): Headers = additionalHeaders + + override fun _queryParams(): QueryParams = + QueryParams.builder() + .apply { + endTimestamp?.let { put("endTimestamp", it.toString()) } + includeInsights?.let { put("includeInsights", it.toString()) } + inferencePipelineId?.let { put("inferencePipelineId", it) } + page?.let { put("page", it.toString()) } + perPage?.let { put("perPage", it.toString()) } + projectVersionId?.let { put("projectVersionId", it) } + startTimestamp?.let { put("startTimestamp", it.toString()) } + status?.let { put("status", it.joinToString(",")) } + putAll(additionalQueryParams) + } + .build() + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is TestListResultsParams && + testId == other.testId && + endTimestamp == other.endTimestamp && + includeInsights == other.includeInsights && + inferencePipelineId == other.inferencePipelineId && + page == other.page && + perPage == other.perPage && + projectVersionId == other.projectVersionId && + startTimestamp == other.startTimestamp && + status == other.status && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams + } + + override fun hashCode(): Int = + Objects.hash( + testId, + endTimestamp, + includeInsights, + inferencePipelineId, + page, + perPage, + projectVersionId, + startTimestamp, + status, + additionalHeaders, + additionalQueryParams, + ) + + override fun toString() = + "TestListResultsParams{testId=$testId, endTimestamp=$endTimestamp, includeInsights=$includeInsights, inferencePipelineId=$inferencePipelineId, page=$page, perPage=$perPage, projectVersionId=$projectVersionId, startTimestamp=$startTimestamp, status=$status, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" +} diff --git a/openlayer-java-core/src/main/kotlin/com/openlayer/api/models/tests/TestListResultsResponse.kt b/openlayer-java-core/src/main/kotlin/com/openlayer/api/models/tests/TestListResultsResponse.kt new file mode 100644 index 00000000..fdebbdcc --- /dev/null +++ b/openlayer-java-core/src/main/kotlin/com/openlayer/api/models/tests/TestListResultsResponse.kt @@ -0,0 +1,13563 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openlayer.api.models.tests + +import 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.openlayer.api.core.BaseDeserializer +import com.openlayer.api.core.BaseSerializer +import com.openlayer.api.core.Enum +import com.openlayer.api.core.ExcludeMissing +import com.openlayer.api.core.JsonField +import com.openlayer.api.core.JsonMissing +import com.openlayer.api.core.JsonValue +import com.openlayer.api.core.allMaxBy +import com.openlayer.api.core.checkKnown +import com.openlayer.api.core.checkRequired +import com.openlayer.api.core.getOrThrow +import com.openlayer.api.core.toImmutable +import com.openlayer.api.errors.OpenlayerInvalidDataException +import java.time.OffsetDateTime +import java.util.Collections +import java.util.Objects +import java.util.Optional +import kotlin.jvm.optionals.getOrNull + +class TestListResultsResponse +@JsonCreator(mode = JsonCreator.Mode.DISABLED) +private constructor( + private val items: JsonField>, + private val lastUnskippedResult: JsonField, + private val additionalProperties: MutableMap, +) { + + @JsonCreator + private constructor( + @JsonProperty("items") @ExcludeMissing items: JsonField> = JsonMissing.of(), + @JsonProperty("lastUnskippedResult") + @ExcludeMissing + lastUnskippedResult: JsonField = JsonMissing.of(), + ) : this(items, lastUnskippedResult, mutableMapOf()) + + /** + * @throws OpenlayerInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun items(): List = items.getRequired("items") + + /** + * @throws OpenlayerInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun lastUnskippedResult(): Optional = + lastUnskippedResult.getOptional("lastUnskippedResult") + + /** + * Returns the raw JSON value of [items]. + * + * Unlike [items], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("items") @ExcludeMissing fun _items(): JsonField> = items + + /** + * Returns the raw JSON value of [lastUnskippedResult]. + * + * Unlike [lastUnskippedResult], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("lastUnskippedResult") + @ExcludeMissing + fun _lastUnskippedResult(): JsonField = lastUnskippedResult + + @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 [TestListResultsResponse]. + * + * The following fields are required: + * ```java + * .items() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [TestListResultsResponse]. */ + class Builder internal constructor() { + + private var items: JsonField>? = null + private var lastUnskippedResult: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(testListResultsResponse: TestListResultsResponse) = apply { + items = testListResultsResponse.items.map { it.toMutableList() } + lastUnskippedResult = testListResultsResponse.lastUnskippedResult + additionalProperties = testListResultsResponse.additionalProperties.toMutableMap() + } + + fun items(items: List) = items(JsonField.of(items)) + + /** + * Sets [Builder.items] to an arbitrary JSON value. + * + * You should usually call [Builder.items] with a well-typed `List` value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun items(items: JsonField>) = apply { + this.items = items.map { it.toMutableList() } + } + + /** + * Adds a single [Item] to [items]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addItem(item: Item) = apply { + items = + (items ?: JsonField.of(mutableListOf())).also { checkKnown("items", it).add(item) } + } + + fun lastUnskippedResult(lastUnskippedResult: LastUnskippedResult?) = + lastUnskippedResult(JsonField.ofNullable(lastUnskippedResult)) + + /** + * Alias for calling [Builder.lastUnskippedResult] with `lastUnskippedResult.orElse(null)`. + */ + fun lastUnskippedResult(lastUnskippedResult: Optional) = + lastUnskippedResult(lastUnskippedResult.getOrNull()) + + /** + * Sets [Builder.lastUnskippedResult] to an arbitrary JSON value. + * + * You should usually call [Builder.lastUnskippedResult] with a well-typed + * [LastUnskippedResult] value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun lastUnskippedResult(lastUnskippedResult: JsonField) = apply { + this.lastUnskippedResult = lastUnskippedResult + } + + 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 [TestListResultsResponse]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .items() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): TestListResultsResponse = + TestListResultsResponse( + checkRequired("items", items).map { it.toImmutable() }, + lastUnskippedResult, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): TestListResultsResponse = apply { + if (validated) { + return@apply + } + + items().forEach { it.validate() } + lastUnskippedResult().ifPresent { it.validate() } + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OpenlayerInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (items.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + + (lastUnskippedResult.asKnown().getOrNull()?.validity() ?: 0) + + class Item + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val id: JsonField, + private val dateCreated: JsonField, + private val dateDataEnds: JsonField, + private val dateDataStarts: JsonField, + private val dateUpdated: JsonField, + private val inferencePipelineId: JsonField, + private val projectVersionId: JsonField, + private val status: JsonField, + private val statusMessage: JsonField, + private val expectedValues: JsonField>, + private val goal: JsonField, + private val goalId: JsonField, + private val rows: JsonField, + private val rowsBody: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("id") @ExcludeMissing id: JsonField = JsonMissing.of(), + @JsonProperty("dateCreated") + @ExcludeMissing + dateCreated: JsonField = JsonMissing.of(), + @JsonProperty("dateDataEnds") + @ExcludeMissing + dateDataEnds: JsonField = JsonMissing.of(), + @JsonProperty("dateDataStarts") + @ExcludeMissing + dateDataStarts: JsonField = JsonMissing.of(), + @JsonProperty("dateUpdated") + @ExcludeMissing + dateUpdated: JsonField = JsonMissing.of(), + @JsonProperty("inferencePipelineId") + @ExcludeMissing + inferencePipelineId: JsonField = JsonMissing.of(), + @JsonProperty("projectVersionId") + @ExcludeMissing + projectVersionId: JsonField = JsonMissing.of(), + @JsonProperty("status") @ExcludeMissing status: JsonField = JsonMissing.of(), + @JsonProperty("statusMessage") + @ExcludeMissing + statusMessage: JsonField = JsonMissing.of(), + @JsonProperty("expectedValues") + @ExcludeMissing + expectedValues: JsonField> = JsonMissing.of(), + @JsonProperty("goal") @ExcludeMissing goal: JsonField = JsonMissing.of(), + @JsonProperty("goalId") @ExcludeMissing goalId: JsonField = JsonMissing.of(), + @JsonProperty("rows") @ExcludeMissing rows: JsonField = JsonMissing.of(), + @JsonProperty("rowsBody") + @ExcludeMissing + rowsBody: JsonField = JsonMissing.of(), + ) : this( + id, + dateCreated, + dateDataEnds, + dateDataStarts, + dateUpdated, + inferencePipelineId, + projectVersionId, + status, + statusMessage, + expectedValues, + goal, + goalId, + rows, + rowsBody, + mutableMapOf(), + ) + + /** + * Project version (commit) id. + * + * @throws OpenlayerInvalidDataException if 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 creation date. + * + * @throws OpenlayerInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun dateCreated(): OffsetDateTime = dateCreated.getRequired("dateCreated") + + /** + * The data end date. + * + * @throws OpenlayerInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun dateDataEnds(): Optional = dateDataEnds.getOptional("dateDataEnds") + + /** + * The data start date. + * + * @throws OpenlayerInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun dateDataStarts(): Optional = + dateDataStarts.getOptional("dateDataStarts") + + /** + * The last updated date. + * + * @throws OpenlayerInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun dateUpdated(): OffsetDateTime = dateUpdated.getRequired("dateUpdated") + + /** + * The inference pipeline id. + * + * @throws OpenlayerInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun inferencePipelineId(): Optional = + inferencePipelineId.getOptional("inferencePipelineId") + + /** + * The project version (commit) id. + * + * @throws OpenlayerInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun projectVersionId(): Optional = projectVersionId.getOptional("projectVersionId") + + /** + * The status of the test. + * + * @throws OpenlayerInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun status(): Status = status.getRequired("status") + + /** + * The status message. + * + * @throws OpenlayerInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun statusMessage(): Optional = statusMessage.getOptional("statusMessage") + + /** + * @throws OpenlayerInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun expectedValues(): Optional> = + expectedValues.getOptional("expectedValues") + + /** + * @throws OpenlayerInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun goal(): Optional = goal.getOptional("goal") + + /** + * The test id. + * + * @throws OpenlayerInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun goalId(): Optional = goalId.getOptional("goalId") + + /** + * The URL to the rows of the test result. + * + * @throws OpenlayerInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun rows(): Optional = rows.getOptional("rows") + + /** + * The body of the rows request. + * + * @throws OpenlayerInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun rowsBody(): Optional = rowsBody.getOptional("rowsBody") + + /** + * 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 [dateCreated]. + * + * Unlike [dateCreated], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("dateCreated") + @ExcludeMissing + fun _dateCreated(): JsonField = dateCreated + + /** + * Returns the raw JSON value of [dateDataEnds]. + * + * Unlike [dateDataEnds], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("dateDataEnds") + @ExcludeMissing + fun _dateDataEnds(): JsonField = dateDataEnds + + /** + * Returns the raw JSON value of [dateDataStarts]. + * + * Unlike [dateDataStarts], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("dateDataStarts") + @ExcludeMissing + fun _dateDataStarts(): JsonField = dateDataStarts + + /** + * Returns the raw JSON value of [dateUpdated]. + * + * Unlike [dateUpdated], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("dateUpdated") + @ExcludeMissing + fun _dateUpdated(): JsonField = dateUpdated + + /** + * Returns the raw JSON value of [inferencePipelineId]. + * + * Unlike [inferencePipelineId], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("inferencePipelineId") + @ExcludeMissing + fun _inferencePipelineId(): JsonField = inferencePipelineId + + /** + * Returns the raw JSON value of [projectVersionId]. + * + * Unlike [projectVersionId], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("projectVersionId") + @ExcludeMissing + fun _projectVersionId(): JsonField = projectVersionId + + /** + * Returns the raw JSON value of [status]. + * + * Unlike [status], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("status") @ExcludeMissing fun _status(): JsonField = status + + /** + * Returns the raw JSON value of [statusMessage]. + * + * Unlike [statusMessage], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("statusMessage") + @ExcludeMissing + fun _statusMessage(): JsonField = statusMessage + + /** + * Returns the raw JSON value of [expectedValues]. + * + * Unlike [expectedValues], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("expectedValues") + @ExcludeMissing + fun _expectedValues(): JsonField> = expectedValues + + /** + * Returns the raw JSON value of [goal]. + * + * Unlike [goal], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("goal") @ExcludeMissing fun _goal(): JsonField = goal + + /** + * Returns the raw JSON value of [goalId]. + * + * Unlike [goalId], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("goalId") @ExcludeMissing fun _goalId(): JsonField = goalId + + /** + * Returns the raw JSON value of [rows]. + * + * Unlike [rows], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("rows") @ExcludeMissing fun _rows(): JsonField = rows + + /** + * Returns the raw JSON value of [rowsBody]. + * + * Unlike [rowsBody], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("rowsBody") @ExcludeMissing fun _rowsBody(): JsonField = rowsBody + + @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 [Item]. + * + * The following fields are required: + * ```java + * .id() + * .dateCreated() + * .dateDataEnds() + * .dateDataStarts() + * .dateUpdated() + * .inferencePipelineId() + * .projectVersionId() + * .status() + * .statusMessage() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [Item]. */ + class Builder internal constructor() { + + private var id: JsonField? = null + private var dateCreated: JsonField? = null + private var dateDataEnds: JsonField? = null + private var dateDataStarts: JsonField? = null + private var dateUpdated: JsonField? = null + private var inferencePipelineId: JsonField? = null + private var projectVersionId: JsonField? = null + private var status: JsonField? = null + private var statusMessage: JsonField? = null + private var expectedValues: JsonField>? = null + private var goal: JsonField = JsonMissing.of() + private var goalId: JsonField = JsonMissing.of() + private var rows: JsonField = JsonMissing.of() + private var rowsBody: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(item: Item) = apply { + id = item.id + dateCreated = item.dateCreated + dateDataEnds = item.dateDataEnds + dateDataStarts = item.dateDataStarts + dateUpdated = item.dateUpdated + inferencePipelineId = item.inferencePipelineId + projectVersionId = item.projectVersionId + status = item.status + statusMessage = item.statusMessage + expectedValues = item.expectedValues.map { it.toMutableList() } + goal = item.goal + goalId = item.goalId + rows = item.rows + rowsBody = item.rowsBody + additionalProperties = item.additionalProperties.toMutableMap() + } + + /** Project version (commit) 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 } + + /** The creation date. */ + fun dateCreated(dateCreated: OffsetDateTime) = dateCreated(JsonField.of(dateCreated)) + + /** + * Sets [Builder.dateCreated] to an arbitrary JSON value. + * + * You should usually call [Builder.dateCreated] with a well-typed [OffsetDateTime] + * value instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun dateCreated(dateCreated: JsonField) = apply { + this.dateCreated = dateCreated + } + + /** The data end date. */ + fun dateDataEnds(dateDataEnds: OffsetDateTime?) = + dateDataEnds(JsonField.ofNullable(dateDataEnds)) + + /** Alias for calling [Builder.dateDataEnds] with `dateDataEnds.orElse(null)`. */ + fun dateDataEnds(dateDataEnds: Optional) = + dateDataEnds(dateDataEnds.getOrNull()) + + /** + * Sets [Builder.dateDataEnds] to an arbitrary JSON value. + * + * You should usually call [Builder.dateDataEnds] with a well-typed [OffsetDateTime] + * value instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun dateDataEnds(dateDataEnds: JsonField) = apply { + this.dateDataEnds = dateDataEnds + } + + /** The data start date. */ + fun dateDataStarts(dateDataStarts: OffsetDateTime?) = + dateDataStarts(JsonField.ofNullable(dateDataStarts)) + + /** Alias for calling [Builder.dateDataStarts] with `dateDataStarts.orElse(null)`. */ + fun dateDataStarts(dateDataStarts: Optional) = + dateDataStarts(dateDataStarts.getOrNull()) + + /** + * Sets [Builder.dateDataStarts] to an arbitrary JSON value. + * + * You should usually call [Builder.dateDataStarts] with a well-typed [OffsetDateTime] + * value instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun dateDataStarts(dateDataStarts: JsonField) = apply { + this.dateDataStarts = dateDataStarts + } + + /** The last updated date. */ + fun dateUpdated(dateUpdated: OffsetDateTime) = dateUpdated(JsonField.of(dateUpdated)) + + /** + * Sets [Builder.dateUpdated] to an arbitrary JSON value. + * + * You should usually call [Builder.dateUpdated] with a well-typed [OffsetDateTime] + * value instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun dateUpdated(dateUpdated: JsonField) = apply { + this.dateUpdated = dateUpdated + } + + /** The inference pipeline id. */ + fun inferencePipelineId(inferencePipelineId: String?) = + inferencePipelineId(JsonField.ofNullable(inferencePipelineId)) + + /** + * Alias for calling [Builder.inferencePipelineId] with + * `inferencePipelineId.orElse(null)`. + */ + fun inferencePipelineId(inferencePipelineId: Optional) = + inferencePipelineId(inferencePipelineId.getOrNull()) + + /** + * Sets [Builder.inferencePipelineId] to an arbitrary JSON value. + * + * You should usually call [Builder.inferencePipelineId] with a well-typed [String] + * value instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun inferencePipelineId(inferencePipelineId: JsonField) = apply { + this.inferencePipelineId = inferencePipelineId + } + + /** The project version (commit) id. */ + fun projectVersionId(projectVersionId: String?) = + projectVersionId(JsonField.ofNullable(projectVersionId)) + + /** + * Alias for calling [Builder.projectVersionId] with `projectVersionId.orElse(null)`. + */ + fun projectVersionId(projectVersionId: Optional) = + projectVersionId(projectVersionId.getOrNull()) + + /** + * Sets [Builder.projectVersionId] to an arbitrary JSON value. + * + * You should usually call [Builder.projectVersionId] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun projectVersionId(projectVersionId: JsonField) = apply { + this.projectVersionId = projectVersionId + } + + /** The status of the test. */ + fun status(status: Status) = status(JsonField.of(status)) + + /** + * Sets [Builder.status] to an arbitrary JSON value. + * + * You should usually call [Builder.status] with a well-typed [Status] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun status(status: JsonField) = apply { this.status = status } + + /** The status message. */ + fun statusMessage(statusMessage: String?) = + statusMessage(JsonField.ofNullable(statusMessage)) + + /** Alias for calling [Builder.statusMessage] with `statusMessage.orElse(null)`. */ + fun statusMessage(statusMessage: Optional) = + statusMessage(statusMessage.getOrNull()) + + /** + * Sets [Builder.statusMessage] to an arbitrary JSON value. + * + * You should usually call [Builder.statusMessage] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun statusMessage(statusMessage: JsonField) = apply { + this.statusMessage = statusMessage + } + + fun expectedValues(expectedValues: List) = + expectedValues(JsonField.of(expectedValues)) + + /** + * Sets [Builder.expectedValues] to an arbitrary JSON value. + * + * You should usually call [Builder.expectedValues] with a well-typed + * `List` value instead. This method is primarily for setting the field + * to an undocumented or not yet supported value. + */ + fun expectedValues(expectedValues: JsonField>) = apply { + this.expectedValues = expectedValues.map { it.toMutableList() } + } + + /** + * Adds a single [ExpectedValue] to [expectedValues]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addExpectedValue(expectedValue: ExpectedValue) = apply { + expectedValues = + (expectedValues ?: JsonField.of(mutableListOf())).also { + checkKnown("expectedValues", it).add(expectedValue) + } + } + + fun goal(goal: Goal) = goal(JsonField.of(goal)) + + /** + * Sets [Builder.goal] to an arbitrary JSON value. + * + * You should usually call [Builder.goal] with a well-typed [Goal] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun goal(goal: JsonField) = apply { this.goal = goal } + + /** The test id. */ + fun goalId(goalId: String?) = goalId(JsonField.ofNullable(goalId)) + + /** Alias for calling [Builder.goalId] with `goalId.orElse(null)`. */ + fun goalId(goalId: Optional) = goalId(goalId.getOrNull()) + + /** + * Sets [Builder.goalId] to an arbitrary JSON value. + * + * You should usually call [Builder.goalId] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun goalId(goalId: JsonField) = apply { this.goalId = goalId } + + /** The URL to the rows of the test result. */ + fun rows(rows: String) = rows(JsonField.of(rows)) + + /** + * Sets [Builder.rows] to an arbitrary JSON value. + * + * You should usually call [Builder.rows] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun rows(rows: JsonField) = apply { this.rows = rows } + + /** The body of the rows request. */ + fun rowsBody(rowsBody: RowsBody?) = rowsBody(JsonField.ofNullable(rowsBody)) + + /** Alias for calling [Builder.rowsBody] with `rowsBody.orElse(null)`. */ + fun rowsBody(rowsBody: Optional) = rowsBody(rowsBody.getOrNull()) + + /** + * Sets [Builder.rowsBody] to an arbitrary JSON value. + * + * You should usually call [Builder.rowsBody] with a well-typed [RowsBody] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun rowsBody(rowsBody: JsonField) = apply { this.rowsBody = rowsBody } + + 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 [Item]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .id() + * .dateCreated() + * .dateDataEnds() + * .dateDataStarts() + * .dateUpdated() + * .inferencePipelineId() + * .projectVersionId() + * .status() + * .statusMessage() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): Item = + Item( + checkRequired("id", id), + checkRequired("dateCreated", dateCreated), + checkRequired("dateDataEnds", dateDataEnds), + checkRequired("dateDataStarts", dateDataStarts), + checkRequired("dateUpdated", dateUpdated), + checkRequired("inferencePipelineId", inferencePipelineId), + checkRequired("projectVersionId", projectVersionId), + checkRequired("status", status), + checkRequired("statusMessage", statusMessage), + (expectedValues ?: JsonMissing.of()).map { it.toImmutable() }, + goal, + goalId, + rows, + rowsBody, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): Item = apply { + if (validated) { + return@apply + } + + id() + dateCreated() + dateDataEnds() + dateDataStarts() + dateUpdated() + inferencePipelineId() + projectVersionId() + status().validate() + statusMessage() + expectedValues().ifPresent { it.forEach { it.validate() } } + goal().ifPresent { it.validate() } + goalId() + rows() + rowsBody().ifPresent { it.validate() } + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OpenlayerInvalidDataException) { + false + } + + /** + * Returns a 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 (dateCreated.asKnown().isPresent) 1 else 0) + + (if (dateDataEnds.asKnown().isPresent) 1 else 0) + + (if (dateDataStarts.asKnown().isPresent) 1 else 0) + + (if (dateUpdated.asKnown().isPresent) 1 else 0) + + (if (inferencePipelineId.asKnown().isPresent) 1 else 0) + + (if (projectVersionId.asKnown().isPresent) 1 else 0) + + (status.asKnown().getOrNull()?.validity() ?: 0) + + (if (statusMessage.asKnown().isPresent) 1 else 0) + + (expectedValues.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + + (goal.asKnown().getOrNull()?.validity() ?: 0) + + (if (goalId.asKnown().isPresent) 1 else 0) + + (if (rows.asKnown().isPresent) 1 else 0) + + (rowsBody.asKnown().getOrNull()?.validity() ?: 0) + + /** The status of the test. */ + class Status @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 RUNNING = of("running") + + @JvmField val PASSING = of("passing") + + @JvmField val FAILING = of("failing") + + @JvmField val SKIPPED = of("skipped") + + @JvmField val ERROR = of("error") + + @JvmStatic fun of(value: String) = Status(JsonField.of(value)) + } + + /** An enum containing [Status]'s known values. */ + enum class Known { + RUNNING, + PASSING, + FAILING, + SKIPPED, + ERROR, + } + + /** + * An enum containing [Status]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [Status] 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 { + RUNNING, + PASSING, + FAILING, + SKIPPED, + ERROR, + /** + * An enum member indicating that [Status] 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) { + RUNNING -> Value.RUNNING + PASSING -> Value.PASSING + FAILING -> Value.FAILING + SKIPPED -> Value.SKIPPED + ERROR -> Value.ERROR + 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 OpenlayerInvalidDataException if this class instance's value is a not a known + * member. + */ + fun known(): Known = + when (this) { + RUNNING -> Known.RUNNING + PASSING -> Known.PASSING + FAILING -> Known.FAILING + SKIPPED -> Known.SKIPPED + ERROR -> Known.ERROR + else -> throw OpenlayerInvalidDataException("Unknown Status: $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 OpenlayerInvalidDataException if this class instance's value does not have + * the expected primitive type. + */ + fun asString(): String = + _value().asString().orElseThrow { + OpenlayerInvalidDataException("Value is not a String") + } + + private var validated: Boolean = false + + fun validate(): Status = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OpenlayerInvalidDataException) { + false + } + + /** + * Returns a 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 Status && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + class ExpectedValue + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val lowerThreshold: JsonField, + private val measurement: JsonField, + private val upperThreshold: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("lowerThreshold") + @ExcludeMissing + lowerThreshold: JsonField = JsonMissing.of(), + @JsonProperty("measurement") + @ExcludeMissing + measurement: JsonField = JsonMissing.of(), + @JsonProperty("upperThreshold") + @ExcludeMissing + upperThreshold: JsonField = JsonMissing.of(), + ) : this(lowerThreshold, measurement, upperThreshold, mutableMapOf()) + + /** + * the lower threshold for the expected value + * + * @throws OpenlayerInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun lowerThreshold(): Optional = lowerThreshold.getOptional("lowerThreshold") + + /** + * One of the `measurement` values in the test's thresholds + * + * @throws OpenlayerInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun measurement(): Optional = measurement.getOptional("measurement") + + /** + * The upper threshold for the expected value + * + * @throws OpenlayerInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun upperThreshold(): Optional = upperThreshold.getOptional("upperThreshold") + + /** + * Returns the raw JSON value of [lowerThreshold]. + * + * Unlike [lowerThreshold], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("lowerThreshold") + @ExcludeMissing + fun _lowerThreshold(): JsonField = lowerThreshold + + /** + * Returns the raw JSON value of [measurement]. + * + * Unlike [measurement], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("measurement") + @ExcludeMissing + fun _measurement(): JsonField = measurement + + /** + * Returns the raw JSON value of [upperThreshold]. + * + * Unlike [upperThreshold], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("upperThreshold") + @ExcludeMissing + fun _upperThreshold(): JsonField = upperThreshold + + @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 [ExpectedValue]. */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [ExpectedValue]. */ + class Builder internal constructor() { + + private var lowerThreshold: JsonField = JsonMissing.of() + private var measurement: JsonField = JsonMissing.of() + private var upperThreshold: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(expectedValue: ExpectedValue) = apply { + lowerThreshold = expectedValue.lowerThreshold + measurement = expectedValue.measurement + upperThreshold = expectedValue.upperThreshold + additionalProperties = expectedValue.additionalProperties.toMutableMap() + } + + /** the lower threshold for the expected value */ + fun lowerThreshold(lowerThreshold: Float?) = + lowerThreshold(JsonField.ofNullable(lowerThreshold)) + + /** + * Alias for [Builder.lowerThreshold]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun lowerThreshold(lowerThreshold: Float) = lowerThreshold(lowerThreshold as Float?) + + /** + * Alias for calling [Builder.lowerThreshold] with `lowerThreshold.orElse(null)`. + */ + fun lowerThreshold(lowerThreshold: Optional) = + lowerThreshold(lowerThreshold.getOrNull()) + + /** + * Sets [Builder.lowerThreshold] to an arbitrary JSON value. + * + * You should usually call [Builder.lowerThreshold] with a well-typed [Float] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun lowerThreshold(lowerThreshold: JsonField) = apply { + this.lowerThreshold = lowerThreshold + } + + /** One of the `measurement` values in the test's thresholds */ + fun measurement(measurement: String) = measurement(JsonField.of(measurement)) + + /** + * Sets [Builder.measurement] to an arbitrary JSON value. + * + * You should usually call [Builder.measurement] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun measurement(measurement: JsonField) = apply { + this.measurement = measurement + } + + /** The upper threshold for the expected value */ + fun upperThreshold(upperThreshold: Float?) = + upperThreshold(JsonField.ofNullable(upperThreshold)) + + /** + * Alias for [Builder.upperThreshold]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun upperThreshold(upperThreshold: Float) = upperThreshold(upperThreshold as Float?) + + /** + * Alias for calling [Builder.upperThreshold] with `upperThreshold.orElse(null)`. + */ + fun upperThreshold(upperThreshold: Optional) = + upperThreshold(upperThreshold.getOrNull()) + + /** + * Sets [Builder.upperThreshold] to an arbitrary JSON value. + * + * You should usually call [Builder.upperThreshold] with a well-typed [Float] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun upperThreshold(upperThreshold: JsonField) = apply { + this.upperThreshold = upperThreshold + } + + 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 [ExpectedValue]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): ExpectedValue = + ExpectedValue( + lowerThreshold, + measurement, + upperThreshold, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): ExpectedValue = apply { + if (validated) { + return@apply + } + + lowerThreshold() + measurement() + upperThreshold() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OpenlayerInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (if (lowerThreshold.asKnown().isPresent) 1 else 0) + + (if (measurement.asKnown().isPresent) 1 else 0) + + (if (upperThreshold.asKnown().isPresent) 1 else 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is ExpectedValue && + lowerThreshold == other.lowerThreshold && + measurement == other.measurement && + upperThreshold == other.upperThreshold && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(lowerThreshold, measurement, upperThreshold, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "ExpectedValue{lowerThreshold=$lowerThreshold, measurement=$measurement, upperThreshold=$upperThreshold, additionalProperties=$additionalProperties}" + } + + class Goal + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val id: JsonField, + private val commentCount: JsonField, + private val creatorId: JsonField, + private val dateArchived: JsonField, + private val dateCreated: JsonField, + private val dateUpdated: JsonField, + private val description: JsonValue, + private val name: JsonField, + private val number: JsonField, + private val originProjectVersionId: JsonField, + private val subtype: JsonField, + private val suggested: JsonField, + private val thresholds: JsonField>, + private val type: JsonField, + private val archived: JsonField, + private val delayWindow: JsonField, + private val evaluationWindow: JsonField, + private val usesMlModel: JsonField, + private val usesProductionData: JsonField, + private val usesReferenceDataset: JsonField, + private val usesTrainingDataset: JsonField, + private val usesValidationDataset: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("id") @ExcludeMissing id: JsonField = JsonMissing.of(), + @JsonProperty("commentCount") + @ExcludeMissing + commentCount: JsonField = JsonMissing.of(), + @JsonProperty("creatorId") + @ExcludeMissing + creatorId: JsonField = JsonMissing.of(), + @JsonProperty("dateArchived") + @ExcludeMissing + dateArchived: JsonField = JsonMissing.of(), + @JsonProperty("dateCreated") + @ExcludeMissing + dateCreated: JsonField = JsonMissing.of(), + @JsonProperty("dateUpdated") + @ExcludeMissing + dateUpdated: JsonField = JsonMissing.of(), + @JsonProperty("description") + @ExcludeMissing + description: JsonValue = JsonMissing.of(), + @JsonProperty("name") @ExcludeMissing name: JsonField = JsonMissing.of(), + @JsonProperty("number") @ExcludeMissing number: JsonField = JsonMissing.of(), + @JsonProperty("originProjectVersionId") + @ExcludeMissing + originProjectVersionId: JsonField = JsonMissing.of(), + @JsonProperty("subtype") + @ExcludeMissing + subtype: JsonField = JsonMissing.of(), + @JsonProperty("suggested") + @ExcludeMissing + suggested: JsonField = JsonMissing.of(), + @JsonProperty("thresholds") + @ExcludeMissing + thresholds: JsonField> = JsonMissing.of(), + @JsonProperty("type") @ExcludeMissing type: JsonField = JsonMissing.of(), + @JsonProperty("archived") + @ExcludeMissing + archived: JsonField = JsonMissing.of(), + @JsonProperty("delayWindow") + @ExcludeMissing + delayWindow: JsonField = JsonMissing.of(), + @JsonProperty("evaluationWindow") + @ExcludeMissing + evaluationWindow: JsonField = JsonMissing.of(), + @JsonProperty("usesMlModel") + @ExcludeMissing + usesMlModel: JsonField = JsonMissing.of(), + @JsonProperty("usesProductionData") + @ExcludeMissing + usesProductionData: JsonField = JsonMissing.of(), + @JsonProperty("usesReferenceDataset") + @ExcludeMissing + usesReferenceDataset: JsonField = JsonMissing.of(), + @JsonProperty("usesTrainingDataset") + @ExcludeMissing + usesTrainingDataset: JsonField = JsonMissing.of(), + @JsonProperty("usesValidationDataset") + @ExcludeMissing + usesValidationDataset: JsonField = JsonMissing.of(), + ) : this( + id, + commentCount, + creatorId, + dateArchived, + dateCreated, + dateUpdated, + description, + name, + number, + originProjectVersionId, + subtype, + suggested, + thresholds, + type, + archived, + delayWindow, + evaluationWindow, + usesMlModel, + usesProductionData, + usesReferenceDataset, + usesTrainingDataset, + usesValidationDataset, + mutableMapOf(), + ) + + /** + * The test id. + * + * @throws OpenlayerInvalidDataException if 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 number of comments on the test. + * + * @throws OpenlayerInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun commentCount(): Long = commentCount.getRequired("commentCount") + + /** + * The test creator id. + * + * @throws OpenlayerInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun creatorId(): Optional = creatorId.getOptional("creatorId") + + /** + * The date the test was archived. + * + * @throws OpenlayerInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun dateArchived(): Optional = dateArchived.getOptional("dateArchived") + + /** + * The creation date. + * + * @throws OpenlayerInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun dateCreated(): OffsetDateTime = dateCreated.getRequired("dateCreated") + + /** + * The last updated date. + * + * @throws OpenlayerInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun dateUpdated(): OffsetDateTime = dateUpdated.getRequired("dateUpdated") + + /** The test description. */ + @JsonProperty("description") @ExcludeMissing fun _description(): JsonValue = description + + /** + * The test name. + * + * @throws OpenlayerInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun name(): String = name.getRequired("name") + + /** + * The test number. + * + * @throws OpenlayerInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun number(): Long = number.getRequired("number") + + /** + * The project version (commit) id where the test was created. + * + * @throws OpenlayerInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun originProjectVersionId(): Optional = + originProjectVersionId.getOptional("originProjectVersionId") + + /** + * The test subtype. + * + * @throws OpenlayerInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun subtype(): Subtype = subtype.getRequired("subtype") + + /** + * Whether the test is suggested or user-created. + * + * @throws OpenlayerInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun suggested(): Boolean = suggested.getRequired("suggested") + + /** + * @throws OpenlayerInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun thresholds(): List = thresholds.getRequired("thresholds") + + /** + * The test type. + * + * @throws OpenlayerInvalidDataException if 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") + + /** + * Whether the test is archived. + * + * @throws OpenlayerInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun archived(): Optional = archived.getOptional("archived") + + /** + * The delay window in seconds. Only applies to tests that use production data. + * + * @throws OpenlayerInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun delayWindow(): Optional = delayWindow.getOptional("delayWindow") + + /** + * The evaluation window in seconds. Only applies to tests that use production data. + * + * @throws OpenlayerInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun evaluationWindow(): Optional = + evaluationWindow.getOptional("evaluationWindow") + + /** + * Whether the test uses an ML model. + * + * @throws OpenlayerInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun usesMlModel(): Optional = usesMlModel.getOptional("usesMlModel") + + /** + * Whether the test uses production data (monitoring mode only). + * + * @throws OpenlayerInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun usesProductionData(): Optional = + usesProductionData.getOptional("usesProductionData") + + /** + * Whether the test uses a reference dataset (monitoring mode only). + * + * @throws OpenlayerInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun usesReferenceDataset(): Optional = + usesReferenceDataset.getOptional("usesReferenceDataset") + + /** + * Whether the test uses a training dataset. + * + * @throws OpenlayerInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun usesTrainingDataset(): Optional = + usesTrainingDataset.getOptional("usesTrainingDataset") + + /** + * Whether the test uses a validation dataset. + * + * @throws OpenlayerInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun usesValidationDataset(): Optional = + usesValidationDataset.getOptional("usesValidationDataset") + + /** + * 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 [commentCount]. + * + * Unlike [commentCount], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("commentCount") + @ExcludeMissing + fun _commentCount(): JsonField = commentCount + + /** + * Returns the raw JSON value of [creatorId]. + * + * Unlike [creatorId], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("creatorId") + @ExcludeMissing + fun _creatorId(): JsonField = creatorId + + /** + * Returns the raw JSON value of [dateArchived]. + * + * Unlike [dateArchived], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("dateArchived") + @ExcludeMissing + fun _dateArchived(): JsonField = dateArchived + + /** + * Returns the raw JSON value of [dateCreated]. + * + * Unlike [dateCreated], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("dateCreated") + @ExcludeMissing + fun _dateCreated(): JsonField = dateCreated + + /** + * Returns the raw JSON value of [dateUpdated]. + * + * Unlike [dateUpdated], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("dateUpdated") + @ExcludeMissing + fun _dateUpdated(): JsonField = dateUpdated + + /** + * 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 [number]. + * + * Unlike [number], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("number") @ExcludeMissing fun _number(): JsonField = number + + /** + * Returns the raw JSON value of [originProjectVersionId]. + * + * Unlike [originProjectVersionId], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("originProjectVersionId") + @ExcludeMissing + fun _originProjectVersionId(): JsonField = originProjectVersionId + + /** + * Returns the raw JSON value of [subtype]. + * + * Unlike [subtype], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("subtype") @ExcludeMissing fun _subtype(): JsonField = subtype + + /** + * Returns the raw JSON value of [suggested]. + * + * Unlike [suggested], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("suggested") + @ExcludeMissing + fun _suggested(): JsonField = suggested + + /** + * Returns the raw JSON value of [thresholds]. + * + * Unlike [thresholds], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("thresholds") + @ExcludeMissing + fun _thresholds(): JsonField> = thresholds + + /** + * 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 + + /** + * Returns the raw JSON value of [archived]. + * + * Unlike [archived], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("archived") @ExcludeMissing fun _archived(): JsonField = archived + + /** + * Returns the raw JSON value of [delayWindow]. + * + * Unlike [delayWindow], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("delayWindow") + @ExcludeMissing + fun _delayWindow(): JsonField = delayWindow + + /** + * Returns the raw JSON value of [evaluationWindow]. + * + * Unlike [evaluationWindow], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("evaluationWindow") + @ExcludeMissing + fun _evaluationWindow(): JsonField = evaluationWindow + + /** + * Returns the raw JSON value of [usesMlModel]. + * + * Unlike [usesMlModel], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("usesMlModel") + @ExcludeMissing + fun _usesMlModel(): JsonField = usesMlModel + + /** + * Returns the raw JSON value of [usesProductionData]. + * + * Unlike [usesProductionData], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("usesProductionData") + @ExcludeMissing + fun _usesProductionData(): JsonField = usesProductionData + + /** + * Returns the raw JSON value of [usesReferenceDataset]. + * + * Unlike [usesReferenceDataset], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("usesReferenceDataset") + @ExcludeMissing + fun _usesReferenceDataset(): JsonField = usesReferenceDataset + + /** + * Returns the raw JSON value of [usesTrainingDataset]. + * + * Unlike [usesTrainingDataset], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("usesTrainingDataset") + @ExcludeMissing + fun _usesTrainingDataset(): JsonField = usesTrainingDataset + + /** + * Returns the raw JSON value of [usesValidationDataset]. + * + * Unlike [usesValidationDataset], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("usesValidationDataset") + @ExcludeMissing + fun _usesValidationDataset(): JsonField = usesValidationDataset + + @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 [Goal]. + * + * The following fields are required: + * ```java + * .id() + * .commentCount() + * .creatorId() + * .dateArchived() + * .dateCreated() + * .dateUpdated() + * .description() + * .name() + * .number() + * .originProjectVersionId() + * .subtype() + * .suggested() + * .thresholds() + * .type() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [Goal]. */ + class Builder internal constructor() { + + private var id: JsonField? = null + private var commentCount: JsonField? = null + private var creatorId: JsonField? = null + private var dateArchived: JsonField? = null + private var dateCreated: JsonField? = null + private var dateUpdated: JsonField? = null + private var description: JsonValue? = null + private var name: JsonField? = null + private var number: JsonField? = null + private var originProjectVersionId: JsonField? = null + private var subtype: JsonField? = null + private var suggested: JsonField? = null + private var thresholds: JsonField>? = null + private var type: JsonField? = null + private var archived: JsonField = JsonMissing.of() + private var delayWindow: JsonField = JsonMissing.of() + private var evaluationWindow: JsonField = JsonMissing.of() + private var usesMlModel: JsonField = JsonMissing.of() + private var usesProductionData: JsonField = JsonMissing.of() + private var usesReferenceDataset: JsonField = JsonMissing.of() + private var usesTrainingDataset: JsonField = JsonMissing.of() + private var usesValidationDataset: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(goal: Goal) = apply { + id = goal.id + commentCount = goal.commentCount + creatorId = goal.creatorId + dateArchived = goal.dateArchived + dateCreated = goal.dateCreated + dateUpdated = goal.dateUpdated + description = goal.description + name = goal.name + number = goal.number + originProjectVersionId = goal.originProjectVersionId + subtype = goal.subtype + suggested = goal.suggested + thresholds = goal.thresholds.map { it.toMutableList() } + type = goal.type + archived = goal.archived + delayWindow = goal.delayWindow + evaluationWindow = goal.evaluationWindow + usesMlModel = goal.usesMlModel + usesProductionData = goal.usesProductionData + usesReferenceDataset = goal.usesReferenceDataset + usesTrainingDataset = goal.usesTrainingDataset + usesValidationDataset = goal.usesValidationDataset + additionalProperties = goal.additionalProperties.toMutableMap() + } + + /** The test 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 } + + /** The number of comments on the test. */ + fun commentCount(commentCount: Long) = commentCount(JsonField.of(commentCount)) + + /** + * Sets [Builder.commentCount] to an arbitrary JSON value. + * + * You should usually call [Builder.commentCount] with a well-typed [Long] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun commentCount(commentCount: JsonField) = apply { + this.commentCount = commentCount + } + + /** The test creator id. */ + fun creatorId(creatorId: String?) = creatorId(JsonField.ofNullable(creatorId)) + + /** Alias for calling [Builder.creatorId] with `creatorId.orElse(null)`. */ + fun creatorId(creatorId: Optional) = creatorId(creatorId.getOrNull()) + + /** + * Sets [Builder.creatorId] to an arbitrary JSON value. + * + * You should usually call [Builder.creatorId] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun creatorId(creatorId: JsonField) = apply { this.creatorId = creatorId } + + /** The date the test was archived. */ + fun dateArchived(dateArchived: OffsetDateTime?) = + dateArchived(JsonField.ofNullable(dateArchived)) + + /** Alias for calling [Builder.dateArchived] with `dateArchived.orElse(null)`. */ + fun dateArchived(dateArchived: Optional) = + dateArchived(dateArchived.getOrNull()) + + /** + * Sets [Builder.dateArchived] to an arbitrary JSON value. + * + * You should usually call [Builder.dateArchived] with a well-typed [OffsetDateTime] + * value instead. This method is primarily for setting the field to an undocumented + * or not yet supported value. + */ + fun dateArchived(dateArchived: JsonField) = apply { + this.dateArchived = dateArchived + } + + /** The creation date. */ + fun dateCreated(dateCreated: OffsetDateTime) = + dateCreated(JsonField.of(dateCreated)) + + /** + * Sets [Builder.dateCreated] to an arbitrary JSON value. + * + * You should usually call [Builder.dateCreated] with a well-typed [OffsetDateTime] + * value instead. This method is primarily for setting the field to an undocumented + * or not yet supported value. + */ + fun dateCreated(dateCreated: JsonField) = apply { + this.dateCreated = dateCreated + } + + /** The last updated date. */ + fun dateUpdated(dateUpdated: OffsetDateTime) = + dateUpdated(JsonField.of(dateUpdated)) + + /** + * Sets [Builder.dateUpdated] to an arbitrary JSON value. + * + * You should usually call [Builder.dateUpdated] with a well-typed [OffsetDateTime] + * value instead. This method is primarily for setting the field to an undocumented + * or not yet supported value. + */ + fun dateUpdated(dateUpdated: JsonField) = apply { + this.dateUpdated = dateUpdated + } + + /** The test description. */ + fun description(description: JsonValue) = apply { this.description = description } + + /** The test 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 test number. */ + fun number(number: Long) = number(JsonField.of(number)) + + /** + * Sets [Builder.number] to an arbitrary JSON value. + * + * You should usually call [Builder.number] with a well-typed [Long] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun number(number: JsonField) = apply { this.number = number } + + /** The project version (commit) id where the test was created. */ + fun originProjectVersionId(originProjectVersionId: String?) = + originProjectVersionId(JsonField.ofNullable(originProjectVersionId)) + + /** + * Alias for calling [Builder.originProjectVersionId] with + * `originProjectVersionId.orElse(null)`. + */ + fun originProjectVersionId(originProjectVersionId: Optional) = + originProjectVersionId(originProjectVersionId.getOrNull()) + + /** + * Sets [Builder.originProjectVersionId] to an arbitrary JSON value. + * + * You should usually call [Builder.originProjectVersionId] with a well-typed + * [String] value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun originProjectVersionId(originProjectVersionId: JsonField) = apply { + this.originProjectVersionId = originProjectVersionId + } + + /** The test subtype. */ + fun subtype(subtype: Subtype) = subtype(JsonField.of(subtype)) + + /** + * Sets [Builder.subtype] to an arbitrary JSON value. + * + * You should usually call [Builder.subtype] with a well-typed [Subtype] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun subtype(subtype: JsonField) = apply { this.subtype = subtype } + + /** Whether the test is suggested or user-created. */ + fun suggested(suggested: Boolean) = suggested(JsonField.of(suggested)) + + /** + * Sets [Builder.suggested] to an arbitrary JSON value. + * + * You should usually call [Builder.suggested] with a well-typed [Boolean] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun suggested(suggested: JsonField) = apply { this.suggested = suggested } + + fun thresholds(thresholds: List) = thresholds(JsonField.of(thresholds)) + + /** + * Sets [Builder.thresholds] to an arbitrary JSON value. + * + * You should usually call [Builder.thresholds] with a well-typed `List` + * value instead. This method is primarily for setting the field to an undocumented + * or not yet supported value. + */ + fun thresholds(thresholds: JsonField>) = apply { + this.thresholds = thresholds.map { it.toMutableList() } + } + + /** + * Adds a single [Threshold] to [thresholds]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addThreshold(threshold: Threshold) = apply { + thresholds = + (thresholds ?: JsonField.of(mutableListOf())).also { + checkKnown("thresholds", it).add(threshold) + } + } + + /** The test 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 } + + /** Whether the test is archived. */ + fun archived(archived: Boolean) = archived(JsonField.of(archived)) + + /** + * Sets [Builder.archived] to an arbitrary JSON value. + * + * You should usually call [Builder.archived] with a well-typed [Boolean] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun archived(archived: JsonField) = apply { this.archived = archived } + + /** The delay window in seconds. Only applies to tests that use production data. */ + fun delayWindow(delayWindow: Double?) = + delayWindow(JsonField.ofNullable(delayWindow)) + + /** + * Alias for [Builder.delayWindow]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun delayWindow(delayWindow: Double) = delayWindow(delayWindow as Double?) + + /** Alias for calling [Builder.delayWindow] with `delayWindow.orElse(null)`. */ + fun delayWindow(delayWindow: Optional) = + delayWindow(delayWindow.getOrNull()) + + /** + * Sets [Builder.delayWindow] to an arbitrary JSON value. + * + * You should usually call [Builder.delayWindow] with a well-typed [Double] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun delayWindow(delayWindow: JsonField) = apply { + this.delayWindow = delayWindow + } + + /** + * The evaluation window in seconds. Only applies to tests that use production data. + */ + fun evaluationWindow(evaluationWindow: Double?) = + evaluationWindow(JsonField.ofNullable(evaluationWindow)) + + /** + * Alias for [Builder.evaluationWindow]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun evaluationWindow(evaluationWindow: Double) = + evaluationWindow(evaluationWindow as Double?) + + /** + * Alias for calling [Builder.evaluationWindow] with + * `evaluationWindow.orElse(null)`. + */ + fun evaluationWindow(evaluationWindow: Optional) = + evaluationWindow(evaluationWindow.getOrNull()) + + /** + * Sets [Builder.evaluationWindow] to an arbitrary JSON value. + * + * You should usually call [Builder.evaluationWindow] with a well-typed [Double] + * value instead. This method is primarily for setting the field to an undocumented + * or not yet supported value. + */ + fun evaluationWindow(evaluationWindow: JsonField) = apply { + this.evaluationWindow = evaluationWindow + } + + /** Whether the test uses an ML model. */ + fun usesMlModel(usesMlModel: Boolean) = usesMlModel(JsonField.of(usesMlModel)) + + /** + * Sets [Builder.usesMlModel] to an arbitrary JSON value. + * + * You should usually call [Builder.usesMlModel] with a well-typed [Boolean] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun usesMlModel(usesMlModel: JsonField) = apply { + this.usesMlModel = usesMlModel + } + + /** Whether the test uses production data (monitoring mode only). */ + fun usesProductionData(usesProductionData: Boolean) = + usesProductionData(JsonField.of(usesProductionData)) + + /** + * Sets [Builder.usesProductionData] to an arbitrary JSON value. + * + * You should usually call [Builder.usesProductionData] with a well-typed [Boolean] + * value instead. This method is primarily for setting the field to an undocumented + * or not yet supported value. + */ + fun usesProductionData(usesProductionData: JsonField) = apply { + this.usesProductionData = usesProductionData + } + + /** Whether the test uses a reference dataset (monitoring mode only). */ + fun usesReferenceDataset(usesReferenceDataset: Boolean) = + usesReferenceDataset(JsonField.of(usesReferenceDataset)) + + /** + * Sets [Builder.usesReferenceDataset] to an arbitrary JSON value. + * + * You should usually call [Builder.usesReferenceDataset] with a well-typed + * [Boolean] value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun usesReferenceDataset(usesReferenceDataset: JsonField) = apply { + this.usesReferenceDataset = usesReferenceDataset + } + + /** Whether the test uses a training dataset. */ + fun usesTrainingDataset(usesTrainingDataset: Boolean) = + usesTrainingDataset(JsonField.of(usesTrainingDataset)) + + /** + * Sets [Builder.usesTrainingDataset] to an arbitrary JSON value. + * + * You should usually call [Builder.usesTrainingDataset] with a well-typed [Boolean] + * value instead. This method is primarily for setting the field to an undocumented + * or not yet supported value. + */ + fun usesTrainingDataset(usesTrainingDataset: JsonField) = apply { + this.usesTrainingDataset = usesTrainingDataset + } + + /** Whether the test uses a validation dataset. */ + fun usesValidationDataset(usesValidationDataset: Boolean) = + usesValidationDataset(JsonField.of(usesValidationDataset)) + + /** + * Sets [Builder.usesValidationDataset] to an arbitrary JSON value. + * + * You should usually call [Builder.usesValidationDataset] with a well-typed + * [Boolean] value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun usesValidationDataset(usesValidationDataset: JsonField) = apply { + this.usesValidationDataset = usesValidationDataset + } + + 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 [Goal]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .id() + * .commentCount() + * .creatorId() + * .dateArchived() + * .dateCreated() + * .dateUpdated() + * .description() + * .name() + * .number() + * .originProjectVersionId() + * .subtype() + * .suggested() + * .thresholds() + * .type() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): Goal = + Goal( + checkRequired("id", id), + checkRequired("commentCount", commentCount), + checkRequired("creatorId", creatorId), + checkRequired("dateArchived", dateArchived), + checkRequired("dateCreated", dateCreated), + checkRequired("dateUpdated", dateUpdated), + checkRequired("description", description), + checkRequired("name", name), + checkRequired("number", number), + checkRequired("originProjectVersionId", originProjectVersionId), + checkRequired("subtype", subtype), + checkRequired("suggested", suggested), + checkRequired("thresholds", thresholds).map { it.toImmutable() }, + checkRequired("type", type), + archived, + delayWindow, + evaluationWindow, + usesMlModel, + usesProductionData, + usesReferenceDataset, + usesTrainingDataset, + usesValidationDataset, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): Goal = apply { + if (validated) { + return@apply + } + + id() + commentCount() + creatorId() + dateArchived() + dateCreated() + dateUpdated() + name() + number() + originProjectVersionId() + subtype().validate() + suggested() + thresholds().forEach { it.validate() } + type().validate() + archived() + delayWindow() + evaluationWindow() + usesMlModel() + usesProductionData() + usesReferenceDataset() + usesTrainingDataset() + usesValidationDataset() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OpenlayerInvalidDataException) { + false + } + + /** + * Returns a 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 (commentCount.asKnown().isPresent) 1 else 0) + + (if (creatorId.asKnown().isPresent) 1 else 0) + + (if (dateArchived.asKnown().isPresent) 1 else 0) + + (if (dateCreated.asKnown().isPresent) 1 else 0) + + (if (dateUpdated.asKnown().isPresent) 1 else 0) + + (if (name.asKnown().isPresent) 1 else 0) + + (if (number.asKnown().isPresent) 1 else 0) + + (if (originProjectVersionId.asKnown().isPresent) 1 else 0) + + (subtype.asKnown().getOrNull()?.validity() ?: 0) + + (if (suggested.asKnown().isPresent) 1 else 0) + + (thresholds.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + + (type.asKnown().getOrNull()?.validity() ?: 0) + + (if (archived.asKnown().isPresent) 1 else 0) + + (if (delayWindow.asKnown().isPresent) 1 else 0) + + (if (evaluationWindow.asKnown().isPresent) 1 else 0) + + (if (usesMlModel.asKnown().isPresent) 1 else 0) + + (if (usesProductionData.asKnown().isPresent) 1 else 0) + + (if (usesReferenceDataset.asKnown().isPresent) 1 else 0) + + (if (usesTrainingDataset.asKnown().isPresent) 1 else 0) + + (if (usesValidationDataset.asKnown().isPresent) 1 else 0) + + /** The test subtype. */ + class Subtype @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 ANOMALOUS_COLUMN_COUNT = of("anomalousColumnCount") + + @JvmField val CHARACTER_LENGTH = of("characterLength") + + @JvmField val CLASS_IMBALANCE_RATIO = of("classImbalanceRatio") + + @JvmField + val EXPECT_COLUMN_A_TO_BE_IN_COLUMN_B = of("expectColumnAToBeInColumnB") + + @JvmField val COLUMN_AVERAGE = of("columnAverage") + + @JvmField val COLUMN_DRIFT = of("columnDrift") + + @JvmField val COLUMN_STATISTIC = of("columnStatistic") + + @JvmField val COLUMN_VALUES_MATCH = of("columnValuesMatch") + + @JvmField val CONFLICTING_LABEL_ROW_COUNT = of("conflictingLabelRowCount") + + @JvmField val CONTAINS_PII = of("containsPii") + + @JvmField val CONTAINS_VALID_URL = of("containsValidUrl") + + @JvmField val CORRELATED_FEATURE_COUNT = of("correlatedFeatureCount") + + @JvmField val CUSTOM_METRIC_THRESHOLD = of("customMetricThreshold") + + @JvmField val DUPLICATE_ROW_COUNT = of("duplicateRowCount") + + @JvmField val EMPTY_FEATURE = of("emptyFeature") + + @JvmField val EMPTY_FEATURE_COUNT = of("emptyFeatureCount") + + @JvmField val DRIFTED_FEATURE_COUNT = of("driftedFeatureCount") + + @JvmField val FEATURE_MISSING_VALUES = of("featureMissingValues") + + @JvmField val FEATURE_VALUE_VALIDATION = of("featureValueValidation") + + @JvmField val GREAT_EXPECTATIONS = of("greatExpectations") + + @JvmField val GROUP_BY_COLUMN_STATS_CHECK = of("groupByColumnStatsCheck") + + @JvmField val ILL_FORMED_ROW_COUNT = of("illFormedRowCount") + + @JvmField val IS_CODE = of("isCode") + + @JvmField val IS_JSON = of("isJson") + + @JvmField val LLM_RUBRIC_THRESHOLD_V2 = of("llmRubricThresholdV2") + + @JvmField val LABEL_DRIFT = of("labelDrift") + + @JvmField val METRIC_THRESHOLD = of("metricThreshold") + + @JvmField val NEW_CATEGORY_COUNT = of("newCategoryCount") + + @JvmField val NEW_LABEL_COUNT = of("newLabelCount") + + @JvmField val NULL_ROW_COUNT = of("nullRowCount") + + @JvmField val ROW_COUNT = of("rowCount") + + @JvmField val PP_SCORE_VALUE_VALIDATION = of("ppScoreValueValidation") + + @JvmField val QUASI_CONSTANT_FEATURE = of("quasiConstantFeature") + + @JvmField val QUASI_CONSTANT_FEATURE_COUNT = of("quasiConstantFeatureCount") + + @JvmField val SQL_QUERY = of("sqlQuery") + + @JvmField val DTYPE_VALIDATION = of("dtypeValidation") + + @JvmField val SENTENCE_LENGTH = of("sentenceLength") + + @JvmField val SIZE_RATIO = of("sizeRatio") + + @JvmField val SPECIAL_CHARACTERS_RATIO = of("specialCharactersRatio") + + @JvmField val STRING_VALIDATION = of("stringValidation") + + @JvmField val TRAIN_VAL_LEAKAGE_ROW_COUNT = of("trainValLeakageRowCount") + + @JvmStatic fun of(value: String) = Subtype(JsonField.of(value)) + } + + /** An enum containing [Subtype]'s known values. */ + enum class Known { + ANOMALOUS_COLUMN_COUNT, + CHARACTER_LENGTH, + CLASS_IMBALANCE_RATIO, + EXPECT_COLUMN_A_TO_BE_IN_COLUMN_B, + COLUMN_AVERAGE, + COLUMN_DRIFT, + COLUMN_STATISTIC, + COLUMN_VALUES_MATCH, + CONFLICTING_LABEL_ROW_COUNT, + CONTAINS_PII, + CONTAINS_VALID_URL, + CORRELATED_FEATURE_COUNT, + CUSTOM_METRIC_THRESHOLD, + DUPLICATE_ROW_COUNT, + EMPTY_FEATURE, + EMPTY_FEATURE_COUNT, + DRIFTED_FEATURE_COUNT, + FEATURE_MISSING_VALUES, + FEATURE_VALUE_VALIDATION, + GREAT_EXPECTATIONS, + GROUP_BY_COLUMN_STATS_CHECK, + ILL_FORMED_ROW_COUNT, + IS_CODE, + IS_JSON, + LLM_RUBRIC_THRESHOLD_V2, + LABEL_DRIFT, + METRIC_THRESHOLD, + NEW_CATEGORY_COUNT, + NEW_LABEL_COUNT, + NULL_ROW_COUNT, + ROW_COUNT, + PP_SCORE_VALUE_VALIDATION, + QUASI_CONSTANT_FEATURE, + QUASI_CONSTANT_FEATURE_COUNT, + SQL_QUERY, + DTYPE_VALIDATION, + SENTENCE_LENGTH, + SIZE_RATIO, + SPECIAL_CHARACTERS_RATIO, + STRING_VALIDATION, + TRAIN_VAL_LEAKAGE_ROW_COUNT, + } + + /** + * An enum containing [Subtype]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [Subtype] 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 { + ANOMALOUS_COLUMN_COUNT, + CHARACTER_LENGTH, + CLASS_IMBALANCE_RATIO, + EXPECT_COLUMN_A_TO_BE_IN_COLUMN_B, + COLUMN_AVERAGE, + COLUMN_DRIFT, + COLUMN_STATISTIC, + COLUMN_VALUES_MATCH, + CONFLICTING_LABEL_ROW_COUNT, + CONTAINS_PII, + CONTAINS_VALID_URL, + CORRELATED_FEATURE_COUNT, + CUSTOM_METRIC_THRESHOLD, + DUPLICATE_ROW_COUNT, + EMPTY_FEATURE, + EMPTY_FEATURE_COUNT, + DRIFTED_FEATURE_COUNT, + FEATURE_MISSING_VALUES, + FEATURE_VALUE_VALIDATION, + GREAT_EXPECTATIONS, + GROUP_BY_COLUMN_STATS_CHECK, + ILL_FORMED_ROW_COUNT, + IS_CODE, + IS_JSON, + LLM_RUBRIC_THRESHOLD_V2, + LABEL_DRIFT, + METRIC_THRESHOLD, + NEW_CATEGORY_COUNT, + NEW_LABEL_COUNT, + NULL_ROW_COUNT, + ROW_COUNT, + PP_SCORE_VALUE_VALIDATION, + QUASI_CONSTANT_FEATURE, + QUASI_CONSTANT_FEATURE_COUNT, + SQL_QUERY, + DTYPE_VALIDATION, + SENTENCE_LENGTH, + SIZE_RATIO, + SPECIAL_CHARACTERS_RATIO, + STRING_VALIDATION, + TRAIN_VAL_LEAKAGE_ROW_COUNT, + /** + * An enum member indicating that [Subtype] 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) { + ANOMALOUS_COLUMN_COUNT -> Value.ANOMALOUS_COLUMN_COUNT + CHARACTER_LENGTH -> Value.CHARACTER_LENGTH + CLASS_IMBALANCE_RATIO -> Value.CLASS_IMBALANCE_RATIO + EXPECT_COLUMN_A_TO_BE_IN_COLUMN_B -> Value.EXPECT_COLUMN_A_TO_BE_IN_COLUMN_B + COLUMN_AVERAGE -> Value.COLUMN_AVERAGE + COLUMN_DRIFT -> Value.COLUMN_DRIFT + COLUMN_STATISTIC -> Value.COLUMN_STATISTIC + COLUMN_VALUES_MATCH -> Value.COLUMN_VALUES_MATCH + CONFLICTING_LABEL_ROW_COUNT -> Value.CONFLICTING_LABEL_ROW_COUNT + CONTAINS_PII -> Value.CONTAINS_PII + CONTAINS_VALID_URL -> Value.CONTAINS_VALID_URL + CORRELATED_FEATURE_COUNT -> Value.CORRELATED_FEATURE_COUNT + CUSTOM_METRIC_THRESHOLD -> Value.CUSTOM_METRIC_THRESHOLD + DUPLICATE_ROW_COUNT -> Value.DUPLICATE_ROW_COUNT + EMPTY_FEATURE -> Value.EMPTY_FEATURE + EMPTY_FEATURE_COUNT -> Value.EMPTY_FEATURE_COUNT + DRIFTED_FEATURE_COUNT -> Value.DRIFTED_FEATURE_COUNT + FEATURE_MISSING_VALUES -> Value.FEATURE_MISSING_VALUES + FEATURE_VALUE_VALIDATION -> Value.FEATURE_VALUE_VALIDATION + GREAT_EXPECTATIONS -> Value.GREAT_EXPECTATIONS + GROUP_BY_COLUMN_STATS_CHECK -> Value.GROUP_BY_COLUMN_STATS_CHECK + ILL_FORMED_ROW_COUNT -> Value.ILL_FORMED_ROW_COUNT + IS_CODE -> Value.IS_CODE + IS_JSON -> Value.IS_JSON + LLM_RUBRIC_THRESHOLD_V2 -> Value.LLM_RUBRIC_THRESHOLD_V2 + LABEL_DRIFT -> Value.LABEL_DRIFT + METRIC_THRESHOLD -> Value.METRIC_THRESHOLD + NEW_CATEGORY_COUNT -> Value.NEW_CATEGORY_COUNT + NEW_LABEL_COUNT -> Value.NEW_LABEL_COUNT + NULL_ROW_COUNT -> Value.NULL_ROW_COUNT + ROW_COUNT -> Value.ROW_COUNT + PP_SCORE_VALUE_VALIDATION -> Value.PP_SCORE_VALUE_VALIDATION + QUASI_CONSTANT_FEATURE -> Value.QUASI_CONSTANT_FEATURE + QUASI_CONSTANT_FEATURE_COUNT -> Value.QUASI_CONSTANT_FEATURE_COUNT + SQL_QUERY -> Value.SQL_QUERY + DTYPE_VALIDATION -> Value.DTYPE_VALIDATION + SENTENCE_LENGTH -> Value.SENTENCE_LENGTH + SIZE_RATIO -> Value.SIZE_RATIO + SPECIAL_CHARACTERS_RATIO -> Value.SPECIAL_CHARACTERS_RATIO + STRING_VALIDATION -> Value.STRING_VALIDATION + TRAIN_VAL_LEAKAGE_ROW_COUNT -> Value.TRAIN_VAL_LEAKAGE_ROW_COUNT + 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 OpenlayerInvalidDataException if this class instance's value is a not a + * known member. + */ + fun known(): Known = + when (this) { + ANOMALOUS_COLUMN_COUNT -> Known.ANOMALOUS_COLUMN_COUNT + CHARACTER_LENGTH -> Known.CHARACTER_LENGTH + CLASS_IMBALANCE_RATIO -> Known.CLASS_IMBALANCE_RATIO + EXPECT_COLUMN_A_TO_BE_IN_COLUMN_B -> Known.EXPECT_COLUMN_A_TO_BE_IN_COLUMN_B + COLUMN_AVERAGE -> Known.COLUMN_AVERAGE + COLUMN_DRIFT -> Known.COLUMN_DRIFT + COLUMN_STATISTIC -> Known.COLUMN_STATISTIC + COLUMN_VALUES_MATCH -> Known.COLUMN_VALUES_MATCH + CONFLICTING_LABEL_ROW_COUNT -> Known.CONFLICTING_LABEL_ROW_COUNT + CONTAINS_PII -> Known.CONTAINS_PII + CONTAINS_VALID_URL -> Known.CONTAINS_VALID_URL + CORRELATED_FEATURE_COUNT -> Known.CORRELATED_FEATURE_COUNT + CUSTOM_METRIC_THRESHOLD -> Known.CUSTOM_METRIC_THRESHOLD + DUPLICATE_ROW_COUNT -> Known.DUPLICATE_ROW_COUNT + EMPTY_FEATURE -> Known.EMPTY_FEATURE + EMPTY_FEATURE_COUNT -> Known.EMPTY_FEATURE_COUNT + DRIFTED_FEATURE_COUNT -> Known.DRIFTED_FEATURE_COUNT + FEATURE_MISSING_VALUES -> Known.FEATURE_MISSING_VALUES + FEATURE_VALUE_VALIDATION -> Known.FEATURE_VALUE_VALIDATION + GREAT_EXPECTATIONS -> Known.GREAT_EXPECTATIONS + GROUP_BY_COLUMN_STATS_CHECK -> Known.GROUP_BY_COLUMN_STATS_CHECK + ILL_FORMED_ROW_COUNT -> Known.ILL_FORMED_ROW_COUNT + IS_CODE -> Known.IS_CODE + IS_JSON -> Known.IS_JSON + LLM_RUBRIC_THRESHOLD_V2 -> Known.LLM_RUBRIC_THRESHOLD_V2 + LABEL_DRIFT -> Known.LABEL_DRIFT + METRIC_THRESHOLD -> Known.METRIC_THRESHOLD + NEW_CATEGORY_COUNT -> Known.NEW_CATEGORY_COUNT + NEW_LABEL_COUNT -> Known.NEW_LABEL_COUNT + NULL_ROW_COUNT -> Known.NULL_ROW_COUNT + ROW_COUNT -> Known.ROW_COUNT + PP_SCORE_VALUE_VALIDATION -> Known.PP_SCORE_VALUE_VALIDATION + QUASI_CONSTANT_FEATURE -> Known.QUASI_CONSTANT_FEATURE + QUASI_CONSTANT_FEATURE_COUNT -> Known.QUASI_CONSTANT_FEATURE_COUNT + SQL_QUERY -> Known.SQL_QUERY + DTYPE_VALIDATION -> Known.DTYPE_VALIDATION + SENTENCE_LENGTH -> Known.SENTENCE_LENGTH + SIZE_RATIO -> Known.SIZE_RATIO + SPECIAL_CHARACTERS_RATIO -> Known.SPECIAL_CHARACTERS_RATIO + STRING_VALIDATION -> Known.STRING_VALIDATION + TRAIN_VAL_LEAKAGE_ROW_COUNT -> Known.TRAIN_VAL_LEAKAGE_ROW_COUNT + else -> throw OpenlayerInvalidDataException("Unknown Subtype: $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 OpenlayerInvalidDataException if this class instance's value does not + * have the expected primitive type. + */ + fun asString(): String = + _value().asString().orElseThrow { + OpenlayerInvalidDataException("Value is not a String") + } + + private var validated: Boolean = false + + fun validate(): Subtype = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OpenlayerInvalidDataException) { + false + } + + /** + * Returns a 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 Subtype && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + class Threshold + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val insightName: JsonField, + private val insightParameters: JsonField>, + private val measurement: JsonField, + private val operator: JsonField, + private val thresholdMode: JsonField, + private val value: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("insightName") + @ExcludeMissing + insightName: JsonField = JsonMissing.of(), + @JsonProperty("insightParameters") + @ExcludeMissing + insightParameters: JsonField> = JsonMissing.of(), + @JsonProperty("measurement") + @ExcludeMissing + measurement: JsonField = JsonMissing.of(), + @JsonProperty("operator") + @ExcludeMissing + operator: JsonField = JsonMissing.of(), + @JsonProperty("thresholdMode") + @ExcludeMissing + thresholdMode: JsonField = JsonMissing.of(), + @JsonProperty("value") + @ExcludeMissing + value: JsonField = JsonMissing.of(), + ) : this( + insightName, + insightParameters, + measurement, + operator, + thresholdMode, + value, + mutableMapOf(), + ) + + /** + * The insight name to be evaluated. + * + * @throws OpenlayerInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun insightName(): Optional = insightName.getOptional("insightName") + + /** + * The insight parameters. Required only for some test subtypes. For example, for + * tests that require a column name, the insight parameters will be + * [{'name': 'column_name', 'value': 'Age'}] + * + * @throws OpenlayerInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun insightParameters(): Optional> = + insightParameters.getOptional("insightParameters") + + /** + * The measurement to be evaluated. + * + * @throws OpenlayerInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun measurement(): Optional = measurement.getOptional("measurement") + + /** + * The operator to be used for the evaluation. + * + * @throws OpenlayerInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun operator(): Optional = operator.getOptional("operator") + + /** + * Whether to use automatic anomaly detection or manual thresholds + * + * @throws OpenlayerInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun thresholdMode(): Optional = + thresholdMode.getOptional("thresholdMode") + + /** + * The value to be compared. + * + * @throws OpenlayerInvalidDataException 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 [insightName]. + * + * Unlike [insightName], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("insightName") + @ExcludeMissing + fun _insightName(): JsonField = insightName + + /** + * Returns the raw JSON value of [insightParameters]. + * + * Unlike [insightParameters], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("insightParameters") + @ExcludeMissing + fun _insightParameters(): JsonField> = insightParameters + + /** + * Returns the raw JSON value of [measurement]. + * + * Unlike [measurement], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("measurement") + @ExcludeMissing + fun _measurement(): JsonField = measurement + + /** + * Returns the raw JSON value of [operator]. + * + * Unlike [operator], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("operator") + @ExcludeMissing + fun _operator(): JsonField = operator + + /** + * Returns the raw JSON value of [thresholdMode]. + * + * Unlike [thresholdMode], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("thresholdMode") + @ExcludeMissing + fun _thresholdMode(): JsonField = thresholdMode + + /** + * 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 [Threshold]. */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [Threshold]. */ + class Builder internal constructor() { + + private var insightName: JsonField = JsonMissing.of() + private var insightParameters: JsonField>? = null + private var measurement: JsonField = JsonMissing.of() + private var operator: JsonField = JsonMissing.of() + private var thresholdMode: JsonField = JsonMissing.of() + private var value: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(threshold: Threshold) = apply { + insightName = threshold.insightName + insightParameters = threshold.insightParameters.map { it.toMutableList() } + measurement = threshold.measurement + operator = threshold.operator + thresholdMode = threshold.thresholdMode + value = threshold.value + additionalProperties = threshold.additionalProperties.toMutableMap() + } + + /** The insight name to be evaluated. */ + fun insightName(insightName: InsightName) = + insightName(JsonField.of(insightName)) + + /** + * Sets [Builder.insightName] to an arbitrary JSON value. + * + * You should usually call [Builder.insightName] with a well-typed [InsightName] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun insightName(insightName: JsonField) = apply { + this.insightName = insightName + } + + /** + * The insight parameters. Required only for some test subtypes. For example, + * for tests that require a column name, the insight parameters will be + * [{'name': 'column_name', 'value': 'Age'}] + */ + fun insightParameters(insightParameters: List?) = + insightParameters(JsonField.ofNullable(insightParameters)) + + /** + * Alias for calling [Builder.insightParameters] with + * `insightParameters.orElse(null)`. + */ + fun insightParameters(insightParameters: Optional>) = + insightParameters(insightParameters.getOrNull()) + + /** + * Sets [Builder.insightParameters] to an arbitrary JSON value. + * + * You should usually call [Builder.insightParameters] with a well-typed + * `List` value instead. This method is primarily for setting + * the field to an undocumented or not yet supported value. + */ + fun insightParameters(insightParameters: JsonField>) = + apply { + this.insightParameters = insightParameters.map { it.toMutableList() } + } + + /** + * Adds a single [InsightParameter] to [insightParameters]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addInsightParameter(insightParameter: InsightParameter) = apply { + insightParameters = + (insightParameters ?: JsonField.of(mutableListOf())).also { + checkKnown("insightParameters", it).add(insightParameter) + } + } + + /** The measurement to be evaluated. */ + fun measurement(measurement: String) = measurement(JsonField.of(measurement)) + + /** + * Sets [Builder.measurement] to an arbitrary JSON value. + * + * You should usually call [Builder.measurement] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun measurement(measurement: JsonField) = apply { + this.measurement = measurement + } + + /** The operator to be used for the evaluation. */ + fun operator(operator: Operator) = operator(JsonField.of(operator)) + + /** + * Sets [Builder.operator] to an arbitrary JSON value. + * + * You should usually call [Builder.operator] with a well-typed [Operator] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun operator(operator: JsonField) = apply { this.operator = operator } + + /** Whether to use automatic anomaly detection or manual thresholds */ + fun thresholdMode(thresholdMode: ThresholdMode) = + thresholdMode(JsonField.of(thresholdMode)) + + /** + * Sets [Builder.thresholdMode] to an arbitrary JSON value. + * + * You should usually call [Builder.thresholdMode] with a well-typed + * [ThresholdMode] value instead. This method is primarily for setting the field + * to an undocumented or not yet supported value. + */ + fun thresholdMode(thresholdMode: JsonField) = apply { + this.thresholdMode = thresholdMode + } + + /** The value to be compared. */ + fun value(value: Value) = value(JsonField.of(value)) + + /** + * Sets [Builder.value] to an arbitrary JSON value. + * + * You should usually call [Builder.value] with a well-typed [Value] 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 } + + /** Alias for calling [value] with `Value.ofNumber(number)`. */ + fun value(number: Double) = value(Value.ofNumber(number)) + + /** Alias for calling [value] with `Value.ofBool(bool)`. */ + fun value(bool: Boolean) = value(Value.ofBool(bool)) + + /** Alias for calling [value] with `Value.ofString(string)`. */ + fun value(string: String) = value(Value.ofString(string)) + + /** Alias for calling [value] with `Value.ofStrings(strings)`. */ + fun valueOfStrings(strings: List) = value(Value.ofStrings(strings)) + + 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 [Threshold]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): Threshold = + Threshold( + insightName, + (insightParameters ?: JsonMissing.of()).map { it.toImmutable() }, + measurement, + operator, + thresholdMode, + value, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): Threshold = apply { + if (validated) { + return@apply + } + + insightName().ifPresent { it.validate() } + insightParameters().ifPresent { it.forEach { it.validate() } } + measurement() + operator().ifPresent { it.validate() } + thresholdMode().ifPresent { it.validate() } + value().ifPresent { it.validate() } + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OpenlayerInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (insightName.asKnown().getOrNull()?.validity() ?: 0) + + (insightParameters.asKnown().getOrNull()?.sumOf { it.validity().toInt() } + ?: 0) + + (if (measurement.asKnown().isPresent) 1 else 0) + + (operator.asKnown().getOrNull()?.validity() ?: 0) + + (thresholdMode.asKnown().getOrNull()?.validity() ?: 0) + + (value.asKnown().getOrNull()?.validity() ?: 0) + + /** The insight name to be evaluated. */ + class InsightName + @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 CHARACTER_LENGTH = of("characterLength") + + @JvmField val CLASS_IMBALANCE = of("classImbalance") + + @JvmField + val EXPECT_COLUMN_A_TO_BE_IN_COLUMN_B = of("expectColumnAToBeInColumnB") + + @JvmField val COLUMN_AVERAGE = of("columnAverage") + + @JvmField val COLUMN_DRIFT = of("columnDrift") + + @JvmField val COLUMN_VALUES_MATCH = of("columnValuesMatch") + + @JvmField val CONFIDENCE_DISTRIBUTION = of("confidenceDistribution") + + @JvmField val CONFLICTING_LABEL_ROW_COUNT = of("conflictingLabelRowCount") + + @JvmField val CONTAINS_PII = of("containsPii") + + @JvmField val CONTAINS_VALID_URL = of("containsValidUrl") + + @JvmField val CORRELATED_FEATURES = of("correlatedFeatures") + + @JvmField val CUSTOM_METRIC = of("customMetric") + + @JvmField val DUPLICATE_ROW_COUNT = of("duplicateRowCount") + + @JvmField val EMPTY_FEATURES = of("emptyFeatures") + + @JvmField val FEATURE_DRIFT = of("featureDrift") + + @JvmField val FEATURE_PROFILE = of("featureProfile") + + @JvmField val GREAT_EXPECTATIONS = of("greatExpectations") + + @JvmField val GROUP_BY_COLUMN_STATS_CHECK = of("groupByColumnStatsCheck") + + @JvmField val ILL_FORMED_ROW_COUNT = of("illFormedRowCount") + + @JvmField val IS_CODE = of("isCode") + + @JvmField val IS_JSON = of("isJson") + + @JvmField val LLM_RUBRIC_V2 = of("llmRubricV2") + + @JvmField val LABEL_DRIFT = of("labelDrift") + + @JvmField val METRICS = of("metrics") + + @JvmField val NEW_CATEGORIES = of("newCategories") + + @JvmField val NEW_LABELS = of("newLabels") + + @JvmField val NULL_ROW_COUNT = of("nullRowCount") + + @JvmField val PP_SCORE = of("ppScore") + + @JvmField val QUASI_CONSTANT_FEATURES = of("quasiConstantFeatures") + + @JvmField val SENTENCE_LENGTH = of("sentenceLength") + + @JvmField val SIZE_RATIO = of("sizeRatio") + + @JvmField val SPECIAL_CHARACTERS = of("specialCharacters") + + @JvmField val STRING_VALIDATION = of("stringValidation") + + @JvmField val TRAIN_VAL_LEAKAGE_ROW_COUNT = of("trainValLeakageRowCount") + + @JvmStatic fun of(value: String) = InsightName(JsonField.of(value)) + } + + /** An enum containing [InsightName]'s known values. */ + enum class Known { + CHARACTER_LENGTH, + CLASS_IMBALANCE, + EXPECT_COLUMN_A_TO_BE_IN_COLUMN_B, + COLUMN_AVERAGE, + COLUMN_DRIFT, + COLUMN_VALUES_MATCH, + CONFIDENCE_DISTRIBUTION, + CONFLICTING_LABEL_ROW_COUNT, + CONTAINS_PII, + CONTAINS_VALID_URL, + CORRELATED_FEATURES, + CUSTOM_METRIC, + DUPLICATE_ROW_COUNT, + EMPTY_FEATURES, + FEATURE_DRIFT, + FEATURE_PROFILE, + GREAT_EXPECTATIONS, + GROUP_BY_COLUMN_STATS_CHECK, + ILL_FORMED_ROW_COUNT, + IS_CODE, + IS_JSON, + LLM_RUBRIC_V2, + LABEL_DRIFT, + METRICS, + NEW_CATEGORIES, + NEW_LABELS, + NULL_ROW_COUNT, + PP_SCORE, + QUASI_CONSTANT_FEATURES, + SENTENCE_LENGTH, + SIZE_RATIO, + SPECIAL_CHARACTERS, + STRING_VALIDATION, + TRAIN_VAL_LEAKAGE_ROW_COUNT, + } + + /** + * An enum containing [InsightName]'s known values, as well as an [_UNKNOWN] + * member. + * + * An instance of [InsightName] 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 { + CHARACTER_LENGTH, + CLASS_IMBALANCE, + EXPECT_COLUMN_A_TO_BE_IN_COLUMN_B, + COLUMN_AVERAGE, + COLUMN_DRIFT, + COLUMN_VALUES_MATCH, + CONFIDENCE_DISTRIBUTION, + CONFLICTING_LABEL_ROW_COUNT, + CONTAINS_PII, + CONTAINS_VALID_URL, + CORRELATED_FEATURES, + CUSTOM_METRIC, + DUPLICATE_ROW_COUNT, + EMPTY_FEATURES, + FEATURE_DRIFT, + FEATURE_PROFILE, + GREAT_EXPECTATIONS, + GROUP_BY_COLUMN_STATS_CHECK, + ILL_FORMED_ROW_COUNT, + IS_CODE, + IS_JSON, + LLM_RUBRIC_V2, + LABEL_DRIFT, + METRICS, + NEW_CATEGORIES, + NEW_LABELS, + NULL_ROW_COUNT, + PP_SCORE, + QUASI_CONSTANT_FEATURES, + SENTENCE_LENGTH, + SIZE_RATIO, + SPECIAL_CHARACTERS, + STRING_VALIDATION, + TRAIN_VAL_LEAKAGE_ROW_COUNT, + /** + * An enum member indicating that [InsightName] 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) { + CHARACTER_LENGTH -> Value.CHARACTER_LENGTH + CLASS_IMBALANCE -> Value.CLASS_IMBALANCE + EXPECT_COLUMN_A_TO_BE_IN_COLUMN_B -> + Value.EXPECT_COLUMN_A_TO_BE_IN_COLUMN_B + COLUMN_AVERAGE -> Value.COLUMN_AVERAGE + COLUMN_DRIFT -> Value.COLUMN_DRIFT + COLUMN_VALUES_MATCH -> Value.COLUMN_VALUES_MATCH + CONFIDENCE_DISTRIBUTION -> Value.CONFIDENCE_DISTRIBUTION + CONFLICTING_LABEL_ROW_COUNT -> Value.CONFLICTING_LABEL_ROW_COUNT + CONTAINS_PII -> Value.CONTAINS_PII + CONTAINS_VALID_URL -> Value.CONTAINS_VALID_URL + CORRELATED_FEATURES -> Value.CORRELATED_FEATURES + CUSTOM_METRIC -> Value.CUSTOM_METRIC + DUPLICATE_ROW_COUNT -> Value.DUPLICATE_ROW_COUNT + EMPTY_FEATURES -> Value.EMPTY_FEATURES + FEATURE_DRIFT -> Value.FEATURE_DRIFT + FEATURE_PROFILE -> Value.FEATURE_PROFILE + GREAT_EXPECTATIONS -> Value.GREAT_EXPECTATIONS + GROUP_BY_COLUMN_STATS_CHECK -> Value.GROUP_BY_COLUMN_STATS_CHECK + ILL_FORMED_ROW_COUNT -> Value.ILL_FORMED_ROW_COUNT + IS_CODE -> Value.IS_CODE + IS_JSON -> Value.IS_JSON + LLM_RUBRIC_V2 -> Value.LLM_RUBRIC_V2 + LABEL_DRIFT -> Value.LABEL_DRIFT + METRICS -> Value.METRICS + NEW_CATEGORIES -> Value.NEW_CATEGORIES + NEW_LABELS -> Value.NEW_LABELS + NULL_ROW_COUNT -> Value.NULL_ROW_COUNT + PP_SCORE -> Value.PP_SCORE + QUASI_CONSTANT_FEATURES -> Value.QUASI_CONSTANT_FEATURES + SENTENCE_LENGTH -> Value.SENTENCE_LENGTH + SIZE_RATIO -> Value.SIZE_RATIO + SPECIAL_CHARACTERS -> Value.SPECIAL_CHARACTERS + STRING_VALIDATION -> Value.STRING_VALIDATION + TRAIN_VAL_LEAKAGE_ROW_COUNT -> Value.TRAIN_VAL_LEAKAGE_ROW_COUNT + 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 OpenlayerInvalidDataException if this class instance's value is a not + * a known member. + */ + fun known(): Known = + when (this) { + CHARACTER_LENGTH -> Known.CHARACTER_LENGTH + CLASS_IMBALANCE -> Known.CLASS_IMBALANCE + EXPECT_COLUMN_A_TO_BE_IN_COLUMN_B -> + Known.EXPECT_COLUMN_A_TO_BE_IN_COLUMN_B + COLUMN_AVERAGE -> Known.COLUMN_AVERAGE + COLUMN_DRIFT -> Known.COLUMN_DRIFT + COLUMN_VALUES_MATCH -> Known.COLUMN_VALUES_MATCH + CONFIDENCE_DISTRIBUTION -> Known.CONFIDENCE_DISTRIBUTION + CONFLICTING_LABEL_ROW_COUNT -> Known.CONFLICTING_LABEL_ROW_COUNT + CONTAINS_PII -> Known.CONTAINS_PII + CONTAINS_VALID_URL -> Known.CONTAINS_VALID_URL + CORRELATED_FEATURES -> Known.CORRELATED_FEATURES + CUSTOM_METRIC -> Known.CUSTOM_METRIC + DUPLICATE_ROW_COUNT -> Known.DUPLICATE_ROW_COUNT + EMPTY_FEATURES -> Known.EMPTY_FEATURES + FEATURE_DRIFT -> Known.FEATURE_DRIFT + FEATURE_PROFILE -> Known.FEATURE_PROFILE + GREAT_EXPECTATIONS -> Known.GREAT_EXPECTATIONS + GROUP_BY_COLUMN_STATS_CHECK -> Known.GROUP_BY_COLUMN_STATS_CHECK + ILL_FORMED_ROW_COUNT -> Known.ILL_FORMED_ROW_COUNT + IS_CODE -> Known.IS_CODE + IS_JSON -> Known.IS_JSON + LLM_RUBRIC_V2 -> Known.LLM_RUBRIC_V2 + LABEL_DRIFT -> Known.LABEL_DRIFT + METRICS -> Known.METRICS + NEW_CATEGORIES -> Known.NEW_CATEGORIES + NEW_LABELS -> Known.NEW_LABELS + NULL_ROW_COUNT -> Known.NULL_ROW_COUNT + PP_SCORE -> Known.PP_SCORE + QUASI_CONSTANT_FEATURES -> Known.QUASI_CONSTANT_FEATURES + SENTENCE_LENGTH -> Known.SENTENCE_LENGTH + SIZE_RATIO -> Known.SIZE_RATIO + SPECIAL_CHARACTERS -> Known.SPECIAL_CHARACTERS + STRING_VALIDATION -> Known.STRING_VALIDATION + TRAIN_VAL_LEAKAGE_ROW_COUNT -> Known.TRAIN_VAL_LEAKAGE_ROW_COUNT + else -> + throw OpenlayerInvalidDataException("Unknown InsightName: $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 OpenlayerInvalidDataException if this class instance's value does not + * have the expected primitive type. + */ + fun asString(): String = + _value().asString().orElseThrow { + OpenlayerInvalidDataException("Value is not a String") + } + + private var validated: Boolean = false + + fun validate(): InsightName = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OpenlayerInvalidDataException) { + false + } + + /** + * Returns a 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 InsightName && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + class InsightParameter + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val name: JsonField, + private val value: JsonValue, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("name") + @ExcludeMissing + name: JsonField = JsonMissing.of(), + @JsonProperty("value") @ExcludeMissing value: JsonValue = JsonMissing.of(), + ) : this(name, value, mutableMapOf()) + + /** + * The name of the insight filter. + * + * @throws OpenlayerInvalidDataException if 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") + + @JsonProperty("value") @ExcludeMissing fun _value(): JsonValue = value + + /** + * Returns the raw JSON value of [name]. + * + * Unlike [name], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("name") @ExcludeMissing fun _name(): JsonField = name + + @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 + * [InsightParameter]. + * + * The following fields are required: + * ```java + * .name() + * .value() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [InsightParameter]. */ + class Builder internal constructor() { + + private var name: JsonField? = null + private var value: JsonValue? = null + private var additionalProperties: MutableMap = + mutableMapOf() + + @JvmSynthetic + internal fun from(insightParameter: InsightParameter) = apply { + name = insightParameter.name + value = insightParameter.value + additionalProperties = + insightParameter.additionalProperties.toMutableMap() + } + + /** The name of the insight filter. */ + 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 } + + fun value(value: JsonValue) = 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 [InsightParameter]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .name() + * .value() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): InsightParameter = + InsightParameter( + checkRequired("name", name), + checkRequired("value", value), + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): InsightParameter = apply { + if (validated) { + return@apply + } + + name() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OpenlayerInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = (if (name.asKnown().isPresent) 1 else 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is InsightParameter && + name == other.name && + value == other.value && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(name, value, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "InsightParameter{name=$name, value=$value, additionalProperties=$additionalProperties}" + } + + /** The operator to be used for the evaluation. */ + class Operator + @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 IS = of("is") + + @JvmField val GREATER = of(">") + + @JvmField val GREATER_OR_EQUALS = of(">=") + + @JvmField val LESS = of("<") + + @JvmField val LESS_OR_EQUALS = of("<=") + + @JvmField val NOT_EQUALS = of("!=") + + @JvmStatic fun of(value: String) = Operator(JsonField.of(value)) + } + + /** An enum containing [Operator]'s known values. */ + enum class Known { + IS, + GREATER, + GREATER_OR_EQUALS, + LESS, + LESS_OR_EQUALS, + NOT_EQUALS, + } + + /** + * An enum containing [Operator]'s known values, as well as an [_UNKNOWN] + * member. + * + * An instance of [Operator] 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 { + IS, + GREATER, + GREATER_OR_EQUALS, + LESS, + LESS_OR_EQUALS, + NOT_EQUALS, + /** + * An enum member indicating that [Operator] 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) { + IS -> Value.IS + GREATER -> Value.GREATER + GREATER_OR_EQUALS -> Value.GREATER_OR_EQUALS + LESS -> Value.LESS + LESS_OR_EQUALS -> Value.LESS_OR_EQUALS + NOT_EQUALS -> Value.NOT_EQUALS + 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 OpenlayerInvalidDataException if this class instance's value is a not + * a known member. + */ + fun known(): Known = + when (this) { + IS -> Known.IS + GREATER -> Known.GREATER + GREATER_OR_EQUALS -> Known.GREATER_OR_EQUALS + LESS -> Known.LESS + LESS_OR_EQUALS -> Known.LESS_OR_EQUALS + NOT_EQUALS -> Known.NOT_EQUALS + else -> throw OpenlayerInvalidDataException("Unknown Operator: $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 OpenlayerInvalidDataException if this class instance's value does not + * have the expected primitive type. + */ + fun asString(): String = + _value().asString().orElseThrow { + OpenlayerInvalidDataException("Value is not a String") + } + + private var validated: Boolean = false + + fun validate(): Operator = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OpenlayerInvalidDataException) { + false + } + + /** + * Returns a 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 Operator && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + /** Whether to use automatic anomaly detection or manual thresholds */ + class ThresholdMode + @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 AUTOMATIC = of("automatic") + + @JvmField val MANUAL = of("manual") + + @JvmStatic fun of(value: String) = ThresholdMode(JsonField.of(value)) + } + + /** An enum containing [ThresholdMode]'s known values. */ + enum class Known { + AUTOMATIC, + MANUAL, + } + + /** + * An enum containing [ThresholdMode]'s known values, as well as an [_UNKNOWN] + * member. + * + * An instance of [ThresholdMode] 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 { + AUTOMATIC, + MANUAL, + /** + * An enum member indicating that [ThresholdMode] 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) { + AUTOMATIC -> Value.AUTOMATIC + MANUAL -> Value.MANUAL + 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 OpenlayerInvalidDataException if this class instance's value is a not + * a known member. + */ + fun known(): Known = + when (this) { + AUTOMATIC -> Known.AUTOMATIC + MANUAL -> Known.MANUAL + else -> + throw OpenlayerInvalidDataException("Unknown ThresholdMode: $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 OpenlayerInvalidDataException if this class instance's value does not + * have the expected primitive type. + */ + fun asString(): String = + _value().asString().orElseThrow { + OpenlayerInvalidDataException("Value is not a String") + } + + private var validated: Boolean = false + + fun validate(): ThresholdMode = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OpenlayerInvalidDataException) { + false + } + + /** + * Returns a 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 ThresholdMode && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + /** The value to be compared. */ + @JsonDeserialize(using = Value.Deserializer::class) + @JsonSerialize(using = Value.Serializer::class) + class Value + private constructor( + private val number: Double? = null, + private val bool: Boolean? = null, + private val string: String? = null, + private val strings: List? = null, + private val _json: JsonValue? = null, + ) { + + fun number(): Optional = Optional.ofNullable(number) + + fun bool(): Optional = Optional.ofNullable(bool) + + fun string(): Optional = Optional.ofNullable(string) + + fun strings(): Optional> = Optional.ofNullable(strings) + + fun isNumber(): Boolean = number != null + + fun isBool(): Boolean = bool != null + + fun isString(): Boolean = string != null + + fun isStrings(): Boolean = strings != null + + fun asNumber(): Double = number.getOrThrow("number") + + fun asBool(): Boolean = bool.getOrThrow("bool") + + fun asString(): String = string.getOrThrow("string") + + fun asStrings(): List = strings.getOrThrow("strings") + + fun _json(): Optional = Optional.ofNullable(_json) + + fun accept(visitor: Visitor): T = + when { + number != null -> visitor.visitNumber(number) + bool != null -> visitor.visitBool(bool) + string != null -> visitor.visitString(string) + strings != null -> visitor.visitStrings(strings) + else -> visitor.unknown(_json) + } + + private var validated: Boolean = false + + fun validate(): Value = apply { + if (validated) { + return@apply + } + + accept( + object : Visitor { + override fun visitNumber(number: Double) {} + + override fun visitBool(bool: Boolean) {} + + override fun visitString(string: String) {} + + override fun visitStrings(strings: List) {} + } + ) + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OpenlayerInvalidDataException) { + false + } + + /** + * Returns 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 visitNumber(number: Double) = 1 + + override fun visitBool(bool: Boolean) = 1 + + override fun visitString(string: String) = 1 + + override fun visitStrings(strings: List) = strings.size + + override fun unknown(json: JsonValue?) = 0 + } + ) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Value && + number == other.number && + bool == other.bool && + string == other.string && + strings == other.strings + } + + override fun hashCode(): Int = Objects.hash(number, bool, string, strings) + + override fun toString(): String = + when { + number != null -> "Value{number=$number}" + bool != null -> "Value{bool=$bool}" + string != null -> "Value{string=$string}" + strings != null -> "Value{strings=$strings}" + _json != null -> "Value{_unknown=$_json}" + else -> throw IllegalStateException("Invalid Value") + } + + companion object { + + @JvmStatic fun ofNumber(number: Double) = Value(number = number) + + @JvmStatic fun ofBool(bool: Boolean) = Value(bool = bool) + + @JvmStatic fun ofString(string: String) = Value(string = string) + + @JvmStatic + fun ofStrings(strings: List) = + Value(strings = strings.toImmutable()) + } + + /** + * An interface that defines how to map each variant of [Value] to a value of + * type [T]. + */ + interface Visitor { + + fun visitNumber(number: Double): T + + fun visitBool(bool: Boolean): T + + fun visitString(string: String): T + + fun visitStrings(strings: List): T + + /** + * Maps an unknown variant of [Value] to a value of type [T]. + * + * An instance of [Value] 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 OpenlayerInvalidDataException in the default implementation. + */ + fun unknown(json: JsonValue?): T { + throw OpenlayerInvalidDataException("Unknown Value: $json") + } + } + + internal class Deserializer : BaseDeserializer(Value::class) { + + override fun ObjectCodec.deserialize(node: JsonNode): Value { + val json = JsonValue.fromJsonNode(node) + + val bestMatches = + sequenceOf( + tryDeserialize(node, jacksonTypeRef())?.let { + Value(number = it, _json = json) + }, + tryDeserialize(node, jacksonTypeRef())?.let { + Value(bool = it, _json = json) + }, + tryDeserialize(node, jacksonTypeRef())?.let { + Value(string = it, _json = json) + }, + tryDeserialize(node, jacksonTypeRef>())?.let { + Value(strings = it, _json = json) + }, + ) + .filterNotNull() + .allMaxBy { it.validity() } + .toList() + return when (bestMatches.size) { + // This can happen if what we're deserializing is completely + // incompatible with all the possible variants (e.g. deserializing + // from object). + 0 -> Value(_json = json) + 1 -> bestMatches.single() + // If there's more than one match with the highest validity, then + // use the first completely valid match, or simply the first match + // if none are completely valid. + else -> + bestMatches.firstOrNull { it.isValid() } ?: bestMatches.first() + } + } + } + + internal class Serializer : BaseSerializer(Value::class) { + + override fun serialize( + value: Value, + generator: JsonGenerator, + provider: SerializerProvider, + ) { + when { + value.number != null -> generator.writeObject(value.number) + value.bool != null -> generator.writeObject(value.bool) + value.string != null -> generator.writeObject(value.string) + value.strings != null -> generator.writeObject(value.strings) + value._json != null -> generator.writeObject(value._json) + else -> throw IllegalStateException("Invalid Value") + } + } + } + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Threshold && + insightName == other.insightName && + insightParameters == other.insightParameters && + measurement == other.measurement && + operator == other.operator && + thresholdMode == other.thresholdMode && + value == other.value && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + insightName, + insightParameters, + measurement, + operator, + thresholdMode, + value, + additionalProperties, + ) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Threshold{insightName=$insightName, insightParameters=$insightParameters, measurement=$measurement, operator=$operator, thresholdMode=$thresholdMode, value=$value, additionalProperties=$additionalProperties}" + } + + /** The test 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 INTEGRITY = of("integrity") + + @JvmField val CONSISTENCY = of("consistency") + + @JvmField val PERFORMANCE = of("performance") + + @JvmStatic fun of(value: String) = Type(JsonField.of(value)) + } + + /** An enum containing [Type]'s known values. */ + enum class Known { + INTEGRITY, + CONSISTENCY, + PERFORMANCE, + } + + /** + * 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 { + INTEGRITY, + CONSISTENCY, + PERFORMANCE, + /** + * 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) { + INTEGRITY -> Value.INTEGRITY + CONSISTENCY -> Value.CONSISTENCY + PERFORMANCE -> Value.PERFORMANCE + 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 OpenlayerInvalidDataException if this class instance's value is a not a + * known member. + */ + fun known(): Known = + when (this) { + INTEGRITY -> Known.INTEGRITY + CONSISTENCY -> Known.CONSISTENCY + PERFORMANCE -> Known.PERFORMANCE + else -> throw OpenlayerInvalidDataException("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 OpenlayerInvalidDataException if this class instance's value does not + * have the expected primitive type. + */ + fun asString(): String = + _value().asString().orElseThrow { + OpenlayerInvalidDataException("Value is not a String") + } + + private var validated: Boolean = false + + fun validate(): Type = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OpenlayerInvalidDataException) { + false + } + + /** + * Returns a 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 Goal && + id == other.id && + commentCount == other.commentCount && + creatorId == other.creatorId && + dateArchived == other.dateArchived && + dateCreated == other.dateCreated && + dateUpdated == other.dateUpdated && + description == other.description && + name == other.name && + number == other.number && + originProjectVersionId == other.originProjectVersionId && + subtype == other.subtype && + suggested == other.suggested && + thresholds == other.thresholds && + type == other.type && + archived == other.archived && + delayWindow == other.delayWindow && + evaluationWindow == other.evaluationWindow && + usesMlModel == other.usesMlModel && + usesProductionData == other.usesProductionData && + usesReferenceDataset == other.usesReferenceDataset && + usesTrainingDataset == other.usesTrainingDataset && + usesValidationDataset == other.usesValidationDataset && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + id, + commentCount, + creatorId, + dateArchived, + dateCreated, + dateUpdated, + description, + name, + number, + originProjectVersionId, + subtype, + suggested, + thresholds, + type, + archived, + delayWindow, + evaluationWindow, + usesMlModel, + usesProductionData, + usesReferenceDataset, + usesTrainingDataset, + usesValidationDataset, + additionalProperties, + ) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Goal{id=$id, commentCount=$commentCount, creatorId=$creatorId, dateArchived=$dateArchived, dateCreated=$dateCreated, dateUpdated=$dateUpdated, description=$description, name=$name, number=$number, originProjectVersionId=$originProjectVersionId, subtype=$subtype, suggested=$suggested, thresholds=$thresholds, type=$type, archived=$archived, delayWindow=$delayWindow, evaluationWindow=$evaluationWindow, usesMlModel=$usesMlModel, usesProductionData=$usesProductionData, usesReferenceDataset=$usesReferenceDataset, usesTrainingDataset=$usesTrainingDataset, usesValidationDataset=$usesValidationDataset, additionalProperties=$additionalProperties}" + } + + /** The body of the rows request. */ + class RowsBody + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val columnFilters: JsonField>, + private val excludeRowIdList: JsonField>, + private val notSearchQueryAnd: JsonField>, + private val notSearchQueryOr: JsonField>, + private val rowIdList: JsonField>, + private val searchQueryAnd: JsonField>, + private val searchQueryOr: JsonField>, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("columnFilters") + @ExcludeMissing + columnFilters: JsonField> = JsonMissing.of(), + @JsonProperty("excludeRowIdList") + @ExcludeMissing + excludeRowIdList: JsonField> = JsonMissing.of(), + @JsonProperty("notSearchQueryAnd") + @ExcludeMissing + notSearchQueryAnd: JsonField> = JsonMissing.of(), + @JsonProperty("notSearchQueryOr") + @ExcludeMissing + notSearchQueryOr: JsonField> = JsonMissing.of(), + @JsonProperty("rowIdList") + @ExcludeMissing + rowIdList: JsonField> = JsonMissing.of(), + @JsonProperty("searchQueryAnd") + @ExcludeMissing + searchQueryAnd: JsonField> = JsonMissing.of(), + @JsonProperty("searchQueryOr") + @ExcludeMissing + searchQueryOr: JsonField> = JsonMissing.of(), + ) : this( + columnFilters, + excludeRowIdList, + notSearchQueryAnd, + notSearchQueryOr, + rowIdList, + searchQueryAnd, + searchQueryOr, + mutableMapOf(), + ) + + /** + * @throws OpenlayerInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun columnFilters(): Optional> = + columnFilters.getOptional("columnFilters") + + /** + * @throws OpenlayerInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun excludeRowIdList(): Optional> = + excludeRowIdList.getOptional("excludeRowIdList") + + /** + * @throws OpenlayerInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun notSearchQueryAnd(): Optional> = + notSearchQueryAnd.getOptional("notSearchQueryAnd") + + /** + * @throws OpenlayerInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun notSearchQueryOr(): Optional> = + notSearchQueryOr.getOptional("notSearchQueryOr") + + /** + * @throws OpenlayerInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun rowIdList(): Optional> = rowIdList.getOptional("rowIdList") + + /** + * @throws OpenlayerInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun searchQueryAnd(): Optional> = + searchQueryAnd.getOptional("searchQueryAnd") + + /** + * @throws OpenlayerInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun searchQueryOr(): Optional> = searchQueryOr.getOptional("searchQueryOr") + + /** + * Returns the raw JSON value of [columnFilters]. + * + * Unlike [columnFilters], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("columnFilters") + @ExcludeMissing + fun _columnFilters(): JsonField> = columnFilters + + /** + * Returns the raw JSON value of [excludeRowIdList]. + * + * Unlike [excludeRowIdList], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("excludeRowIdList") + @ExcludeMissing + fun _excludeRowIdList(): JsonField> = excludeRowIdList + + /** + * Returns the raw JSON value of [notSearchQueryAnd]. + * + * Unlike [notSearchQueryAnd], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("notSearchQueryAnd") + @ExcludeMissing + fun _notSearchQueryAnd(): JsonField> = notSearchQueryAnd + + /** + * Returns the raw JSON value of [notSearchQueryOr]. + * + * Unlike [notSearchQueryOr], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("notSearchQueryOr") + @ExcludeMissing + fun _notSearchQueryOr(): JsonField> = notSearchQueryOr + + /** + * Returns the raw JSON value of [rowIdList]. + * + * Unlike [rowIdList], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("rowIdList") + @ExcludeMissing + fun _rowIdList(): JsonField> = rowIdList + + /** + * Returns the raw JSON value of [searchQueryAnd]. + * + * Unlike [searchQueryAnd], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("searchQueryAnd") + @ExcludeMissing + fun _searchQueryAnd(): JsonField> = searchQueryAnd + + /** + * Returns the raw JSON value of [searchQueryOr]. + * + * Unlike [searchQueryOr], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("searchQueryOr") + @ExcludeMissing + fun _searchQueryOr(): JsonField> = searchQueryOr + + @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 [RowsBody]. */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [RowsBody]. */ + class Builder internal constructor() { + + private var columnFilters: JsonField>? = null + private var excludeRowIdList: JsonField>? = null + private var notSearchQueryAnd: JsonField>? = null + private var notSearchQueryOr: JsonField>? = null + private var rowIdList: JsonField>? = null + private var searchQueryAnd: JsonField>? = null + private var searchQueryOr: JsonField>? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(rowsBody: RowsBody) = apply { + columnFilters = rowsBody.columnFilters.map { it.toMutableList() } + excludeRowIdList = rowsBody.excludeRowIdList.map { it.toMutableList() } + notSearchQueryAnd = rowsBody.notSearchQueryAnd.map { it.toMutableList() } + notSearchQueryOr = rowsBody.notSearchQueryOr.map { it.toMutableList() } + rowIdList = rowsBody.rowIdList.map { it.toMutableList() } + searchQueryAnd = rowsBody.searchQueryAnd.map { it.toMutableList() } + searchQueryOr = rowsBody.searchQueryOr.map { it.toMutableList() } + additionalProperties = rowsBody.additionalProperties.toMutableMap() + } + + fun columnFilters(columnFilters: List?) = + columnFilters(JsonField.ofNullable(columnFilters)) + + /** Alias for calling [Builder.columnFilters] with `columnFilters.orElse(null)`. */ + fun columnFilters(columnFilters: Optional>) = + columnFilters(columnFilters.getOrNull()) + + /** + * Sets [Builder.columnFilters] to an arbitrary JSON value. + * + * You should usually call [Builder.columnFilters] with a well-typed + * `List` value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. + */ + fun columnFilters(columnFilters: JsonField>) = apply { + this.columnFilters = columnFilters.map { it.toMutableList() } + } + + /** + * Adds a single [ColumnFilter] to [columnFilters]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addColumnFilter(columnFilter: ColumnFilter) = apply { + columnFilters = + (columnFilters ?: JsonField.of(mutableListOf())).also { + checkKnown("columnFilters", it).add(columnFilter) + } + } + + /** Alias for calling [addColumnFilter] with `ColumnFilter.ofSet(set)`. */ + fun addColumnFilter(set: ColumnFilter.SetColumnFilter) = + addColumnFilter(ColumnFilter.ofSet(set)) + + /** Alias for calling [addColumnFilter] with `ColumnFilter.ofNumeric(numeric)`. */ + fun addColumnFilter(numeric: ColumnFilter.NumericColumnFilter) = + addColumnFilter(ColumnFilter.ofNumeric(numeric)) + + /** Alias for calling [addColumnFilter] with `ColumnFilter.ofString(string)`. */ + fun addColumnFilter(string: ColumnFilter.StringColumnFilter) = + addColumnFilter(ColumnFilter.ofString(string)) + + fun excludeRowIdList(excludeRowIdList: List?) = + excludeRowIdList(JsonField.ofNullable(excludeRowIdList)) + + /** + * Alias for calling [Builder.excludeRowIdList] with + * `excludeRowIdList.orElse(null)`. + */ + fun excludeRowIdList(excludeRowIdList: Optional>) = + excludeRowIdList(excludeRowIdList.getOrNull()) + + /** + * Sets [Builder.excludeRowIdList] to an arbitrary JSON value. + * + * You should usually call [Builder.excludeRowIdList] with a well-typed `List` + * value instead. This method is primarily for setting the field to an undocumented + * or not yet supported value. + */ + fun excludeRowIdList(excludeRowIdList: JsonField>) = apply { + this.excludeRowIdList = excludeRowIdList.map { it.toMutableList() } + } + + /** + * Adds a single [Long] to [Builder.excludeRowIdList]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addExcludeRowIdList(excludeRowIdList: Long) = apply { + this.excludeRowIdList = + (this.excludeRowIdList ?: JsonField.of(mutableListOf())).also { + checkKnown("excludeRowIdList", it).add(excludeRowIdList) + } + } + + fun notSearchQueryAnd(notSearchQueryAnd: List?) = + notSearchQueryAnd(JsonField.ofNullable(notSearchQueryAnd)) + + /** + * Alias for calling [Builder.notSearchQueryAnd] with + * `notSearchQueryAnd.orElse(null)`. + */ + fun notSearchQueryAnd(notSearchQueryAnd: Optional>) = + notSearchQueryAnd(notSearchQueryAnd.getOrNull()) + + /** + * Sets [Builder.notSearchQueryAnd] to an arbitrary JSON value. + * + * You should usually call [Builder.notSearchQueryAnd] with a well-typed + * `List` value instead. This method is primarily for setting the field to + * an undocumented or not yet supported value. + */ + fun notSearchQueryAnd(notSearchQueryAnd: JsonField>) = apply { + this.notSearchQueryAnd = notSearchQueryAnd.map { it.toMutableList() } + } + + /** + * Adds a single [String] to [Builder.notSearchQueryAnd]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addNotSearchQueryAnd(notSearchQueryAnd: String) = apply { + this.notSearchQueryAnd = + (this.notSearchQueryAnd ?: JsonField.of(mutableListOf())).also { + checkKnown("notSearchQueryAnd", it).add(notSearchQueryAnd) + } + } + + fun notSearchQueryOr(notSearchQueryOr: List?) = + notSearchQueryOr(JsonField.ofNullable(notSearchQueryOr)) + + /** + * Alias for calling [Builder.notSearchQueryOr] with + * `notSearchQueryOr.orElse(null)`. + */ + fun notSearchQueryOr(notSearchQueryOr: Optional>) = + notSearchQueryOr(notSearchQueryOr.getOrNull()) + + /** + * Sets [Builder.notSearchQueryOr] to an arbitrary JSON value. + * + * You should usually call [Builder.notSearchQueryOr] with a well-typed + * `List` value instead. This method is primarily for setting the field to + * an undocumented or not yet supported value. + */ + fun notSearchQueryOr(notSearchQueryOr: JsonField>) = apply { + this.notSearchQueryOr = notSearchQueryOr.map { it.toMutableList() } + } + + /** + * Adds a single [String] to [Builder.notSearchQueryOr]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addNotSearchQueryOr(notSearchQueryOr: String) = apply { + this.notSearchQueryOr = + (this.notSearchQueryOr ?: JsonField.of(mutableListOf())).also { + checkKnown("notSearchQueryOr", it).add(notSearchQueryOr) + } + } + + fun rowIdList(rowIdList: List?) = rowIdList(JsonField.ofNullable(rowIdList)) + + /** Alias for calling [Builder.rowIdList] with `rowIdList.orElse(null)`. */ + fun rowIdList(rowIdList: Optional>) = rowIdList(rowIdList.getOrNull()) + + /** + * Sets [Builder.rowIdList] to an arbitrary JSON value. + * + * You should usually call [Builder.rowIdList] with a well-typed `List` value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun rowIdList(rowIdList: JsonField>) = apply { + this.rowIdList = rowIdList.map { it.toMutableList() } + } + + /** + * Adds a single [Long] to [Builder.rowIdList]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addRowIdList(rowIdList: Long) = apply { + this.rowIdList = + (this.rowIdList ?: JsonField.of(mutableListOf())).also { + checkKnown("rowIdList", it).add(rowIdList) + } + } + + fun searchQueryAnd(searchQueryAnd: List?) = + searchQueryAnd(JsonField.ofNullable(searchQueryAnd)) + + /** + * Alias for calling [Builder.searchQueryAnd] with `searchQueryAnd.orElse(null)`. + */ + fun searchQueryAnd(searchQueryAnd: Optional>) = + searchQueryAnd(searchQueryAnd.getOrNull()) + + /** + * Sets [Builder.searchQueryAnd] to an arbitrary JSON value. + * + * You should usually call [Builder.searchQueryAnd] with a well-typed `List` + * value instead. This method is primarily for setting the field to an undocumented + * or not yet supported value. + */ + fun searchQueryAnd(searchQueryAnd: JsonField>) = apply { + this.searchQueryAnd = searchQueryAnd.map { it.toMutableList() } + } + + /** + * Adds a single [String] to [Builder.searchQueryAnd]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addSearchQueryAnd(searchQueryAnd: String) = apply { + this.searchQueryAnd = + (this.searchQueryAnd ?: JsonField.of(mutableListOf())).also { + checkKnown("searchQueryAnd", it).add(searchQueryAnd) + } + } + + fun searchQueryOr(searchQueryOr: List?) = + searchQueryOr(JsonField.ofNullable(searchQueryOr)) + + /** Alias for calling [Builder.searchQueryOr] with `searchQueryOr.orElse(null)`. */ + fun searchQueryOr(searchQueryOr: Optional>) = + searchQueryOr(searchQueryOr.getOrNull()) + + /** + * Sets [Builder.searchQueryOr] to an arbitrary JSON value. + * + * You should usually call [Builder.searchQueryOr] with a well-typed `List` + * value instead. This method is primarily for setting the field to an undocumented + * or not yet supported value. + */ + fun searchQueryOr(searchQueryOr: JsonField>) = apply { + this.searchQueryOr = searchQueryOr.map { it.toMutableList() } + } + + /** + * Adds a single [String] to [Builder.searchQueryOr]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addSearchQueryOr(searchQueryOr: String) = apply { + this.searchQueryOr = + (this.searchQueryOr ?: JsonField.of(mutableListOf())).also { + checkKnown("searchQueryOr", it).add(searchQueryOr) + } + } + + 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 [RowsBody]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): RowsBody = + RowsBody( + (columnFilters ?: JsonMissing.of()).map { it.toImmutable() }, + (excludeRowIdList ?: JsonMissing.of()).map { it.toImmutable() }, + (notSearchQueryAnd ?: JsonMissing.of()).map { it.toImmutable() }, + (notSearchQueryOr ?: JsonMissing.of()).map { it.toImmutable() }, + (rowIdList ?: JsonMissing.of()).map { it.toImmutable() }, + (searchQueryAnd ?: JsonMissing.of()).map { it.toImmutable() }, + (searchQueryOr ?: JsonMissing.of()).map { it.toImmutable() }, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): RowsBody = apply { + if (validated) { + return@apply + } + + columnFilters().ifPresent { it.forEach { it.validate() } } + excludeRowIdList() + notSearchQueryAnd() + notSearchQueryOr() + rowIdList() + searchQueryAnd() + searchQueryOr() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OpenlayerInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (columnFilters.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + + (excludeRowIdList.asKnown().getOrNull()?.size ?: 0) + + (notSearchQueryAnd.asKnown().getOrNull()?.size ?: 0) + + (notSearchQueryOr.asKnown().getOrNull()?.size ?: 0) + + (rowIdList.asKnown().getOrNull()?.size ?: 0) + + (searchQueryAnd.asKnown().getOrNull()?.size ?: 0) + + (searchQueryOr.asKnown().getOrNull()?.size ?: 0) + + @JsonDeserialize(using = ColumnFilter.Deserializer::class) + @JsonSerialize(using = ColumnFilter.Serializer::class) + class ColumnFilter + private constructor( + private val set: SetColumnFilter? = null, + private val numeric: NumericColumnFilter? = null, + private val string: StringColumnFilter? = null, + private val _json: JsonValue? = null, + ) { + + fun set(): Optional = Optional.ofNullable(set) + + fun numeric(): Optional = Optional.ofNullable(numeric) + + fun string(): Optional = Optional.ofNullable(string) + + fun isSet(): Boolean = set != null + + fun isNumeric(): Boolean = numeric != null + + fun isString(): Boolean = string != null + + fun asSet(): SetColumnFilter = set.getOrThrow("set") + + fun asNumeric(): NumericColumnFilter = numeric.getOrThrow("numeric") + + fun asString(): StringColumnFilter = string.getOrThrow("string") + + fun _json(): Optional = Optional.ofNullable(_json) + + fun accept(visitor: Visitor): T = + when { + set != null -> visitor.visitSet(set) + numeric != null -> visitor.visitNumeric(numeric) + string != null -> visitor.visitString(string) + else -> visitor.unknown(_json) + } + + private var validated: Boolean = false + + fun validate(): ColumnFilter = apply { + if (validated) { + return@apply + } + + accept( + object : Visitor { + override fun visitSet(set: SetColumnFilter) { + set.validate() + } + + override fun visitNumeric(numeric: NumericColumnFilter) { + numeric.validate() + } + + override fun visitString(string: StringColumnFilter) { + string.validate() + } + } + ) + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OpenlayerInvalidDataException) { + false + } + + /** + * Returns 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 visitSet(set: SetColumnFilter) = set.validity() + + override fun visitNumeric(numeric: NumericColumnFilter) = + numeric.validity() + + override fun visitString(string: StringColumnFilter) = string.validity() + + override fun unknown(json: JsonValue?) = 0 + } + ) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is ColumnFilter && + set == other.set && + numeric == other.numeric && + string == other.string + } + + override fun hashCode(): Int = Objects.hash(set, numeric, string) + + override fun toString(): String = + when { + set != null -> "ColumnFilter{set=$set}" + numeric != null -> "ColumnFilter{numeric=$numeric}" + string != null -> "ColumnFilter{string=$string}" + _json != null -> "ColumnFilter{_unknown=$_json}" + else -> throw IllegalStateException("Invalid ColumnFilter") + } + + companion object { + + @JvmStatic fun ofSet(set: SetColumnFilter) = ColumnFilter(set = set) + + @JvmStatic + fun ofNumeric(numeric: NumericColumnFilter) = ColumnFilter(numeric = numeric) + + @JvmStatic + fun ofString(string: StringColumnFilter) = ColumnFilter(string = string) + } + + /** + * An interface that defines how to map each variant of [ColumnFilter] to a value of + * type [T]. + */ + interface Visitor { + + fun visitSet(set: SetColumnFilter): T + + fun visitNumeric(numeric: NumericColumnFilter): T + + fun visitString(string: StringColumnFilter): T + + /** + * Maps an unknown variant of [ColumnFilter] to a value of type [T]. + * + * An instance of [ColumnFilter] 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 OpenlayerInvalidDataException in the default implementation. + */ + fun unknown(json: JsonValue?): T { + throw OpenlayerInvalidDataException("Unknown ColumnFilter: $json") + } + } + + internal class Deserializer : BaseDeserializer(ColumnFilter::class) { + + override fun ObjectCodec.deserialize(node: JsonNode): ColumnFilter { + val json = JsonValue.fromJsonNode(node) + + val bestMatches = + sequenceOf( + tryDeserialize(node, jacksonTypeRef())?.let { + ColumnFilter(set = it, _json = json) + }, + tryDeserialize(node, jacksonTypeRef()) + ?.let { ColumnFilter(numeric = it, _json = json) }, + tryDeserialize(node, jacksonTypeRef()) + ?.let { ColumnFilter(string = it, _json = json) }, + ) + .filterNotNull() + .allMaxBy { it.validity() } + .toList() + return when (bestMatches.size) { + // This can happen if what we're deserializing is completely + // incompatible with all the possible variants (e.g. deserializing from + // boolean). + 0 -> ColumnFilter(_json = json) + 1 -> bestMatches.single() + // If there's more than one match with the highest validity, then use + // the first completely valid match, or simply the first match if none + // are completely valid. + else -> bestMatches.firstOrNull { it.isValid() } ?: bestMatches.first() + } + } + } + + internal class Serializer : BaseSerializer(ColumnFilter::class) { + + override fun serialize( + value: ColumnFilter, + generator: JsonGenerator, + provider: SerializerProvider, + ) { + when { + value.set != null -> generator.writeObject(value.set) + value.numeric != null -> generator.writeObject(value.numeric) + value.string != null -> generator.writeObject(value.string) + value._json != null -> generator.writeObject(value._json) + else -> throw IllegalStateException("Invalid ColumnFilter") + } + } + } + + class SetColumnFilter + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val measurement: JsonField, + private val operator: JsonField, + private val value: JsonField>, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("measurement") + @ExcludeMissing + measurement: JsonField = JsonMissing.of(), + @JsonProperty("operator") + @ExcludeMissing + operator: JsonField = JsonMissing.of(), + @JsonProperty("value") + @ExcludeMissing + value: JsonField> = JsonMissing.of(), + ) : this(measurement, operator, value, mutableMapOf()) + + /** + * The name of the column. + * + * @throws OpenlayerInvalidDataException if the JSON field has an unexpected + * type or is unexpectedly missing or null (e.g. if the server responded with + * an unexpected value). + */ + fun measurement(): String = measurement.getRequired("measurement") + + /** + * @throws OpenlayerInvalidDataException if the JSON field has an unexpected + * type or is unexpectedly missing or null (e.g. if the server responded with + * an unexpected value). + */ + fun operator(): Operator = operator.getRequired("operator") + + /** + * @throws OpenlayerInvalidDataException if the JSON field has an unexpected + * type or is unexpectedly missing or null (e.g. if the server responded with + * an unexpected value). + */ + fun value(): List = value.getRequired("value") + + /** + * Returns the raw JSON value of [measurement]. + * + * Unlike [measurement], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("measurement") + @ExcludeMissing + fun _measurement(): JsonField = measurement + + /** + * Returns the raw JSON value of [operator]. + * + * Unlike [operator], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("operator") + @ExcludeMissing + fun _operator(): JsonField = operator + + /** + * 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 + * [SetColumnFilter]. + * + * The following fields are required: + * ```java + * .measurement() + * .operator() + * .value() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [SetColumnFilter]. */ + class Builder internal constructor() { + + private var measurement: JsonField? = null + private var operator: JsonField? = null + private var value: JsonField>? = null + private var additionalProperties: MutableMap = + mutableMapOf() + + @JvmSynthetic + internal fun from(setColumnFilter: SetColumnFilter) = apply { + measurement = setColumnFilter.measurement + operator = setColumnFilter.operator + value = setColumnFilter.value.map { it.toMutableList() } + additionalProperties = + setColumnFilter.additionalProperties.toMutableMap() + } + + /** The name of the column. */ + fun measurement(measurement: String) = + measurement(JsonField.of(measurement)) + + /** + * Sets [Builder.measurement] to an arbitrary JSON value. + * + * You should usually call [Builder.measurement] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun measurement(measurement: JsonField) = apply { + this.measurement = measurement + } + + fun operator(operator: Operator) = operator(JsonField.of(operator)) + + /** + * Sets [Builder.operator] to an arbitrary JSON value. + * + * You should usually call [Builder.operator] with a well-typed [Operator] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun operator(operator: JsonField) = apply { + this.operator = operator + } + + fun value(value: List) = value(JsonField.of(value)) + + /** + * Sets [Builder.value] to an arbitrary JSON value. + * + * You should usually call [Builder.value] with a well-typed `List` + * 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.map { it.toMutableList() } + } + + /** + * Adds a single [Value] to [Builder.value]. + * + * @throws IllegalStateException if the field was previously set to a + * non-list. + */ + fun addValue(value: Value) = apply { + this.value = + (this.value ?: JsonField.of(mutableListOf())).also { + checkKnown("value", it).add(value) + } + } + + /** Alias for calling [addValue] with `Value.ofString(string)`. */ + fun addValue(string: String) = addValue(Value.ofString(string)) + + /** Alias for calling [addValue] with `Value.ofNumber(number)`. */ + fun addValue(number: Double) = addValue(Value.ofNumber(number)) + + 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 [SetColumnFilter]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .measurement() + * .operator() + * .value() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): SetColumnFilter = + SetColumnFilter( + checkRequired("measurement", measurement), + checkRequired("operator", operator), + checkRequired("value", value).map { it.toImmutable() }, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): SetColumnFilter = apply { + if (validated) { + return@apply + } + + measurement() + operator().validate() + value().forEach { it.validate() } + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OpenlayerInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (if (measurement.asKnown().isPresent) 1 else 0) + + (operator.asKnown().getOrNull()?.validity() ?: 0) + + (value.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + + class Operator + @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 CONTAINS_NONE = of("contains_none") + + @JvmField val CONTAINS_ANY = of("contains_any") + + @JvmField val CONTAINS_ALL = of("contains_all") + + @JvmField val ONE_OF = of("one_of") + + @JvmField val NONE_OF = of("none_of") + + @JvmStatic fun of(value: String) = Operator(JsonField.of(value)) + } + + /** An enum containing [Operator]'s known values. */ + enum class Known { + CONTAINS_NONE, + CONTAINS_ANY, + CONTAINS_ALL, + ONE_OF, + NONE_OF, + } + + /** + * An enum containing [Operator]'s known values, as well as an [_UNKNOWN] + * member. + * + * An instance of [Operator] 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 { + CONTAINS_NONE, + CONTAINS_ANY, + CONTAINS_ALL, + ONE_OF, + NONE_OF, + /** + * An enum member indicating that [Operator] 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) { + CONTAINS_NONE -> Value.CONTAINS_NONE + CONTAINS_ANY -> Value.CONTAINS_ANY + CONTAINS_ALL -> Value.CONTAINS_ALL + ONE_OF -> Value.ONE_OF + NONE_OF -> Value.NONE_OF + 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 OpenlayerInvalidDataException if this class instance's value is a + * not a known member. + */ + fun known(): Known = + when (this) { + CONTAINS_NONE -> Known.CONTAINS_NONE + CONTAINS_ANY -> Known.CONTAINS_ANY + CONTAINS_ALL -> Known.CONTAINS_ALL + ONE_OF -> Known.ONE_OF + NONE_OF -> Known.NONE_OF + else -> + throw OpenlayerInvalidDataException("Unknown Operator: $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 OpenlayerInvalidDataException if this class instance's value does + * not have the expected primitive type. + */ + fun asString(): String = + _value().asString().orElseThrow { + OpenlayerInvalidDataException("Value is not a String") + } + + private var validated: Boolean = false + + fun validate(): Operator = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OpenlayerInvalidDataException) { + false + } + + /** + * Returns a 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 Operator && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + @JsonDeserialize(using = Value.Deserializer::class) + @JsonSerialize(using = Value.Serializer::class) + class Value + private constructor( + private val string: String? = null, + private val number: Double? = null, + private val _json: JsonValue? = null, + ) { + + fun string(): Optional = Optional.ofNullable(string) + + fun number(): Optional = Optional.ofNullable(number) + + fun isString(): Boolean = string != null + + fun isNumber(): Boolean = number != null + + fun asString(): String = string.getOrThrow("string") + + fun asNumber(): Double = number.getOrThrow("number") + + fun _json(): Optional = Optional.ofNullable(_json) + + fun accept(visitor: Visitor): T = + when { + string != null -> visitor.visitString(string) + number != null -> visitor.visitNumber(number) + else -> visitor.unknown(_json) + } + + private var validated: Boolean = false + + fun validate(): Value = apply { + if (validated) { + return@apply + } + + accept( + object : Visitor { + override fun visitString(string: String) {} + + override fun visitNumber(number: Double) {} + } + ) + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OpenlayerInvalidDataException) { + false + } + + /** + * Returns 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 visitString(string: String) = 1 + + override fun visitNumber(number: Double) = 1 + + override fun unknown(json: JsonValue?) = 0 + } + ) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Value && + string == other.string && + number == other.number + } + + override fun hashCode(): Int = Objects.hash(string, number) + + override fun toString(): String = + when { + string != null -> "Value{string=$string}" + number != null -> "Value{number=$number}" + _json != null -> "Value{_unknown=$_json}" + else -> throw IllegalStateException("Invalid Value") + } + + companion object { + + @JvmStatic fun ofString(string: String) = Value(string = string) + + @JvmStatic fun ofNumber(number: Double) = Value(number = number) + } + + /** + * An interface that defines how to map each variant of [Value] to a value + * of type [T]. + */ + interface Visitor { + + fun visitString(string: String): T + + fun visitNumber(number: Double): T + + /** + * Maps an unknown variant of [Value] to a value of type [T]. + * + * An instance of [Value] 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 OpenlayerInvalidDataException in the default implementation. + */ + fun unknown(json: JsonValue?): T { + throw OpenlayerInvalidDataException("Unknown Value: $json") + } + } + + internal class Deserializer : BaseDeserializer(Value::class) { + + override fun ObjectCodec.deserialize(node: JsonNode): Value { + val json = JsonValue.fromJsonNode(node) + + val bestMatches = + sequenceOf( + tryDeserialize(node, jacksonTypeRef())?.let { + Value(string = it, _json = json) + }, + tryDeserialize(node, jacksonTypeRef())?.let { + Value(number = it, _json = json) + }, + ) + .filterNotNull() + .allMaxBy { it.validity() } + .toList() + return when (bestMatches.size) { + // This can happen if what we're deserializing is completely + // incompatible with all the possible variants (e.g. + // deserializing from object). + 0 -> Value(_json = json) + 1 -> bestMatches.single() + // If there's more than one match with the highest validity, + // then use the first completely valid match, or simply the + // first match if none are completely valid. + else -> + bestMatches.firstOrNull { it.isValid() } + ?: bestMatches.first() + } + } + } + + internal class Serializer : BaseSerializer(Value::class) { + + override fun serialize( + value: Value, + generator: JsonGenerator, + provider: SerializerProvider, + ) { + when { + value.string != null -> generator.writeObject(value.string) + value.number != null -> generator.writeObject(value.number) + value._json != null -> generator.writeObject(value._json) + else -> throw IllegalStateException("Invalid Value") + } + } + } + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is SetColumnFilter && + measurement == other.measurement && + operator == other.operator && + value == other.value && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(measurement, operator, value, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "SetColumnFilter{measurement=$measurement, operator=$operator, value=$value, additionalProperties=$additionalProperties}" + } + + class NumericColumnFilter + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val measurement: JsonField, + private val operator: JsonField, + private val value: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("measurement") + @ExcludeMissing + measurement: JsonField = JsonMissing.of(), + @JsonProperty("operator") + @ExcludeMissing + operator: JsonField = JsonMissing.of(), + @JsonProperty("value") + @ExcludeMissing + value: JsonField = JsonMissing.of(), + ) : this(measurement, operator, value, mutableMapOf()) + + /** + * The name of the column. + * + * @throws OpenlayerInvalidDataException if the JSON field has an unexpected + * type or is unexpectedly missing or null (e.g. if the server responded with + * an unexpected value). + */ + fun measurement(): String = measurement.getRequired("measurement") + + /** + * @throws OpenlayerInvalidDataException if the JSON field has an unexpected + * type or is unexpectedly missing or null (e.g. if the server responded with + * an unexpected value). + */ + fun operator(): Operator = operator.getRequired("operator") + + /** + * @throws OpenlayerInvalidDataException 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 [measurement]. + * + * Unlike [measurement], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("measurement") + @ExcludeMissing + fun _measurement(): JsonField = measurement + + /** + * Returns the raw JSON value of [operator]. + * + * Unlike [operator], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("operator") + @ExcludeMissing + fun _operator(): JsonField = operator + + /** + * 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 + * [NumericColumnFilter]. + * + * The following fields are required: + * ```java + * .measurement() + * .operator() + * .value() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [NumericColumnFilter]. */ + class Builder internal constructor() { + + private var measurement: JsonField? = null + private var operator: JsonField? = null + private var value: JsonField? = null + private var additionalProperties: MutableMap = + mutableMapOf() + + @JvmSynthetic + internal fun from(numericColumnFilter: NumericColumnFilter) = apply { + measurement = numericColumnFilter.measurement + operator = numericColumnFilter.operator + value = numericColumnFilter.value + additionalProperties = + numericColumnFilter.additionalProperties.toMutableMap() + } + + /** The name of the column. */ + fun measurement(measurement: String) = + measurement(JsonField.of(measurement)) + + /** + * Sets [Builder.measurement] to an arbitrary JSON value. + * + * You should usually call [Builder.measurement] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun measurement(measurement: JsonField) = apply { + this.measurement = measurement + } + + fun operator(operator: Operator) = operator(JsonField.of(operator)) + + /** + * Sets [Builder.operator] to an arbitrary JSON value. + * + * You should usually call [Builder.operator] with a well-typed [Operator] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun operator(operator: JsonField) = apply { + this.operator = operator + } + + fun value(value: Float?) = value(JsonField.ofNullable(value)) + + /** + * Alias for [Builder.value]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun value(value: Float) = value(value as Float?) + + /** Alias for calling [Builder.value] with `value.orElse(null)`. */ + fun value(value: Optional) = value(value.getOrNull()) + + /** + * Sets [Builder.value] to an arbitrary JSON value. + * + * You should usually call [Builder.value] with a well-typed [Float] 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 [NumericColumnFilter]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .measurement() + * .operator() + * .value() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): NumericColumnFilter = + NumericColumnFilter( + checkRequired("measurement", measurement), + checkRequired("operator", operator), + checkRequired("value", value), + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): NumericColumnFilter = apply { + if (validated) { + return@apply + } + + measurement() + operator().validate() + value() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OpenlayerInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (if (measurement.asKnown().isPresent) 1 else 0) + + (operator.asKnown().getOrNull()?.validity() ?: 0) + + (if (value.asKnown().isPresent) 1 else 0) + + class Operator + @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 GREATER = of(">") + + @JvmField val GREATER_OR_EQUALS = of(">=") + + @JvmField val IS = of("is") + + @JvmField val LESS = of("<") + + @JvmField val LESS_OR_EQUALS = of("<=") + + @JvmField val NOT_EQUALS = of("!=") + + @JvmStatic fun of(value: String) = Operator(JsonField.of(value)) + } + + /** An enum containing [Operator]'s known values. */ + enum class Known { + GREATER, + GREATER_OR_EQUALS, + IS, + LESS, + LESS_OR_EQUALS, + NOT_EQUALS, + } + + /** + * An enum containing [Operator]'s known values, as well as an [_UNKNOWN] + * member. + * + * An instance of [Operator] 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 { + GREATER, + GREATER_OR_EQUALS, + IS, + LESS, + LESS_OR_EQUALS, + NOT_EQUALS, + /** + * An enum member indicating that [Operator] 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) { + GREATER -> Value.GREATER + GREATER_OR_EQUALS -> Value.GREATER_OR_EQUALS + IS -> Value.IS + LESS -> Value.LESS + LESS_OR_EQUALS -> Value.LESS_OR_EQUALS + NOT_EQUALS -> Value.NOT_EQUALS + 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 OpenlayerInvalidDataException if this class instance's value is a + * not a known member. + */ + fun known(): Known = + when (this) { + GREATER -> Known.GREATER + GREATER_OR_EQUALS -> Known.GREATER_OR_EQUALS + IS -> Known.IS + LESS -> Known.LESS + LESS_OR_EQUALS -> Known.LESS_OR_EQUALS + NOT_EQUALS -> Known.NOT_EQUALS + else -> + throw OpenlayerInvalidDataException("Unknown Operator: $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 OpenlayerInvalidDataException if this class instance's value does + * not have the expected primitive type. + */ + fun asString(): String = + _value().asString().orElseThrow { + OpenlayerInvalidDataException("Value is not a String") + } + + private var validated: Boolean = false + + fun validate(): Operator = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OpenlayerInvalidDataException) { + false + } + + /** + * Returns a 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 Operator && 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 NumericColumnFilter && + measurement == other.measurement && + operator == other.operator && + value == other.value && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(measurement, operator, value, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "NumericColumnFilter{measurement=$measurement, operator=$operator, value=$value, additionalProperties=$additionalProperties}" + } + + class StringColumnFilter + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val measurement: JsonField, + private val operator: JsonField, + private val value: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("measurement") + @ExcludeMissing + measurement: JsonField = JsonMissing.of(), + @JsonProperty("operator") + @ExcludeMissing + operator: JsonField = JsonMissing.of(), + @JsonProperty("value") + @ExcludeMissing + value: JsonField = JsonMissing.of(), + ) : this(measurement, operator, value, mutableMapOf()) + + /** + * The name of the column. + * + * @throws OpenlayerInvalidDataException if the JSON field has an unexpected + * type or is unexpectedly missing or null (e.g. if the server responded with + * an unexpected value). + */ + fun measurement(): String = measurement.getRequired("measurement") + + /** + * @throws OpenlayerInvalidDataException if the JSON field has an unexpected + * type or is unexpectedly missing or null (e.g. if the server responded with + * an unexpected value). + */ + fun operator(): Operator = operator.getRequired("operator") + + /** + * @throws OpenlayerInvalidDataException if the JSON field has an unexpected + * type or is unexpectedly missing or null (e.g. if the server responded with + * an unexpected value). + */ + fun value(): Value = value.getRequired("value") + + /** + * Returns the raw JSON value of [measurement]. + * + * Unlike [measurement], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("measurement") + @ExcludeMissing + fun _measurement(): JsonField = measurement + + /** + * Returns the raw JSON value of [operator]. + * + * Unlike [operator], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("operator") + @ExcludeMissing + fun _operator(): JsonField = operator + + /** + * 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 + * [StringColumnFilter]. + * + * The following fields are required: + * ```java + * .measurement() + * .operator() + * .value() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [StringColumnFilter]. */ + class Builder internal constructor() { + + private var measurement: JsonField? = null + private var operator: JsonField? = null + private var value: JsonField? = null + private var additionalProperties: MutableMap = + mutableMapOf() + + @JvmSynthetic + internal fun from(stringColumnFilter: StringColumnFilter) = apply { + measurement = stringColumnFilter.measurement + operator = stringColumnFilter.operator + value = stringColumnFilter.value + additionalProperties = + stringColumnFilter.additionalProperties.toMutableMap() + } + + /** The name of the column. */ + fun measurement(measurement: String) = + measurement(JsonField.of(measurement)) + + /** + * Sets [Builder.measurement] to an arbitrary JSON value. + * + * You should usually call [Builder.measurement] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun measurement(measurement: JsonField) = apply { + this.measurement = measurement + } + + fun operator(operator: Operator) = operator(JsonField.of(operator)) + + /** + * Sets [Builder.operator] to an arbitrary JSON value. + * + * You should usually call [Builder.operator] with a well-typed [Operator] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun operator(operator: JsonField) = apply { + this.operator = operator + } + + fun value(value: Value) = value(JsonField.of(value)) + + /** + * Sets [Builder.value] to an arbitrary JSON value. + * + * You should usually call [Builder.value] with a well-typed [Value] 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 } + + /** Alias for calling [value] with `Value.ofString(string)`. */ + fun value(string: String) = value(Value.ofString(string)) + + /** Alias for calling [value] with `Value.ofBool(bool)`. */ + fun value(bool: Boolean) = value(Value.ofBool(bool)) + + 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 [StringColumnFilter]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .measurement() + * .operator() + * .value() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): StringColumnFilter = + StringColumnFilter( + checkRequired("measurement", measurement), + checkRequired("operator", operator), + checkRequired("value", value), + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): StringColumnFilter = apply { + if (validated) { + return@apply + } + + measurement() + operator().validate() + value().validate() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OpenlayerInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (if (measurement.asKnown().isPresent) 1 else 0) + + (operator.asKnown().getOrNull()?.validity() ?: 0) + + (value.asKnown().getOrNull()?.validity() ?: 0) + + class Operator + @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 IS = of("is") + + @JvmField val NOT_EQUALS = of("!=") + + @JvmStatic fun of(value: String) = Operator(JsonField.of(value)) + } + + /** An enum containing [Operator]'s known values. */ + enum class Known { + IS, + NOT_EQUALS, + } + + /** + * An enum containing [Operator]'s known values, as well as an [_UNKNOWN] + * member. + * + * An instance of [Operator] 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 { + IS, + NOT_EQUALS, + /** + * An enum member indicating that [Operator] 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) { + IS -> Value.IS + NOT_EQUALS -> Value.NOT_EQUALS + 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 OpenlayerInvalidDataException if this class instance's value is a + * not a known member. + */ + fun known(): Known = + when (this) { + IS -> Known.IS + NOT_EQUALS -> Known.NOT_EQUALS + else -> + throw OpenlayerInvalidDataException("Unknown Operator: $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 OpenlayerInvalidDataException if this class instance's value does + * not have the expected primitive type. + */ + fun asString(): String = + _value().asString().orElseThrow { + OpenlayerInvalidDataException("Value is not a String") + } + + private var validated: Boolean = false + + fun validate(): Operator = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OpenlayerInvalidDataException) { + false + } + + /** + * Returns a 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 Operator && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + @JsonDeserialize(using = Value.Deserializer::class) + @JsonSerialize(using = Value.Serializer::class) + class Value + private constructor( + private val string: String? = null, + private val bool: Boolean? = null, + private val _json: JsonValue? = null, + ) { + + fun string(): Optional = Optional.ofNullable(string) + + fun bool(): Optional = Optional.ofNullable(bool) + + fun isString(): Boolean = string != null + + fun isBool(): Boolean = bool != null + + fun asString(): String = string.getOrThrow("string") + + fun asBool(): Boolean = bool.getOrThrow("bool") + + fun _json(): Optional = Optional.ofNullable(_json) + + fun accept(visitor: Visitor): T = + when { + string != null -> visitor.visitString(string) + bool != null -> visitor.visitBool(bool) + else -> visitor.unknown(_json) + } + + private var validated: Boolean = false + + fun validate(): Value = apply { + if (validated) { + return@apply + } + + accept( + object : Visitor { + override fun visitString(string: String) {} + + override fun visitBool(bool: Boolean) {} + } + ) + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OpenlayerInvalidDataException) { + false + } + + /** + * Returns 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 visitString(string: String) = 1 + + override fun visitBool(bool: Boolean) = 1 + + override fun unknown(json: JsonValue?) = 0 + } + ) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Value && string == other.string && bool == other.bool + } + + override fun hashCode(): Int = Objects.hash(string, bool) + + override fun toString(): String = + when { + string != null -> "Value{string=$string}" + bool != null -> "Value{bool=$bool}" + _json != null -> "Value{_unknown=$_json}" + else -> throw IllegalStateException("Invalid Value") + } + + companion object { + + @JvmStatic fun ofString(string: String) = Value(string = string) + + @JvmStatic fun ofBool(bool: Boolean) = Value(bool = bool) + } + + /** + * An interface that defines how to map each variant of [Value] to a value + * of type [T]. + */ + interface Visitor { + + fun visitString(string: String): T + + fun visitBool(bool: Boolean): T + + /** + * Maps an unknown variant of [Value] to a value of type [T]. + * + * An instance of [Value] 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 OpenlayerInvalidDataException in the default implementation. + */ + fun unknown(json: JsonValue?): T { + throw OpenlayerInvalidDataException("Unknown Value: $json") + } + } + + internal class Deserializer : BaseDeserializer(Value::class) { + + override fun ObjectCodec.deserialize(node: JsonNode): Value { + val json = JsonValue.fromJsonNode(node) + + val bestMatches = + sequenceOf( + tryDeserialize(node, jacksonTypeRef())?.let { + Value(string = it, _json = json) + }, + tryDeserialize(node, jacksonTypeRef())?.let { + Value(bool = it, _json = json) + }, + ) + .filterNotNull() + .allMaxBy { it.validity() } + .toList() + return when (bestMatches.size) { + // This can happen if what we're deserializing is completely + // incompatible with all the possible variants (e.g. + // deserializing from object). + 0 -> Value(_json = json) + 1 -> bestMatches.single() + // If there's more than one match with the highest validity, + // then use the first completely valid match, or simply the + // first match if none are completely valid. + else -> + bestMatches.firstOrNull { it.isValid() } + ?: bestMatches.first() + } + } + } + + internal class Serializer : BaseSerializer(Value::class) { + + override fun serialize( + value: Value, + generator: JsonGenerator, + provider: SerializerProvider, + ) { + when { + value.string != null -> generator.writeObject(value.string) + value.bool != null -> generator.writeObject(value.bool) + value._json != null -> generator.writeObject(value._json) + else -> throw IllegalStateException("Invalid Value") + } + } + } + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is StringColumnFilter && + measurement == other.measurement && + operator == other.operator && + value == other.value && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(measurement, operator, value, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "StringColumnFilter{measurement=$measurement, operator=$operator, value=$value, additionalProperties=$additionalProperties}" + } + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is RowsBody && + columnFilters == other.columnFilters && + excludeRowIdList == other.excludeRowIdList && + notSearchQueryAnd == other.notSearchQueryAnd && + notSearchQueryOr == other.notSearchQueryOr && + rowIdList == other.rowIdList && + searchQueryAnd == other.searchQueryAnd && + searchQueryOr == other.searchQueryOr && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + columnFilters, + excludeRowIdList, + notSearchQueryAnd, + notSearchQueryOr, + rowIdList, + searchQueryAnd, + searchQueryOr, + additionalProperties, + ) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "RowsBody{columnFilters=$columnFilters, excludeRowIdList=$excludeRowIdList, notSearchQueryAnd=$notSearchQueryAnd, notSearchQueryOr=$notSearchQueryOr, rowIdList=$rowIdList, searchQueryAnd=$searchQueryAnd, searchQueryOr=$searchQueryOr, additionalProperties=$additionalProperties}" + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Item && + id == other.id && + dateCreated == other.dateCreated && + dateDataEnds == other.dateDataEnds && + dateDataStarts == other.dateDataStarts && + dateUpdated == other.dateUpdated && + inferencePipelineId == other.inferencePipelineId && + projectVersionId == other.projectVersionId && + status == other.status && + statusMessage == other.statusMessage && + expectedValues == other.expectedValues && + goal == other.goal && + goalId == other.goalId && + rows == other.rows && + rowsBody == other.rowsBody && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + id, + dateCreated, + dateDataEnds, + dateDataStarts, + dateUpdated, + inferencePipelineId, + projectVersionId, + status, + statusMessage, + expectedValues, + goal, + goalId, + rows, + rowsBody, + additionalProperties, + ) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Item{id=$id, dateCreated=$dateCreated, dateDataEnds=$dateDataEnds, dateDataStarts=$dateDataStarts, dateUpdated=$dateUpdated, inferencePipelineId=$inferencePipelineId, projectVersionId=$projectVersionId, status=$status, statusMessage=$statusMessage, expectedValues=$expectedValues, goal=$goal, goalId=$goalId, rows=$rows, rowsBody=$rowsBody, additionalProperties=$additionalProperties}" + } + + class LastUnskippedResult + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val id: JsonField, + private val dateCreated: JsonField, + private val dateDataEnds: JsonField, + private val dateDataStarts: JsonField, + private val dateUpdated: JsonField, + private val inferencePipelineId: JsonField, + private val projectVersionId: JsonField, + private val status: JsonField, + private val statusMessage: JsonField, + private val expectedValues: JsonField>, + private val goal: JsonField, + private val goalId: JsonField, + private val rows: JsonField, + private val rowsBody: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("id") @ExcludeMissing id: JsonField = JsonMissing.of(), + @JsonProperty("dateCreated") + @ExcludeMissing + dateCreated: JsonField = JsonMissing.of(), + @JsonProperty("dateDataEnds") + @ExcludeMissing + dateDataEnds: JsonField = JsonMissing.of(), + @JsonProperty("dateDataStarts") + @ExcludeMissing + dateDataStarts: JsonField = JsonMissing.of(), + @JsonProperty("dateUpdated") + @ExcludeMissing + dateUpdated: JsonField = JsonMissing.of(), + @JsonProperty("inferencePipelineId") + @ExcludeMissing + inferencePipelineId: JsonField = JsonMissing.of(), + @JsonProperty("projectVersionId") + @ExcludeMissing + projectVersionId: JsonField = JsonMissing.of(), + @JsonProperty("status") @ExcludeMissing status: JsonField = JsonMissing.of(), + @JsonProperty("statusMessage") + @ExcludeMissing + statusMessage: JsonField = JsonMissing.of(), + @JsonProperty("expectedValues") + @ExcludeMissing + expectedValues: JsonField> = JsonMissing.of(), + @JsonProperty("goal") @ExcludeMissing goal: JsonField = JsonMissing.of(), + @JsonProperty("goalId") @ExcludeMissing goalId: JsonField = JsonMissing.of(), + @JsonProperty("rows") @ExcludeMissing rows: JsonField = JsonMissing.of(), + @JsonProperty("rowsBody") + @ExcludeMissing + rowsBody: JsonField = JsonMissing.of(), + ) : this( + id, + dateCreated, + dateDataEnds, + dateDataStarts, + dateUpdated, + inferencePipelineId, + projectVersionId, + status, + statusMessage, + expectedValues, + goal, + goalId, + rows, + rowsBody, + mutableMapOf(), + ) + + /** + * Project version (commit) id. + * + * @throws OpenlayerInvalidDataException if 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 creation date. + * + * @throws OpenlayerInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun dateCreated(): OffsetDateTime = dateCreated.getRequired("dateCreated") + + /** + * The data end date. + * + * @throws OpenlayerInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun dateDataEnds(): Optional = dateDataEnds.getOptional("dateDataEnds") + + /** + * The data start date. + * + * @throws OpenlayerInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun dateDataStarts(): Optional = + dateDataStarts.getOptional("dateDataStarts") + + /** + * The last updated date. + * + * @throws OpenlayerInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun dateUpdated(): OffsetDateTime = dateUpdated.getRequired("dateUpdated") + + /** + * The inference pipeline id. + * + * @throws OpenlayerInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun inferencePipelineId(): Optional = + inferencePipelineId.getOptional("inferencePipelineId") + + /** + * The project version (commit) id. + * + * @throws OpenlayerInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun projectVersionId(): Optional = projectVersionId.getOptional("projectVersionId") + + /** + * The status of the test. + * + * @throws OpenlayerInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun status(): Status = status.getRequired("status") + + /** + * The status message. + * + * @throws OpenlayerInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun statusMessage(): Optional = statusMessage.getOptional("statusMessage") + + /** + * @throws OpenlayerInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun expectedValues(): Optional> = + expectedValues.getOptional("expectedValues") + + /** + * @throws OpenlayerInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun goal(): Optional = goal.getOptional("goal") + + /** + * The test id. + * + * @throws OpenlayerInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun goalId(): Optional = goalId.getOptional("goalId") + + /** + * The URL to the rows of the test result. + * + * @throws OpenlayerInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun rows(): Optional = rows.getOptional("rows") + + /** + * The body of the rows request. + * + * @throws OpenlayerInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun rowsBody(): Optional = rowsBody.getOptional("rowsBody") + + /** + * 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 [dateCreated]. + * + * Unlike [dateCreated], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("dateCreated") + @ExcludeMissing + fun _dateCreated(): JsonField = dateCreated + + /** + * Returns the raw JSON value of [dateDataEnds]. + * + * Unlike [dateDataEnds], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("dateDataEnds") + @ExcludeMissing + fun _dateDataEnds(): JsonField = dateDataEnds + + /** + * Returns the raw JSON value of [dateDataStarts]. + * + * Unlike [dateDataStarts], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("dateDataStarts") + @ExcludeMissing + fun _dateDataStarts(): JsonField = dateDataStarts + + /** + * Returns the raw JSON value of [dateUpdated]. + * + * Unlike [dateUpdated], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("dateUpdated") + @ExcludeMissing + fun _dateUpdated(): JsonField = dateUpdated + + /** + * Returns the raw JSON value of [inferencePipelineId]. + * + * Unlike [inferencePipelineId], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("inferencePipelineId") + @ExcludeMissing + fun _inferencePipelineId(): JsonField = inferencePipelineId + + /** + * Returns the raw JSON value of [projectVersionId]. + * + * Unlike [projectVersionId], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("projectVersionId") + @ExcludeMissing + fun _projectVersionId(): JsonField = projectVersionId + + /** + * Returns the raw JSON value of [status]. + * + * Unlike [status], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("status") @ExcludeMissing fun _status(): JsonField = status + + /** + * Returns the raw JSON value of [statusMessage]. + * + * Unlike [statusMessage], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("statusMessage") + @ExcludeMissing + fun _statusMessage(): JsonField = statusMessage + + /** + * Returns the raw JSON value of [expectedValues]. + * + * Unlike [expectedValues], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("expectedValues") + @ExcludeMissing + fun _expectedValues(): JsonField> = expectedValues + + /** + * Returns the raw JSON value of [goal]. + * + * Unlike [goal], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("goal") @ExcludeMissing fun _goal(): JsonField = goal + + /** + * Returns the raw JSON value of [goalId]. + * + * Unlike [goalId], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("goalId") @ExcludeMissing fun _goalId(): JsonField = goalId + + /** + * Returns the raw JSON value of [rows]. + * + * Unlike [rows], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("rows") @ExcludeMissing fun _rows(): JsonField = rows + + /** + * Returns the raw JSON value of [rowsBody]. + * + * Unlike [rowsBody], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("rowsBody") @ExcludeMissing fun _rowsBody(): JsonField = rowsBody + + @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 [LastUnskippedResult]. + * + * The following fields are required: + * ```java + * .id() + * .dateCreated() + * .dateDataEnds() + * .dateDataStarts() + * .dateUpdated() + * .inferencePipelineId() + * .projectVersionId() + * .status() + * .statusMessage() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [LastUnskippedResult]. */ + class Builder internal constructor() { + + private var id: JsonField? = null + private var dateCreated: JsonField? = null + private var dateDataEnds: JsonField? = null + private var dateDataStarts: JsonField? = null + private var dateUpdated: JsonField? = null + private var inferencePipelineId: JsonField? = null + private var projectVersionId: JsonField? = null + private var status: JsonField? = null + private var statusMessage: JsonField? = null + private var expectedValues: JsonField>? = null + private var goal: JsonField = JsonMissing.of() + private var goalId: JsonField = JsonMissing.of() + private var rows: JsonField = JsonMissing.of() + private var rowsBody: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(lastUnskippedResult: LastUnskippedResult) = apply { + id = lastUnskippedResult.id + dateCreated = lastUnskippedResult.dateCreated + dateDataEnds = lastUnskippedResult.dateDataEnds + dateDataStarts = lastUnskippedResult.dateDataStarts + dateUpdated = lastUnskippedResult.dateUpdated + inferencePipelineId = lastUnskippedResult.inferencePipelineId + projectVersionId = lastUnskippedResult.projectVersionId + status = lastUnskippedResult.status + statusMessage = lastUnskippedResult.statusMessage + expectedValues = lastUnskippedResult.expectedValues.map { it.toMutableList() } + goal = lastUnskippedResult.goal + goalId = lastUnskippedResult.goalId + rows = lastUnskippedResult.rows + rowsBody = lastUnskippedResult.rowsBody + additionalProperties = lastUnskippedResult.additionalProperties.toMutableMap() + } + + /** Project version (commit) 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 } + + /** The creation date. */ + fun dateCreated(dateCreated: OffsetDateTime) = dateCreated(JsonField.of(dateCreated)) + + /** + * Sets [Builder.dateCreated] to an arbitrary JSON value. + * + * You should usually call [Builder.dateCreated] with a well-typed [OffsetDateTime] + * value instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun dateCreated(dateCreated: JsonField) = apply { + this.dateCreated = dateCreated + } + + /** The data end date. */ + fun dateDataEnds(dateDataEnds: OffsetDateTime?) = + dateDataEnds(JsonField.ofNullable(dateDataEnds)) + + /** Alias for calling [Builder.dateDataEnds] with `dateDataEnds.orElse(null)`. */ + fun dateDataEnds(dateDataEnds: Optional) = + dateDataEnds(dateDataEnds.getOrNull()) + + /** + * Sets [Builder.dateDataEnds] to an arbitrary JSON value. + * + * You should usually call [Builder.dateDataEnds] with a well-typed [OffsetDateTime] + * value instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun dateDataEnds(dateDataEnds: JsonField) = apply { + this.dateDataEnds = dateDataEnds + } + + /** The data start date. */ + fun dateDataStarts(dateDataStarts: OffsetDateTime?) = + dateDataStarts(JsonField.ofNullable(dateDataStarts)) + + /** Alias for calling [Builder.dateDataStarts] with `dateDataStarts.orElse(null)`. */ + fun dateDataStarts(dateDataStarts: Optional) = + dateDataStarts(dateDataStarts.getOrNull()) + + /** + * Sets [Builder.dateDataStarts] to an arbitrary JSON value. + * + * You should usually call [Builder.dateDataStarts] with a well-typed [OffsetDateTime] + * value instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun dateDataStarts(dateDataStarts: JsonField) = apply { + this.dateDataStarts = dateDataStarts + } + + /** The last updated date. */ + fun dateUpdated(dateUpdated: OffsetDateTime) = dateUpdated(JsonField.of(dateUpdated)) + + /** + * Sets [Builder.dateUpdated] to an arbitrary JSON value. + * + * You should usually call [Builder.dateUpdated] with a well-typed [OffsetDateTime] + * value instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun dateUpdated(dateUpdated: JsonField) = apply { + this.dateUpdated = dateUpdated + } + + /** The inference pipeline id. */ + fun inferencePipelineId(inferencePipelineId: String?) = + inferencePipelineId(JsonField.ofNullable(inferencePipelineId)) + + /** + * Alias for calling [Builder.inferencePipelineId] with + * `inferencePipelineId.orElse(null)`. + */ + fun inferencePipelineId(inferencePipelineId: Optional) = + inferencePipelineId(inferencePipelineId.getOrNull()) + + /** + * Sets [Builder.inferencePipelineId] to an arbitrary JSON value. + * + * You should usually call [Builder.inferencePipelineId] with a well-typed [String] + * value instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun inferencePipelineId(inferencePipelineId: JsonField) = apply { + this.inferencePipelineId = inferencePipelineId + } + + /** The project version (commit) id. */ + fun projectVersionId(projectVersionId: String?) = + projectVersionId(JsonField.ofNullable(projectVersionId)) + + /** + * Alias for calling [Builder.projectVersionId] with `projectVersionId.orElse(null)`. + */ + fun projectVersionId(projectVersionId: Optional) = + projectVersionId(projectVersionId.getOrNull()) + + /** + * Sets [Builder.projectVersionId] to an arbitrary JSON value. + * + * You should usually call [Builder.projectVersionId] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun projectVersionId(projectVersionId: JsonField) = apply { + this.projectVersionId = projectVersionId + } + + /** The status of the test. */ + fun status(status: Status) = status(JsonField.of(status)) + + /** + * Sets [Builder.status] to an arbitrary JSON value. + * + * You should usually call [Builder.status] with a well-typed [Status] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun status(status: JsonField) = apply { this.status = status } + + /** The status message. */ + fun statusMessage(statusMessage: String?) = + statusMessage(JsonField.ofNullable(statusMessage)) + + /** Alias for calling [Builder.statusMessage] with `statusMessage.orElse(null)`. */ + fun statusMessage(statusMessage: Optional) = + statusMessage(statusMessage.getOrNull()) + + /** + * Sets [Builder.statusMessage] to an arbitrary JSON value. + * + * You should usually call [Builder.statusMessage] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun statusMessage(statusMessage: JsonField) = apply { + this.statusMessage = statusMessage + } + + fun expectedValues(expectedValues: List) = + expectedValues(JsonField.of(expectedValues)) + + /** + * Sets [Builder.expectedValues] to an arbitrary JSON value. + * + * You should usually call [Builder.expectedValues] with a well-typed + * `List` value instead. This method is primarily for setting the field + * to an undocumented or not yet supported value. + */ + fun expectedValues(expectedValues: JsonField>) = apply { + this.expectedValues = expectedValues.map { it.toMutableList() } + } + + /** + * Adds a single [ExpectedValue] to [expectedValues]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addExpectedValue(expectedValue: ExpectedValue) = apply { + expectedValues = + (expectedValues ?: JsonField.of(mutableListOf())).also { + checkKnown("expectedValues", it).add(expectedValue) + } + } + + fun goal(goal: Goal) = goal(JsonField.of(goal)) + + /** + * Sets [Builder.goal] to an arbitrary JSON value. + * + * You should usually call [Builder.goal] with a well-typed [Goal] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun goal(goal: JsonField) = apply { this.goal = goal } + + /** The test id. */ + fun goalId(goalId: String?) = goalId(JsonField.ofNullable(goalId)) + + /** Alias for calling [Builder.goalId] with `goalId.orElse(null)`. */ + fun goalId(goalId: Optional) = goalId(goalId.getOrNull()) + + /** + * Sets [Builder.goalId] to an arbitrary JSON value. + * + * You should usually call [Builder.goalId] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun goalId(goalId: JsonField) = apply { this.goalId = goalId } + + /** The URL to the rows of the test result. */ + fun rows(rows: String) = rows(JsonField.of(rows)) + + /** + * Sets [Builder.rows] to an arbitrary JSON value. + * + * You should usually call [Builder.rows] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun rows(rows: JsonField) = apply { this.rows = rows } + + /** The body of the rows request. */ + fun rowsBody(rowsBody: RowsBody?) = rowsBody(JsonField.ofNullable(rowsBody)) + + /** Alias for calling [Builder.rowsBody] with `rowsBody.orElse(null)`. */ + fun rowsBody(rowsBody: Optional) = rowsBody(rowsBody.getOrNull()) + + /** + * Sets [Builder.rowsBody] to an arbitrary JSON value. + * + * You should usually call [Builder.rowsBody] with a well-typed [RowsBody] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun rowsBody(rowsBody: JsonField) = apply { this.rowsBody = rowsBody } + + 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 [LastUnskippedResult]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .id() + * .dateCreated() + * .dateDataEnds() + * .dateDataStarts() + * .dateUpdated() + * .inferencePipelineId() + * .projectVersionId() + * .status() + * .statusMessage() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): LastUnskippedResult = + LastUnskippedResult( + checkRequired("id", id), + checkRequired("dateCreated", dateCreated), + checkRequired("dateDataEnds", dateDataEnds), + checkRequired("dateDataStarts", dateDataStarts), + checkRequired("dateUpdated", dateUpdated), + checkRequired("inferencePipelineId", inferencePipelineId), + checkRequired("projectVersionId", projectVersionId), + checkRequired("status", status), + checkRequired("statusMessage", statusMessage), + (expectedValues ?: JsonMissing.of()).map { it.toImmutable() }, + goal, + goalId, + rows, + rowsBody, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): LastUnskippedResult = apply { + if (validated) { + return@apply + } + + id() + dateCreated() + dateDataEnds() + dateDataStarts() + dateUpdated() + inferencePipelineId() + projectVersionId() + status().validate() + statusMessage() + expectedValues().ifPresent { it.forEach { it.validate() } } + goal().ifPresent { it.validate() } + goalId() + rows() + rowsBody().ifPresent { it.validate() } + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OpenlayerInvalidDataException) { + false + } + + /** + * Returns a 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 (dateCreated.asKnown().isPresent) 1 else 0) + + (if (dateDataEnds.asKnown().isPresent) 1 else 0) + + (if (dateDataStarts.asKnown().isPresent) 1 else 0) + + (if (dateUpdated.asKnown().isPresent) 1 else 0) + + (if (inferencePipelineId.asKnown().isPresent) 1 else 0) + + (if (projectVersionId.asKnown().isPresent) 1 else 0) + + (status.asKnown().getOrNull()?.validity() ?: 0) + + (if (statusMessage.asKnown().isPresent) 1 else 0) + + (expectedValues.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + + (goal.asKnown().getOrNull()?.validity() ?: 0) + + (if (goalId.asKnown().isPresent) 1 else 0) + + (if (rows.asKnown().isPresent) 1 else 0) + + (rowsBody.asKnown().getOrNull()?.validity() ?: 0) + + /** The status of the test. */ + class Status @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 RUNNING = of("running") + + @JvmField val PASSING = of("passing") + + @JvmField val FAILING = of("failing") + + @JvmField val SKIPPED = of("skipped") + + @JvmField val ERROR = of("error") + + @JvmStatic fun of(value: String) = Status(JsonField.of(value)) + } + + /** An enum containing [Status]'s known values. */ + enum class Known { + RUNNING, + PASSING, + FAILING, + SKIPPED, + ERROR, + } + + /** + * An enum containing [Status]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [Status] 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 { + RUNNING, + PASSING, + FAILING, + SKIPPED, + ERROR, + /** + * An enum member indicating that [Status] 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) { + RUNNING -> Value.RUNNING + PASSING -> Value.PASSING + FAILING -> Value.FAILING + SKIPPED -> Value.SKIPPED + ERROR -> Value.ERROR + 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 OpenlayerInvalidDataException if this class instance's value is a not a known + * member. + */ + fun known(): Known = + when (this) { + RUNNING -> Known.RUNNING + PASSING -> Known.PASSING + FAILING -> Known.FAILING + SKIPPED -> Known.SKIPPED + ERROR -> Known.ERROR + else -> throw OpenlayerInvalidDataException("Unknown Status: $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 OpenlayerInvalidDataException if this class instance's value does not have + * the expected primitive type. + */ + fun asString(): String = + _value().asString().orElseThrow { + OpenlayerInvalidDataException("Value is not a String") + } + + private var validated: Boolean = false + + fun validate(): Status = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OpenlayerInvalidDataException) { + false + } + + /** + * Returns a 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 Status && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + class ExpectedValue + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val lowerThreshold: JsonField, + private val measurement: JsonField, + private val upperThreshold: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("lowerThreshold") + @ExcludeMissing + lowerThreshold: JsonField = JsonMissing.of(), + @JsonProperty("measurement") + @ExcludeMissing + measurement: JsonField = JsonMissing.of(), + @JsonProperty("upperThreshold") + @ExcludeMissing + upperThreshold: JsonField = JsonMissing.of(), + ) : this(lowerThreshold, measurement, upperThreshold, mutableMapOf()) + + /** + * the lower threshold for the expected value + * + * @throws OpenlayerInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun lowerThreshold(): Optional = lowerThreshold.getOptional("lowerThreshold") + + /** + * One of the `measurement` values in the test's thresholds + * + * @throws OpenlayerInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun measurement(): Optional = measurement.getOptional("measurement") + + /** + * The upper threshold for the expected value + * + * @throws OpenlayerInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun upperThreshold(): Optional = upperThreshold.getOptional("upperThreshold") + + /** + * Returns the raw JSON value of [lowerThreshold]. + * + * Unlike [lowerThreshold], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("lowerThreshold") + @ExcludeMissing + fun _lowerThreshold(): JsonField = lowerThreshold + + /** + * Returns the raw JSON value of [measurement]. + * + * Unlike [measurement], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("measurement") + @ExcludeMissing + fun _measurement(): JsonField = measurement + + /** + * Returns the raw JSON value of [upperThreshold]. + * + * Unlike [upperThreshold], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("upperThreshold") + @ExcludeMissing + fun _upperThreshold(): JsonField = upperThreshold + + @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 [ExpectedValue]. */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [ExpectedValue]. */ + class Builder internal constructor() { + + private var lowerThreshold: JsonField = JsonMissing.of() + private var measurement: JsonField = JsonMissing.of() + private var upperThreshold: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(expectedValue: ExpectedValue) = apply { + lowerThreshold = expectedValue.lowerThreshold + measurement = expectedValue.measurement + upperThreshold = expectedValue.upperThreshold + additionalProperties = expectedValue.additionalProperties.toMutableMap() + } + + /** the lower threshold for the expected value */ + fun lowerThreshold(lowerThreshold: Float?) = + lowerThreshold(JsonField.ofNullable(lowerThreshold)) + + /** + * Alias for [Builder.lowerThreshold]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun lowerThreshold(lowerThreshold: Float) = lowerThreshold(lowerThreshold as Float?) + + /** + * Alias for calling [Builder.lowerThreshold] with `lowerThreshold.orElse(null)`. + */ + fun lowerThreshold(lowerThreshold: Optional) = + lowerThreshold(lowerThreshold.getOrNull()) + + /** + * Sets [Builder.lowerThreshold] to an arbitrary JSON value. + * + * You should usually call [Builder.lowerThreshold] with a well-typed [Float] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun lowerThreshold(lowerThreshold: JsonField) = apply { + this.lowerThreshold = lowerThreshold + } + + /** One of the `measurement` values in the test's thresholds */ + fun measurement(measurement: String) = measurement(JsonField.of(measurement)) + + /** + * Sets [Builder.measurement] to an arbitrary JSON value. + * + * You should usually call [Builder.measurement] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun measurement(measurement: JsonField) = apply { + this.measurement = measurement + } + + /** The upper threshold for the expected value */ + fun upperThreshold(upperThreshold: Float?) = + upperThreshold(JsonField.ofNullable(upperThreshold)) + + /** + * Alias for [Builder.upperThreshold]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun upperThreshold(upperThreshold: Float) = upperThreshold(upperThreshold as Float?) + + /** + * Alias for calling [Builder.upperThreshold] with `upperThreshold.orElse(null)`. + */ + fun upperThreshold(upperThreshold: Optional) = + upperThreshold(upperThreshold.getOrNull()) + + /** + * Sets [Builder.upperThreshold] to an arbitrary JSON value. + * + * You should usually call [Builder.upperThreshold] with a well-typed [Float] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun upperThreshold(upperThreshold: JsonField) = apply { + this.upperThreshold = upperThreshold + } + + 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 [ExpectedValue]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): ExpectedValue = + ExpectedValue( + lowerThreshold, + measurement, + upperThreshold, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): ExpectedValue = apply { + if (validated) { + return@apply + } + + lowerThreshold() + measurement() + upperThreshold() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OpenlayerInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (if (lowerThreshold.asKnown().isPresent) 1 else 0) + + (if (measurement.asKnown().isPresent) 1 else 0) + + (if (upperThreshold.asKnown().isPresent) 1 else 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is ExpectedValue && + lowerThreshold == other.lowerThreshold && + measurement == other.measurement && + upperThreshold == other.upperThreshold && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(lowerThreshold, measurement, upperThreshold, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "ExpectedValue{lowerThreshold=$lowerThreshold, measurement=$measurement, upperThreshold=$upperThreshold, additionalProperties=$additionalProperties}" + } + + class Goal + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val id: JsonField, + private val commentCount: JsonField, + private val creatorId: JsonField, + private val dateArchived: JsonField, + private val dateCreated: JsonField, + private val dateUpdated: JsonField, + private val description: JsonValue, + private val name: JsonField, + private val number: JsonField, + private val originProjectVersionId: JsonField, + private val subtype: JsonField, + private val suggested: JsonField, + private val thresholds: JsonField>, + private val type: JsonField, + private val archived: JsonField, + private val delayWindow: JsonField, + private val evaluationWindow: JsonField, + private val usesMlModel: JsonField, + private val usesProductionData: JsonField, + private val usesReferenceDataset: JsonField, + private val usesTrainingDataset: JsonField, + private val usesValidationDataset: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("id") @ExcludeMissing id: JsonField = JsonMissing.of(), + @JsonProperty("commentCount") + @ExcludeMissing + commentCount: JsonField = JsonMissing.of(), + @JsonProperty("creatorId") + @ExcludeMissing + creatorId: JsonField = JsonMissing.of(), + @JsonProperty("dateArchived") + @ExcludeMissing + dateArchived: JsonField = JsonMissing.of(), + @JsonProperty("dateCreated") + @ExcludeMissing + dateCreated: JsonField = JsonMissing.of(), + @JsonProperty("dateUpdated") + @ExcludeMissing + dateUpdated: JsonField = JsonMissing.of(), + @JsonProperty("description") + @ExcludeMissing + description: JsonValue = JsonMissing.of(), + @JsonProperty("name") @ExcludeMissing name: JsonField = JsonMissing.of(), + @JsonProperty("number") @ExcludeMissing number: JsonField = JsonMissing.of(), + @JsonProperty("originProjectVersionId") + @ExcludeMissing + originProjectVersionId: JsonField = JsonMissing.of(), + @JsonProperty("subtype") + @ExcludeMissing + subtype: JsonField = JsonMissing.of(), + @JsonProperty("suggested") + @ExcludeMissing + suggested: JsonField = JsonMissing.of(), + @JsonProperty("thresholds") + @ExcludeMissing + thresholds: JsonField> = JsonMissing.of(), + @JsonProperty("type") @ExcludeMissing type: JsonField = JsonMissing.of(), + @JsonProperty("archived") + @ExcludeMissing + archived: JsonField = JsonMissing.of(), + @JsonProperty("delayWindow") + @ExcludeMissing + delayWindow: JsonField = JsonMissing.of(), + @JsonProperty("evaluationWindow") + @ExcludeMissing + evaluationWindow: JsonField = JsonMissing.of(), + @JsonProperty("usesMlModel") + @ExcludeMissing + usesMlModel: JsonField = JsonMissing.of(), + @JsonProperty("usesProductionData") + @ExcludeMissing + usesProductionData: JsonField = JsonMissing.of(), + @JsonProperty("usesReferenceDataset") + @ExcludeMissing + usesReferenceDataset: JsonField = JsonMissing.of(), + @JsonProperty("usesTrainingDataset") + @ExcludeMissing + usesTrainingDataset: JsonField = JsonMissing.of(), + @JsonProperty("usesValidationDataset") + @ExcludeMissing + usesValidationDataset: JsonField = JsonMissing.of(), + ) : this( + id, + commentCount, + creatorId, + dateArchived, + dateCreated, + dateUpdated, + description, + name, + number, + originProjectVersionId, + subtype, + suggested, + thresholds, + type, + archived, + delayWindow, + evaluationWindow, + usesMlModel, + usesProductionData, + usesReferenceDataset, + usesTrainingDataset, + usesValidationDataset, + mutableMapOf(), + ) + + /** + * The test id. + * + * @throws OpenlayerInvalidDataException if 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 number of comments on the test. + * + * @throws OpenlayerInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun commentCount(): Long = commentCount.getRequired("commentCount") + + /** + * The test creator id. + * + * @throws OpenlayerInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun creatorId(): Optional = creatorId.getOptional("creatorId") + + /** + * The date the test was archived. + * + * @throws OpenlayerInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun dateArchived(): Optional = dateArchived.getOptional("dateArchived") + + /** + * The creation date. + * + * @throws OpenlayerInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun dateCreated(): OffsetDateTime = dateCreated.getRequired("dateCreated") + + /** + * The last updated date. + * + * @throws OpenlayerInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun dateUpdated(): OffsetDateTime = dateUpdated.getRequired("dateUpdated") + + /** The test description. */ + @JsonProperty("description") @ExcludeMissing fun _description(): JsonValue = description + + /** + * The test name. + * + * @throws OpenlayerInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun name(): String = name.getRequired("name") + + /** + * The test number. + * + * @throws OpenlayerInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun number(): Long = number.getRequired("number") + + /** + * The project version (commit) id where the test was created. + * + * @throws OpenlayerInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun originProjectVersionId(): Optional = + originProjectVersionId.getOptional("originProjectVersionId") + + /** + * The test subtype. + * + * @throws OpenlayerInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun subtype(): Subtype = subtype.getRequired("subtype") + + /** + * Whether the test is suggested or user-created. + * + * @throws OpenlayerInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun suggested(): Boolean = suggested.getRequired("suggested") + + /** + * @throws OpenlayerInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun thresholds(): List = thresholds.getRequired("thresholds") + + /** + * The test type. + * + * @throws OpenlayerInvalidDataException if 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") + + /** + * Whether the test is archived. + * + * @throws OpenlayerInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun archived(): Optional = archived.getOptional("archived") + + /** + * The delay window in seconds. Only applies to tests that use production data. + * + * @throws OpenlayerInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun delayWindow(): Optional = delayWindow.getOptional("delayWindow") + + /** + * The evaluation window in seconds. Only applies to tests that use production data. + * + * @throws OpenlayerInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun evaluationWindow(): Optional = + evaluationWindow.getOptional("evaluationWindow") + + /** + * Whether the test uses an ML model. + * + * @throws OpenlayerInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun usesMlModel(): Optional = usesMlModel.getOptional("usesMlModel") + + /** + * Whether the test uses production data (monitoring mode only). + * + * @throws OpenlayerInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun usesProductionData(): Optional = + usesProductionData.getOptional("usesProductionData") + + /** + * Whether the test uses a reference dataset (monitoring mode only). + * + * @throws OpenlayerInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun usesReferenceDataset(): Optional = + usesReferenceDataset.getOptional("usesReferenceDataset") + + /** + * Whether the test uses a training dataset. + * + * @throws OpenlayerInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun usesTrainingDataset(): Optional = + usesTrainingDataset.getOptional("usesTrainingDataset") + + /** + * Whether the test uses a validation dataset. + * + * @throws OpenlayerInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun usesValidationDataset(): Optional = + usesValidationDataset.getOptional("usesValidationDataset") + + /** + * 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 [commentCount]. + * + * Unlike [commentCount], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("commentCount") + @ExcludeMissing + fun _commentCount(): JsonField = commentCount + + /** + * Returns the raw JSON value of [creatorId]. + * + * Unlike [creatorId], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("creatorId") + @ExcludeMissing + fun _creatorId(): JsonField = creatorId + + /** + * Returns the raw JSON value of [dateArchived]. + * + * Unlike [dateArchived], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("dateArchived") + @ExcludeMissing + fun _dateArchived(): JsonField = dateArchived + + /** + * Returns the raw JSON value of [dateCreated]. + * + * Unlike [dateCreated], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("dateCreated") + @ExcludeMissing + fun _dateCreated(): JsonField = dateCreated + + /** + * Returns the raw JSON value of [dateUpdated]. + * + * Unlike [dateUpdated], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("dateUpdated") + @ExcludeMissing + fun _dateUpdated(): JsonField = dateUpdated + + /** + * 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 [number]. + * + * Unlike [number], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("number") @ExcludeMissing fun _number(): JsonField = number + + /** + * Returns the raw JSON value of [originProjectVersionId]. + * + * Unlike [originProjectVersionId], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("originProjectVersionId") + @ExcludeMissing + fun _originProjectVersionId(): JsonField = originProjectVersionId + + /** + * Returns the raw JSON value of [subtype]. + * + * Unlike [subtype], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("subtype") @ExcludeMissing fun _subtype(): JsonField = subtype + + /** + * Returns the raw JSON value of [suggested]. + * + * Unlike [suggested], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("suggested") + @ExcludeMissing + fun _suggested(): JsonField = suggested + + /** + * Returns the raw JSON value of [thresholds]. + * + * Unlike [thresholds], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("thresholds") + @ExcludeMissing + fun _thresholds(): JsonField> = thresholds + + /** + * 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 + + /** + * Returns the raw JSON value of [archived]. + * + * Unlike [archived], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("archived") @ExcludeMissing fun _archived(): JsonField = archived + + /** + * Returns the raw JSON value of [delayWindow]. + * + * Unlike [delayWindow], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("delayWindow") + @ExcludeMissing + fun _delayWindow(): JsonField = delayWindow + + /** + * Returns the raw JSON value of [evaluationWindow]. + * + * Unlike [evaluationWindow], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("evaluationWindow") + @ExcludeMissing + fun _evaluationWindow(): JsonField = evaluationWindow + + /** + * Returns the raw JSON value of [usesMlModel]. + * + * Unlike [usesMlModel], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("usesMlModel") + @ExcludeMissing + fun _usesMlModel(): JsonField = usesMlModel + + /** + * Returns the raw JSON value of [usesProductionData]. + * + * Unlike [usesProductionData], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("usesProductionData") + @ExcludeMissing + fun _usesProductionData(): JsonField = usesProductionData + + /** + * Returns the raw JSON value of [usesReferenceDataset]. + * + * Unlike [usesReferenceDataset], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("usesReferenceDataset") + @ExcludeMissing + fun _usesReferenceDataset(): JsonField = usesReferenceDataset + + /** + * Returns the raw JSON value of [usesTrainingDataset]. + * + * Unlike [usesTrainingDataset], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("usesTrainingDataset") + @ExcludeMissing + fun _usesTrainingDataset(): JsonField = usesTrainingDataset + + /** + * Returns the raw JSON value of [usesValidationDataset]. + * + * Unlike [usesValidationDataset], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("usesValidationDataset") + @ExcludeMissing + fun _usesValidationDataset(): JsonField = usesValidationDataset + + @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 [Goal]. + * + * The following fields are required: + * ```java + * .id() + * .commentCount() + * .creatorId() + * .dateArchived() + * .dateCreated() + * .dateUpdated() + * .description() + * .name() + * .number() + * .originProjectVersionId() + * .subtype() + * .suggested() + * .thresholds() + * .type() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [Goal]. */ + class Builder internal constructor() { + + private var id: JsonField? = null + private var commentCount: JsonField? = null + private var creatorId: JsonField? = null + private var dateArchived: JsonField? = null + private var dateCreated: JsonField? = null + private var dateUpdated: JsonField? = null + private var description: JsonValue? = null + private var name: JsonField? = null + private var number: JsonField? = null + private var originProjectVersionId: JsonField? = null + private var subtype: JsonField? = null + private var suggested: JsonField? = null + private var thresholds: JsonField>? = null + private var type: JsonField? = null + private var archived: JsonField = JsonMissing.of() + private var delayWindow: JsonField = JsonMissing.of() + private var evaluationWindow: JsonField = JsonMissing.of() + private var usesMlModel: JsonField = JsonMissing.of() + private var usesProductionData: JsonField = JsonMissing.of() + private var usesReferenceDataset: JsonField = JsonMissing.of() + private var usesTrainingDataset: JsonField = JsonMissing.of() + private var usesValidationDataset: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(goal: Goal) = apply { + id = goal.id + commentCount = goal.commentCount + creatorId = goal.creatorId + dateArchived = goal.dateArchived + dateCreated = goal.dateCreated + dateUpdated = goal.dateUpdated + description = goal.description + name = goal.name + number = goal.number + originProjectVersionId = goal.originProjectVersionId + subtype = goal.subtype + suggested = goal.suggested + thresholds = goal.thresholds.map { it.toMutableList() } + type = goal.type + archived = goal.archived + delayWindow = goal.delayWindow + evaluationWindow = goal.evaluationWindow + usesMlModel = goal.usesMlModel + usesProductionData = goal.usesProductionData + usesReferenceDataset = goal.usesReferenceDataset + usesTrainingDataset = goal.usesTrainingDataset + usesValidationDataset = goal.usesValidationDataset + additionalProperties = goal.additionalProperties.toMutableMap() + } + + /** The test 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 } + + /** The number of comments on the test. */ + fun commentCount(commentCount: Long) = commentCount(JsonField.of(commentCount)) + + /** + * Sets [Builder.commentCount] to an arbitrary JSON value. + * + * You should usually call [Builder.commentCount] with a well-typed [Long] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun commentCount(commentCount: JsonField) = apply { + this.commentCount = commentCount + } + + /** The test creator id. */ + fun creatorId(creatorId: String?) = creatorId(JsonField.ofNullable(creatorId)) + + /** Alias for calling [Builder.creatorId] with `creatorId.orElse(null)`. */ + fun creatorId(creatorId: Optional) = creatorId(creatorId.getOrNull()) + + /** + * Sets [Builder.creatorId] to an arbitrary JSON value. + * + * You should usually call [Builder.creatorId] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun creatorId(creatorId: JsonField) = apply { this.creatorId = creatorId } + + /** The date the test was archived. */ + fun dateArchived(dateArchived: OffsetDateTime?) = + dateArchived(JsonField.ofNullable(dateArchived)) + + /** Alias for calling [Builder.dateArchived] with `dateArchived.orElse(null)`. */ + fun dateArchived(dateArchived: Optional) = + dateArchived(dateArchived.getOrNull()) + + /** + * Sets [Builder.dateArchived] to an arbitrary JSON value. + * + * You should usually call [Builder.dateArchived] with a well-typed [OffsetDateTime] + * value instead. This method is primarily for setting the field to an undocumented + * or not yet supported value. + */ + fun dateArchived(dateArchived: JsonField) = apply { + this.dateArchived = dateArchived + } + + /** The creation date. */ + fun dateCreated(dateCreated: OffsetDateTime) = + dateCreated(JsonField.of(dateCreated)) + + /** + * Sets [Builder.dateCreated] to an arbitrary JSON value. + * + * You should usually call [Builder.dateCreated] with a well-typed [OffsetDateTime] + * value instead. This method is primarily for setting the field to an undocumented + * or not yet supported value. + */ + fun dateCreated(dateCreated: JsonField) = apply { + this.dateCreated = dateCreated + } + + /** The last updated date. */ + fun dateUpdated(dateUpdated: OffsetDateTime) = + dateUpdated(JsonField.of(dateUpdated)) + + /** + * Sets [Builder.dateUpdated] to an arbitrary JSON value. + * + * You should usually call [Builder.dateUpdated] with a well-typed [OffsetDateTime] + * value instead. This method is primarily for setting the field to an undocumented + * or not yet supported value. + */ + fun dateUpdated(dateUpdated: JsonField) = apply { + this.dateUpdated = dateUpdated + } + + /** The test description. */ + fun description(description: JsonValue) = apply { this.description = description } + + /** The test 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 test number. */ + fun number(number: Long) = number(JsonField.of(number)) + + /** + * Sets [Builder.number] to an arbitrary JSON value. + * + * You should usually call [Builder.number] with a well-typed [Long] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun number(number: JsonField) = apply { this.number = number } + + /** The project version (commit) id where the test was created. */ + fun originProjectVersionId(originProjectVersionId: String?) = + originProjectVersionId(JsonField.ofNullable(originProjectVersionId)) + + /** + * Alias for calling [Builder.originProjectVersionId] with + * `originProjectVersionId.orElse(null)`. + */ + fun originProjectVersionId(originProjectVersionId: Optional) = + originProjectVersionId(originProjectVersionId.getOrNull()) + + /** + * Sets [Builder.originProjectVersionId] to an arbitrary JSON value. + * + * You should usually call [Builder.originProjectVersionId] with a well-typed + * [String] value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun originProjectVersionId(originProjectVersionId: JsonField) = apply { + this.originProjectVersionId = originProjectVersionId + } + + /** The test subtype. */ + fun subtype(subtype: Subtype) = subtype(JsonField.of(subtype)) + + /** + * Sets [Builder.subtype] to an arbitrary JSON value. + * + * You should usually call [Builder.subtype] with a well-typed [Subtype] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun subtype(subtype: JsonField) = apply { this.subtype = subtype } + + /** Whether the test is suggested or user-created. */ + fun suggested(suggested: Boolean) = suggested(JsonField.of(suggested)) + + /** + * Sets [Builder.suggested] to an arbitrary JSON value. + * + * You should usually call [Builder.suggested] with a well-typed [Boolean] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun suggested(suggested: JsonField) = apply { this.suggested = suggested } + + fun thresholds(thresholds: List) = thresholds(JsonField.of(thresholds)) + + /** + * Sets [Builder.thresholds] to an arbitrary JSON value. + * + * You should usually call [Builder.thresholds] with a well-typed `List` + * value instead. This method is primarily for setting the field to an undocumented + * or not yet supported value. + */ + fun thresholds(thresholds: JsonField>) = apply { + this.thresholds = thresholds.map { it.toMutableList() } + } + + /** + * Adds a single [Threshold] to [thresholds]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addThreshold(threshold: Threshold) = apply { + thresholds = + (thresholds ?: JsonField.of(mutableListOf())).also { + checkKnown("thresholds", it).add(threshold) + } + } + + /** The test 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 } + + /** Whether the test is archived. */ + fun archived(archived: Boolean) = archived(JsonField.of(archived)) + + /** + * Sets [Builder.archived] to an arbitrary JSON value. + * + * You should usually call [Builder.archived] with a well-typed [Boolean] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun archived(archived: JsonField) = apply { this.archived = archived } + + /** The delay window in seconds. Only applies to tests that use production data. */ + fun delayWindow(delayWindow: Double?) = + delayWindow(JsonField.ofNullable(delayWindow)) + + /** + * Alias for [Builder.delayWindow]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun delayWindow(delayWindow: Double) = delayWindow(delayWindow as Double?) + + /** Alias for calling [Builder.delayWindow] with `delayWindow.orElse(null)`. */ + fun delayWindow(delayWindow: Optional) = + delayWindow(delayWindow.getOrNull()) + + /** + * Sets [Builder.delayWindow] to an arbitrary JSON value. + * + * You should usually call [Builder.delayWindow] with a well-typed [Double] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun delayWindow(delayWindow: JsonField) = apply { + this.delayWindow = delayWindow + } + + /** + * The evaluation window in seconds. Only applies to tests that use production data. + */ + fun evaluationWindow(evaluationWindow: Double?) = + evaluationWindow(JsonField.ofNullable(evaluationWindow)) + + /** + * Alias for [Builder.evaluationWindow]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun evaluationWindow(evaluationWindow: Double) = + evaluationWindow(evaluationWindow as Double?) + + /** + * Alias for calling [Builder.evaluationWindow] with + * `evaluationWindow.orElse(null)`. + */ + fun evaluationWindow(evaluationWindow: Optional) = + evaluationWindow(evaluationWindow.getOrNull()) + + /** + * Sets [Builder.evaluationWindow] to an arbitrary JSON value. + * + * You should usually call [Builder.evaluationWindow] with a well-typed [Double] + * value instead. This method is primarily for setting the field to an undocumented + * or not yet supported value. + */ + fun evaluationWindow(evaluationWindow: JsonField) = apply { + this.evaluationWindow = evaluationWindow + } + + /** Whether the test uses an ML model. */ + fun usesMlModel(usesMlModel: Boolean) = usesMlModel(JsonField.of(usesMlModel)) + + /** + * Sets [Builder.usesMlModel] to an arbitrary JSON value. + * + * You should usually call [Builder.usesMlModel] with a well-typed [Boolean] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun usesMlModel(usesMlModel: JsonField) = apply { + this.usesMlModel = usesMlModel + } + + /** Whether the test uses production data (monitoring mode only). */ + fun usesProductionData(usesProductionData: Boolean) = + usesProductionData(JsonField.of(usesProductionData)) + + /** + * Sets [Builder.usesProductionData] to an arbitrary JSON value. + * + * You should usually call [Builder.usesProductionData] with a well-typed [Boolean] + * value instead. This method is primarily for setting the field to an undocumented + * or not yet supported value. + */ + fun usesProductionData(usesProductionData: JsonField) = apply { + this.usesProductionData = usesProductionData + } + + /** Whether the test uses a reference dataset (monitoring mode only). */ + fun usesReferenceDataset(usesReferenceDataset: Boolean) = + usesReferenceDataset(JsonField.of(usesReferenceDataset)) + + /** + * Sets [Builder.usesReferenceDataset] to an arbitrary JSON value. + * + * You should usually call [Builder.usesReferenceDataset] with a well-typed + * [Boolean] value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun usesReferenceDataset(usesReferenceDataset: JsonField) = apply { + this.usesReferenceDataset = usesReferenceDataset + } + + /** Whether the test uses a training dataset. */ + fun usesTrainingDataset(usesTrainingDataset: Boolean) = + usesTrainingDataset(JsonField.of(usesTrainingDataset)) + + /** + * Sets [Builder.usesTrainingDataset] to an arbitrary JSON value. + * + * You should usually call [Builder.usesTrainingDataset] with a well-typed [Boolean] + * value instead. This method is primarily for setting the field to an undocumented + * or not yet supported value. + */ + fun usesTrainingDataset(usesTrainingDataset: JsonField) = apply { + this.usesTrainingDataset = usesTrainingDataset + } + + /** Whether the test uses a validation dataset. */ + fun usesValidationDataset(usesValidationDataset: Boolean) = + usesValidationDataset(JsonField.of(usesValidationDataset)) + + /** + * Sets [Builder.usesValidationDataset] to an arbitrary JSON value. + * + * You should usually call [Builder.usesValidationDataset] with a well-typed + * [Boolean] value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun usesValidationDataset(usesValidationDataset: JsonField) = apply { + this.usesValidationDataset = usesValidationDataset + } + + 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 [Goal]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .id() + * .commentCount() + * .creatorId() + * .dateArchived() + * .dateCreated() + * .dateUpdated() + * .description() + * .name() + * .number() + * .originProjectVersionId() + * .subtype() + * .suggested() + * .thresholds() + * .type() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): Goal = + Goal( + checkRequired("id", id), + checkRequired("commentCount", commentCount), + checkRequired("creatorId", creatorId), + checkRequired("dateArchived", dateArchived), + checkRequired("dateCreated", dateCreated), + checkRequired("dateUpdated", dateUpdated), + checkRequired("description", description), + checkRequired("name", name), + checkRequired("number", number), + checkRequired("originProjectVersionId", originProjectVersionId), + checkRequired("subtype", subtype), + checkRequired("suggested", suggested), + checkRequired("thresholds", thresholds).map { it.toImmutable() }, + checkRequired("type", type), + archived, + delayWindow, + evaluationWindow, + usesMlModel, + usesProductionData, + usesReferenceDataset, + usesTrainingDataset, + usesValidationDataset, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): Goal = apply { + if (validated) { + return@apply + } + + id() + commentCount() + creatorId() + dateArchived() + dateCreated() + dateUpdated() + name() + number() + originProjectVersionId() + subtype().validate() + suggested() + thresholds().forEach { it.validate() } + type().validate() + archived() + delayWindow() + evaluationWindow() + usesMlModel() + usesProductionData() + usesReferenceDataset() + usesTrainingDataset() + usesValidationDataset() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OpenlayerInvalidDataException) { + false + } + + /** + * Returns a 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 (commentCount.asKnown().isPresent) 1 else 0) + + (if (creatorId.asKnown().isPresent) 1 else 0) + + (if (dateArchived.asKnown().isPresent) 1 else 0) + + (if (dateCreated.asKnown().isPresent) 1 else 0) + + (if (dateUpdated.asKnown().isPresent) 1 else 0) + + (if (name.asKnown().isPresent) 1 else 0) + + (if (number.asKnown().isPresent) 1 else 0) + + (if (originProjectVersionId.asKnown().isPresent) 1 else 0) + + (subtype.asKnown().getOrNull()?.validity() ?: 0) + + (if (suggested.asKnown().isPresent) 1 else 0) + + (thresholds.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + + (type.asKnown().getOrNull()?.validity() ?: 0) + + (if (archived.asKnown().isPresent) 1 else 0) + + (if (delayWindow.asKnown().isPresent) 1 else 0) + + (if (evaluationWindow.asKnown().isPresent) 1 else 0) + + (if (usesMlModel.asKnown().isPresent) 1 else 0) + + (if (usesProductionData.asKnown().isPresent) 1 else 0) + + (if (usesReferenceDataset.asKnown().isPresent) 1 else 0) + + (if (usesTrainingDataset.asKnown().isPresent) 1 else 0) + + (if (usesValidationDataset.asKnown().isPresent) 1 else 0) + + /** The test subtype. */ + class Subtype @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 ANOMALOUS_COLUMN_COUNT = of("anomalousColumnCount") + + @JvmField val CHARACTER_LENGTH = of("characterLength") + + @JvmField val CLASS_IMBALANCE_RATIO = of("classImbalanceRatio") + + @JvmField + val EXPECT_COLUMN_A_TO_BE_IN_COLUMN_B = of("expectColumnAToBeInColumnB") + + @JvmField val COLUMN_AVERAGE = of("columnAverage") + + @JvmField val COLUMN_DRIFT = of("columnDrift") + + @JvmField val COLUMN_STATISTIC = of("columnStatistic") + + @JvmField val COLUMN_VALUES_MATCH = of("columnValuesMatch") + + @JvmField val CONFLICTING_LABEL_ROW_COUNT = of("conflictingLabelRowCount") + + @JvmField val CONTAINS_PII = of("containsPii") + + @JvmField val CONTAINS_VALID_URL = of("containsValidUrl") + + @JvmField val CORRELATED_FEATURE_COUNT = of("correlatedFeatureCount") + + @JvmField val CUSTOM_METRIC_THRESHOLD = of("customMetricThreshold") + + @JvmField val DUPLICATE_ROW_COUNT = of("duplicateRowCount") + + @JvmField val EMPTY_FEATURE = of("emptyFeature") + + @JvmField val EMPTY_FEATURE_COUNT = of("emptyFeatureCount") + + @JvmField val DRIFTED_FEATURE_COUNT = of("driftedFeatureCount") + + @JvmField val FEATURE_MISSING_VALUES = of("featureMissingValues") + + @JvmField val FEATURE_VALUE_VALIDATION = of("featureValueValidation") + + @JvmField val GREAT_EXPECTATIONS = of("greatExpectations") + + @JvmField val GROUP_BY_COLUMN_STATS_CHECK = of("groupByColumnStatsCheck") + + @JvmField val ILL_FORMED_ROW_COUNT = of("illFormedRowCount") + + @JvmField val IS_CODE = of("isCode") + + @JvmField val IS_JSON = of("isJson") + + @JvmField val LLM_RUBRIC_THRESHOLD_V2 = of("llmRubricThresholdV2") + + @JvmField val LABEL_DRIFT = of("labelDrift") + + @JvmField val METRIC_THRESHOLD = of("metricThreshold") + + @JvmField val NEW_CATEGORY_COUNT = of("newCategoryCount") + + @JvmField val NEW_LABEL_COUNT = of("newLabelCount") + + @JvmField val NULL_ROW_COUNT = of("nullRowCount") + + @JvmField val ROW_COUNT = of("rowCount") + + @JvmField val PP_SCORE_VALUE_VALIDATION = of("ppScoreValueValidation") + + @JvmField val QUASI_CONSTANT_FEATURE = of("quasiConstantFeature") + + @JvmField val QUASI_CONSTANT_FEATURE_COUNT = of("quasiConstantFeatureCount") + + @JvmField val SQL_QUERY = of("sqlQuery") + + @JvmField val DTYPE_VALIDATION = of("dtypeValidation") + + @JvmField val SENTENCE_LENGTH = of("sentenceLength") + + @JvmField val SIZE_RATIO = of("sizeRatio") + + @JvmField val SPECIAL_CHARACTERS_RATIO = of("specialCharactersRatio") + + @JvmField val STRING_VALIDATION = of("stringValidation") + + @JvmField val TRAIN_VAL_LEAKAGE_ROW_COUNT = of("trainValLeakageRowCount") + + @JvmStatic fun of(value: String) = Subtype(JsonField.of(value)) + } + + /** An enum containing [Subtype]'s known values. */ + enum class Known { + ANOMALOUS_COLUMN_COUNT, + CHARACTER_LENGTH, + CLASS_IMBALANCE_RATIO, + EXPECT_COLUMN_A_TO_BE_IN_COLUMN_B, + COLUMN_AVERAGE, + COLUMN_DRIFT, + COLUMN_STATISTIC, + COLUMN_VALUES_MATCH, + CONFLICTING_LABEL_ROW_COUNT, + CONTAINS_PII, + CONTAINS_VALID_URL, + CORRELATED_FEATURE_COUNT, + CUSTOM_METRIC_THRESHOLD, + DUPLICATE_ROW_COUNT, + EMPTY_FEATURE, + EMPTY_FEATURE_COUNT, + DRIFTED_FEATURE_COUNT, + FEATURE_MISSING_VALUES, + FEATURE_VALUE_VALIDATION, + GREAT_EXPECTATIONS, + GROUP_BY_COLUMN_STATS_CHECK, + ILL_FORMED_ROW_COUNT, + IS_CODE, + IS_JSON, + LLM_RUBRIC_THRESHOLD_V2, + LABEL_DRIFT, + METRIC_THRESHOLD, + NEW_CATEGORY_COUNT, + NEW_LABEL_COUNT, + NULL_ROW_COUNT, + ROW_COUNT, + PP_SCORE_VALUE_VALIDATION, + QUASI_CONSTANT_FEATURE, + QUASI_CONSTANT_FEATURE_COUNT, + SQL_QUERY, + DTYPE_VALIDATION, + SENTENCE_LENGTH, + SIZE_RATIO, + SPECIAL_CHARACTERS_RATIO, + STRING_VALIDATION, + TRAIN_VAL_LEAKAGE_ROW_COUNT, + } + + /** + * An enum containing [Subtype]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [Subtype] 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 { + ANOMALOUS_COLUMN_COUNT, + CHARACTER_LENGTH, + CLASS_IMBALANCE_RATIO, + EXPECT_COLUMN_A_TO_BE_IN_COLUMN_B, + COLUMN_AVERAGE, + COLUMN_DRIFT, + COLUMN_STATISTIC, + COLUMN_VALUES_MATCH, + CONFLICTING_LABEL_ROW_COUNT, + CONTAINS_PII, + CONTAINS_VALID_URL, + CORRELATED_FEATURE_COUNT, + CUSTOM_METRIC_THRESHOLD, + DUPLICATE_ROW_COUNT, + EMPTY_FEATURE, + EMPTY_FEATURE_COUNT, + DRIFTED_FEATURE_COUNT, + FEATURE_MISSING_VALUES, + FEATURE_VALUE_VALIDATION, + GREAT_EXPECTATIONS, + GROUP_BY_COLUMN_STATS_CHECK, + ILL_FORMED_ROW_COUNT, + IS_CODE, + IS_JSON, + LLM_RUBRIC_THRESHOLD_V2, + LABEL_DRIFT, + METRIC_THRESHOLD, + NEW_CATEGORY_COUNT, + NEW_LABEL_COUNT, + NULL_ROW_COUNT, + ROW_COUNT, + PP_SCORE_VALUE_VALIDATION, + QUASI_CONSTANT_FEATURE, + QUASI_CONSTANT_FEATURE_COUNT, + SQL_QUERY, + DTYPE_VALIDATION, + SENTENCE_LENGTH, + SIZE_RATIO, + SPECIAL_CHARACTERS_RATIO, + STRING_VALIDATION, + TRAIN_VAL_LEAKAGE_ROW_COUNT, + /** + * An enum member indicating that [Subtype] 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) { + ANOMALOUS_COLUMN_COUNT -> Value.ANOMALOUS_COLUMN_COUNT + CHARACTER_LENGTH -> Value.CHARACTER_LENGTH + CLASS_IMBALANCE_RATIO -> Value.CLASS_IMBALANCE_RATIO + EXPECT_COLUMN_A_TO_BE_IN_COLUMN_B -> Value.EXPECT_COLUMN_A_TO_BE_IN_COLUMN_B + COLUMN_AVERAGE -> Value.COLUMN_AVERAGE + COLUMN_DRIFT -> Value.COLUMN_DRIFT + COLUMN_STATISTIC -> Value.COLUMN_STATISTIC + COLUMN_VALUES_MATCH -> Value.COLUMN_VALUES_MATCH + CONFLICTING_LABEL_ROW_COUNT -> Value.CONFLICTING_LABEL_ROW_COUNT + CONTAINS_PII -> Value.CONTAINS_PII + CONTAINS_VALID_URL -> Value.CONTAINS_VALID_URL + CORRELATED_FEATURE_COUNT -> Value.CORRELATED_FEATURE_COUNT + CUSTOM_METRIC_THRESHOLD -> Value.CUSTOM_METRIC_THRESHOLD + DUPLICATE_ROW_COUNT -> Value.DUPLICATE_ROW_COUNT + EMPTY_FEATURE -> Value.EMPTY_FEATURE + EMPTY_FEATURE_COUNT -> Value.EMPTY_FEATURE_COUNT + DRIFTED_FEATURE_COUNT -> Value.DRIFTED_FEATURE_COUNT + FEATURE_MISSING_VALUES -> Value.FEATURE_MISSING_VALUES + FEATURE_VALUE_VALIDATION -> Value.FEATURE_VALUE_VALIDATION + GREAT_EXPECTATIONS -> Value.GREAT_EXPECTATIONS + GROUP_BY_COLUMN_STATS_CHECK -> Value.GROUP_BY_COLUMN_STATS_CHECK + ILL_FORMED_ROW_COUNT -> Value.ILL_FORMED_ROW_COUNT + IS_CODE -> Value.IS_CODE + IS_JSON -> Value.IS_JSON + LLM_RUBRIC_THRESHOLD_V2 -> Value.LLM_RUBRIC_THRESHOLD_V2 + LABEL_DRIFT -> Value.LABEL_DRIFT + METRIC_THRESHOLD -> Value.METRIC_THRESHOLD + NEW_CATEGORY_COUNT -> Value.NEW_CATEGORY_COUNT + NEW_LABEL_COUNT -> Value.NEW_LABEL_COUNT + NULL_ROW_COUNT -> Value.NULL_ROW_COUNT + ROW_COUNT -> Value.ROW_COUNT + PP_SCORE_VALUE_VALIDATION -> Value.PP_SCORE_VALUE_VALIDATION + QUASI_CONSTANT_FEATURE -> Value.QUASI_CONSTANT_FEATURE + QUASI_CONSTANT_FEATURE_COUNT -> Value.QUASI_CONSTANT_FEATURE_COUNT + SQL_QUERY -> Value.SQL_QUERY + DTYPE_VALIDATION -> Value.DTYPE_VALIDATION + SENTENCE_LENGTH -> Value.SENTENCE_LENGTH + SIZE_RATIO -> Value.SIZE_RATIO + SPECIAL_CHARACTERS_RATIO -> Value.SPECIAL_CHARACTERS_RATIO + STRING_VALIDATION -> Value.STRING_VALIDATION + TRAIN_VAL_LEAKAGE_ROW_COUNT -> Value.TRAIN_VAL_LEAKAGE_ROW_COUNT + 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 OpenlayerInvalidDataException if this class instance's value is a not a + * known member. + */ + fun known(): Known = + when (this) { + ANOMALOUS_COLUMN_COUNT -> Known.ANOMALOUS_COLUMN_COUNT + CHARACTER_LENGTH -> Known.CHARACTER_LENGTH + CLASS_IMBALANCE_RATIO -> Known.CLASS_IMBALANCE_RATIO + EXPECT_COLUMN_A_TO_BE_IN_COLUMN_B -> Known.EXPECT_COLUMN_A_TO_BE_IN_COLUMN_B + COLUMN_AVERAGE -> Known.COLUMN_AVERAGE + COLUMN_DRIFT -> Known.COLUMN_DRIFT + COLUMN_STATISTIC -> Known.COLUMN_STATISTIC + COLUMN_VALUES_MATCH -> Known.COLUMN_VALUES_MATCH + CONFLICTING_LABEL_ROW_COUNT -> Known.CONFLICTING_LABEL_ROW_COUNT + CONTAINS_PII -> Known.CONTAINS_PII + CONTAINS_VALID_URL -> Known.CONTAINS_VALID_URL + CORRELATED_FEATURE_COUNT -> Known.CORRELATED_FEATURE_COUNT + CUSTOM_METRIC_THRESHOLD -> Known.CUSTOM_METRIC_THRESHOLD + DUPLICATE_ROW_COUNT -> Known.DUPLICATE_ROW_COUNT + EMPTY_FEATURE -> Known.EMPTY_FEATURE + EMPTY_FEATURE_COUNT -> Known.EMPTY_FEATURE_COUNT + DRIFTED_FEATURE_COUNT -> Known.DRIFTED_FEATURE_COUNT + FEATURE_MISSING_VALUES -> Known.FEATURE_MISSING_VALUES + FEATURE_VALUE_VALIDATION -> Known.FEATURE_VALUE_VALIDATION + GREAT_EXPECTATIONS -> Known.GREAT_EXPECTATIONS + GROUP_BY_COLUMN_STATS_CHECK -> Known.GROUP_BY_COLUMN_STATS_CHECK + ILL_FORMED_ROW_COUNT -> Known.ILL_FORMED_ROW_COUNT + IS_CODE -> Known.IS_CODE + IS_JSON -> Known.IS_JSON + LLM_RUBRIC_THRESHOLD_V2 -> Known.LLM_RUBRIC_THRESHOLD_V2 + LABEL_DRIFT -> Known.LABEL_DRIFT + METRIC_THRESHOLD -> Known.METRIC_THRESHOLD + NEW_CATEGORY_COUNT -> Known.NEW_CATEGORY_COUNT + NEW_LABEL_COUNT -> Known.NEW_LABEL_COUNT + NULL_ROW_COUNT -> Known.NULL_ROW_COUNT + ROW_COUNT -> Known.ROW_COUNT + PP_SCORE_VALUE_VALIDATION -> Known.PP_SCORE_VALUE_VALIDATION + QUASI_CONSTANT_FEATURE -> Known.QUASI_CONSTANT_FEATURE + QUASI_CONSTANT_FEATURE_COUNT -> Known.QUASI_CONSTANT_FEATURE_COUNT + SQL_QUERY -> Known.SQL_QUERY + DTYPE_VALIDATION -> Known.DTYPE_VALIDATION + SENTENCE_LENGTH -> Known.SENTENCE_LENGTH + SIZE_RATIO -> Known.SIZE_RATIO + SPECIAL_CHARACTERS_RATIO -> Known.SPECIAL_CHARACTERS_RATIO + STRING_VALIDATION -> Known.STRING_VALIDATION + TRAIN_VAL_LEAKAGE_ROW_COUNT -> Known.TRAIN_VAL_LEAKAGE_ROW_COUNT + else -> throw OpenlayerInvalidDataException("Unknown Subtype: $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 OpenlayerInvalidDataException if this class instance's value does not + * have the expected primitive type. + */ + fun asString(): String = + _value().asString().orElseThrow { + OpenlayerInvalidDataException("Value is not a String") + } + + private var validated: Boolean = false + + fun validate(): Subtype = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OpenlayerInvalidDataException) { + false + } + + /** + * Returns a 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 Subtype && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + class Threshold + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val insightName: JsonField, + private val insightParameters: JsonField>, + private val measurement: JsonField, + private val operator: JsonField, + private val thresholdMode: JsonField, + private val value: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("insightName") + @ExcludeMissing + insightName: JsonField = JsonMissing.of(), + @JsonProperty("insightParameters") + @ExcludeMissing + insightParameters: JsonField> = JsonMissing.of(), + @JsonProperty("measurement") + @ExcludeMissing + measurement: JsonField = JsonMissing.of(), + @JsonProperty("operator") + @ExcludeMissing + operator: JsonField = JsonMissing.of(), + @JsonProperty("thresholdMode") + @ExcludeMissing + thresholdMode: JsonField = JsonMissing.of(), + @JsonProperty("value") + @ExcludeMissing + value: JsonField = JsonMissing.of(), + ) : this( + insightName, + insightParameters, + measurement, + operator, + thresholdMode, + value, + mutableMapOf(), + ) + + /** + * The insight name to be evaluated. + * + * @throws OpenlayerInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun insightName(): Optional = insightName.getOptional("insightName") + + /** + * The insight parameters. Required only for some test subtypes. For example, for + * tests that require a column name, the insight parameters will be + * [{'name': 'column_name', 'value': 'Age'}] + * + * @throws OpenlayerInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun insightParameters(): Optional> = + insightParameters.getOptional("insightParameters") + + /** + * The measurement to be evaluated. + * + * @throws OpenlayerInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun measurement(): Optional = measurement.getOptional("measurement") + + /** + * The operator to be used for the evaluation. + * + * @throws OpenlayerInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun operator(): Optional = operator.getOptional("operator") + + /** + * Whether to use automatic anomaly detection or manual thresholds + * + * @throws OpenlayerInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun thresholdMode(): Optional = + thresholdMode.getOptional("thresholdMode") + + /** + * The value to be compared. + * + * @throws OpenlayerInvalidDataException 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 [insightName]. + * + * Unlike [insightName], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("insightName") + @ExcludeMissing + fun _insightName(): JsonField = insightName + + /** + * Returns the raw JSON value of [insightParameters]. + * + * Unlike [insightParameters], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("insightParameters") + @ExcludeMissing + fun _insightParameters(): JsonField> = insightParameters + + /** + * Returns the raw JSON value of [measurement]. + * + * Unlike [measurement], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("measurement") + @ExcludeMissing + fun _measurement(): JsonField = measurement + + /** + * Returns the raw JSON value of [operator]. + * + * Unlike [operator], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("operator") + @ExcludeMissing + fun _operator(): JsonField = operator + + /** + * Returns the raw JSON value of [thresholdMode]. + * + * Unlike [thresholdMode], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("thresholdMode") + @ExcludeMissing + fun _thresholdMode(): JsonField = thresholdMode + + /** + * 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 [Threshold]. */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [Threshold]. */ + class Builder internal constructor() { + + private var insightName: JsonField = JsonMissing.of() + private var insightParameters: JsonField>? = null + private var measurement: JsonField = JsonMissing.of() + private var operator: JsonField = JsonMissing.of() + private var thresholdMode: JsonField = JsonMissing.of() + private var value: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(threshold: Threshold) = apply { + insightName = threshold.insightName + insightParameters = threshold.insightParameters.map { it.toMutableList() } + measurement = threshold.measurement + operator = threshold.operator + thresholdMode = threshold.thresholdMode + value = threshold.value + additionalProperties = threshold.additionalProperties.toMutableMap() + } + + /** The insight name to be evaluated. */ + fun insightName(insightName: InsightName) = + insightName(JsonField.of(insightName)) + + /** + * Sets [Builder.insightName] to an arbitrary JSON value. + * + * You should usually call [Builder.insightName] with a well-typed [InsightName] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun insightName(insightName: JsonField) = apply { + this.insightName = insightName + } + + /** + * The insight parameters. Required only for some test subtypes. For example, + * for tests that require a column name, the insight parameters will be + * [{'name': 'column_name', 'value': 'Age'}] + */ + fun insightParameters(insightParameters: List?) = + insightParameters(JsonField.ofNullable(insightParameters)) + + /** + * Alias for calling [Builder.insightParameters] with + * `insightParameters.orElse(null)`. + */ + fun insightParameters(insightParameters: Optional>) = + insightParameters(insightParameters.getOrNull()) + + /** + * Sets [Builder.insightParameters] to an arbitrary JSON value. + * + * You should usually call [Builder.insightParameters] with a well-typed + * `List` value instead. This method is primarily for setting + * the field to an undocumented or not yet supported value. + */ + fun insightParameters(insightParameters: JsonField>) = + apply { + this.insightParameters = insightParameters.map { it.toMutableList() } + } + + /** + * Adds a single [InsightParameter] to [insightParameters]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addInsightParameter(insightParameter: InsightParameter) = apply { + insightParameters = + (insightParameters ?: JsonField.of(mutableListOf())).also { + checkKnown("insightParameters", it).add(insightParameter) + } + } + + /** The measurement to be evaluated. */ + fun measurement(measurement: String) = measurement(JsonField.of(measurement)) + + /** + * Sets [Builder.measurement] to an arbitrary JSON value. + * + * You should usually call [Builder.measurement] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun measurement(measurement: JsonField) = apply { + this.measurement = measurement + } + + /** The operator to be used for the evaluation. */ + fun operator(operator: Operator) = operator(JsonField.of(operator)) + + /** + * Sets [Builder.operator] to an arbitrary JSON value. + * + * You should usually call [Builder.operator] with a well-typed [Operator] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun operator(operator: JsonField) = apply { this.operator = operator } + + /** Whether to use automatic anomaly detection or manual thresholds */ + fun thresholdMode(thresholdMode: ThresholdMode) = + thresholdMode(JsonField.of(thresholdMode)) + + /** + * Sets [Builder.thresholdMode] to an arbitrary JSON value. + * + * You should usually call [Builder.thresholdMode] with a well-typed + * [ThresholdMode] value instead. This method is primarily for setting the field + * to an undocumented or not yet supported value. + */ + fun thresholdMode(thresholdMode: JsonField) = apply { + this.thresholdMode = thresholdMode + } + + /** The value to be compared. */ + fun value(value: Value) = value(JsonField.of(value)) + + /** + * Sets [Builder.value] to an arbitrary JSON value. + * + * You should usually call [Builder.value] with a well-typed [Value] 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 } + + /** Alias for calling [value] with `Value.ofNumber(number)`. */ + fun value(number: Double) = value(Value.ofNumber(number)) + + /** Alias for calling [value] with `Value.ofBool(bool)`. */ + fun value(bool: Boolean) = value(Value.ofBool(bool)) + + /** Alias for calling [value] with `Value.ofString(string)`. */ + fun value(string: String) = value(Value.ofString(string)) + + /** Alias for calling [value] with `Value.ofStrings(strings)`. */ + fun valueOfStrings(strings: List) = value(Value.ofStrings(strings)) + + 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 [Threshold]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): Threshold = + Threshold( + insightName, + (insightParameters ?: JsonMissing.of()).map { it.toImmutable() }, + measurement, + operator, + thresholdMode, + value, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): Threshold = apply { + if (validated) { + return@apply + } + + insightName().ifPresent { it.validate() } + insightParameters().ifPresent { it.forEach { it.validate() } } + measurement() + operator().ifPresent { it.validate() } + thresholdMode().ifPresent { it.validate() } + value().ifPresent { it.validate() } + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OpenlayerInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (insightName.asKnown().getOrNull()?.validity() ?: 0) + + (insightParameters.asKnown().getOrNull()?.sumOf { it.validity().toInt() } + ?: 0) + + (if (measurement.asKnown().isPresent) 1 else 0) + + (operator.asKnown().getOrNull()?.validity() ?: 0) + + (thresholdMode.asKnown().getOrNull()?.validity() ?: 0) + + (value.asKnown().getOrNull()?.validity() ?: 0) + + /** The insight name to be evaluated. */ + class InsightName + @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 CHARACTER_LENGTH = of("characterLength") + + @JvmField val CLASS_IMBALANCE = of("classImbalance") + + @JvmField + val EXPECT_COLUMN_A_TO_BE_IN_COLUMN_B = of("expectColumnAToBeInColumnB") + + @JvmField val COLUMN_AVERAGE = of("columnAverage") + + @JvmField val COLUMN_DRIFT = of("columnDrift") + + @JvmField val COLUMN_VALUES_MATCH = of("columnValuesMatch") + + @JvmField val CONFIDENCE_DISTRIBUTION = of("confidenceDistribution") + + @JvmField val CONFLICTING_LABEL_ROW_COUNT = of("conflictingLabelRowCount") + + @JvmField val CONTAINS_PII = of("containsPii") + + @JvmField val CONTAINS_VALID_URL = of("containsValidUrl") + + @JvmField val CORRELATED_FEATURES = of("correlatedFeatures") + + @JvmField val CUSTOM_METRIC = of("customMetric") + + @JvmField val DUPLICATE_ROW_COUNT = of("duplicateRowCount") + + @JvmField val EMPTY_FEATURES = of("emptyFeatures") + + @JvmField val FEATURE_DRIFT = of("featureDrift") + + @JvmField val FEATURE_PROFILE = of("featureProfile") + + @JvmField val GREAT_EXPECTATIONS = of("greatExpectations") + + @JvmField val GROUP_BY_COLUMN_STATS_CHECK = of("groupByColumnStatsCheck") + + @JvmField val ILL_FORMED_ROW_COUNT = of("illFormedRowCount") + + @JvmField val IS_CODE = of("isCode") + + @JvmField val IS_JSON = of("isJson") + + @JvmField val LLM_RUBRIC_V2 = of("llmRubricV2") + + @JvmField val LABEL_DRIFT = of("labelDrift") + + @JvmField val METRICS = of("metrics") + + @JvmField val NEW_CATEGORIES = of("newCategories") + + @JvmField val NEW_LABELS = of("newLabels") + + @JvmField val NULL_ROW_COUNT = of("nullRowCount") + + @JvmField val PP_SCORE = of("ppScore") + + @JvmField val QUASI_CONSTANT_FEATURES = of("quasiConstantFeatures") + + @JvmField val SENTENCE_LENGTH = of("sentenceLength") + + @JvmField val SIZE_RATIO = of("sizeRatio") + + @JvmField val SPECIAL_CHARACTERS = of("specialCharacters") + + @JvmField val STRING_VALIDATION = of("stringValidation") + + @JvmField val TRAIN_VAL_LEAKAGE_ROW_COUNT = of("trainValLeakageRowCount") + + @JvmStatic fun of(value: String) = InsightName(JsonField.of(value)) + } + + /** An enum containing [InsightName]'s known values. */ + enum class Known { + CHARACTER_LENGTH, + CLASS_IMBALANCE, + EXPECT_COLUMN_A_TO_BE_IN_COLUMN_B, + COLUMN_AVERAGE, + COLUMN_DRIFT, + COLUMN_VALUES_MATCH, + CONFIDENCE_DISTRIBUTION, + CONFLICTING_LABEL_ROW_COUNT, + CONTAINS_PII, + CONTAINS_VALID_URL, + CORRELATED_FEATURES, + CUSTOM_METRIC, + DUPLICATE_ROW_COUNT, + EMPTY_FEATURES, + FEATURE_DRIFT, + FEATURE_PROFILE, + GREAT_EXPECTATIONS, + GROUP_BY_COLUMN_STATS_CHECK, + ILL_FORMED_ROW_COUNT, + IS_CODE, + IS_JSON, + LLM_RUBRIC_V2, + LABEL_DRIFT, + METRICS, + NEW_CATEGORIES, + NEW_LABELS, + NULL_ROW_COUNT, + PP_SCORE, + QUASI_CONSTANT_FEATURES, + SENTENCE_LENGTH, + SIZE_RATIO, + SPECIAL_CHARACTERS, + STRING_VALIDATION, + TRAIN_VAL_LEAKAGE_ROW_COUNT, + } + + /** + * An enum containing [InsightName]'s known values, as well as an [_UNKNOWN] + * member. + * + * An instance of [InsightName] 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 { + CHARACTER_LENGTH, + CLASS_IMBALANCE, + EXPECT_COLUMN_A_TO_BE_IN_COLUMN_B, + COLUMN_AVERAGE, + COLUMN_DRIFT, + COLUMN_VALUES_MATCH, + CONFIDENCE_DISTRIBUTION, + CONFLICTING_LABEL_ROW_COUNT, + CONTAINS_PII, + CONTAINS_VALID_URL, + CORRELATED_FEATURES, + CUSTOM_METRIC, + DUPLICATE_ROW_COUNT, + EMPTY_FEATURES, + FEATURE_DRIFT, + FEATURE_PROFILE, + GREAT_EXPECTATIONS, + GROUP_BY_COLUMN_STATS_CHECK, + ILL_FORMED_ROW_COUNT, + IS_CODE, + IS_JSON, + LLM_RUBRIC_V2, + LABEL_DRIFT, + METRICS, + NEW_CATEGORIES, + NEW_LABELS, + NULL_ROW_COUNT, + PP_SCORE, + QUASI_CONSTANT_FEATURES, + SENTENCE_LENGTH, + SIZE_RATIO, + SPECIAL_CHARACTERS, + STRING_VALIDATION, + TRAIN_VAL_LEAKAGE_ROW_COUNT, + /** + * An enum member indicating that [InsightName] 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) { + CHARACTER_LENGTH -> Value.CHARACTER_LENGTH + CLASS_IMBALANCE -> Value.CLASS_IMBALANCE + EXPECT_COLUMN_A_TO_BE_IN_COLUMN_B -> + Value.EXPECT_COLUMN_A_TO_BE_IN_COLUMN_B + COLUMN_AVERAGE -> Value.COLUMN_AVERAGE + COLUMN_DRIFT -> Value.COLUMN_DRIFT + COLUMN_VALUES_MATCH -> Value.COLUMN_VALUES_MATCH + CONFIDENCE_DISTRIBUTION -> Value.CONFIDENCE_DISTRIBUTION + CONFLICTING_LABEL_ROW_COUNT -> Value.CONFLICTING_LABEL_ROW_COUNT + CONTAINS_PII -> Value.CONTAINS_PII + CONTAINS_VALID_URL -> Value.CONTAINS_VALID_URL + CORRELATED_FEATURES -> Value.CORRELATED_FEATURES + CUSTOM_METRIC -> Value.CUSTOM_METRIC + DUPLICATE_ROW_COUNT -> Value.DUPLICATE_ROW_COUNT + EMPTY_FEATURES -> Value.EMPTY_FEATURES + FEATURE_DRIFT -> Value.FEATURE_DRIFT + FEATURE_PROFILE -> Value.FEATURE_PROFILE + GREAT_EXPECTATIONS -> Value.GREAT_EXPECTATIONS + GROUP_BY_COLUMN_STATS_CHECK -> Value.GROUP_BY_COLUMN_STATS_CHECK + ILL_FORMED_ROW_COUNT -> Value.ILL_FORMED_ROW_COUNT + IS_CODE -> Value.IS_CODE + IS_JSON -> Value.IS_JSON + LLM_RUBRIC_V2 -> Value.LLM_RUBRIC_V2 + LABEL_DRIFT -> Value.LABEL_DRIFT + METRICS -> Value.METRICS + NEW_CATEGORIES -> Value.NEW_CATEGORIES + NEW_LABELS -> Value.NEW_LABELS + NULL_ROW_COUNT -> Value.NULL_ROW_COUNT + PP_SCORE -> Value.PP_SCORE + QUASI_CONSTANT_FEATURES -> Value.QUASI_CONSTANT_FEATURES + SENTENCE_LENGTH -> Value.SENTENCE_LENGTH + SIZE_RATIO -> Value.SIZE_RATIO + SPECIAL_CHARACTERS -> Value.SPECIAL_CHARACTERS + STRING_VALIDATION -> Value.STRING_VALIDATION + TRAIN_VAL_LEAKAGE_ROW_COUNT -> Value.TRAIN_VAL_LEAKAGE_ROW_COUNT + 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 OpenlayerInvalidDataException if this class instance's value is a not + * a known member. + */ + fun known(): Known = + when (this) { + CHARACTER_LENGTH -> Known.CHARACTER_LENGTH + CLASS_IMBALANCE -> Known.CLASS_IMBALANCE + EXPECT_COLUMN_A_TO_BE_IN_COLUMN_B -> + Known.EXPECT_COLUMN_A_TO_BE_IN_COLUMN_B + COLUMN_AVERAGE -> Known.COLUMN_AVERAGE + COLUMN_DRIFT -> Known.COLUMN_DRIFT + COLUMN_VALUES_MATCH -> Known.COLUMN_VALUES_MATCH + CONFIDENCE_DISTRIBUTION -> Known.CONFIDENCE_DISTRIBUTION + CONFLICTING_LABEL_ROW_COUNT -> Known.CONFLICTING_LABEL_ROW_COUNT + CONTAINS_PII -> Known.CONTAINS_PII + CONTAINS_VALID_URL -> Known.CONTAINS_VALID_URL + CORRELATED_FEATURES -> Known.CORRELATED_FEATURES + CUSTOM_METRIC -> Known.CUSTOM_METRIC + DUPLICATE_ROW_COUNT -> Known.DUPLICATE_ROW_COUNT + EMPTY_FEATURES -> Known.EMPTY_FEATURES + FEATURE_DRIFT -> Known.FEATURE_DRIFT + FEATURE_PROFILE -> Known.FEATURE_PROFILE + GREAT_EXPECTATIONS -> Known.GREAT_EXPECTATIONS + GROUP_BY_COLUMN_STATS_CHECK -> Known.GROUP_BY_COLUMN_STATS_CHECK + ILL_FORMED_ROW_COUNT -> Known.ILL_FORMED_ROW_COUNT + IS_CODE -> Known.IS_CODE + IS_JSON -> Known.IS_JSON + LLM_RUBRIC_V2 -> Known.LLM_RUBRIC_V2 + LABEL_DRIFT -> Known.LABEL_DRIFT + METRICS -> Known.METRICS + NEW_CATEGORIES -> Known.NEW_CATEGORIES + NEW_LABELS -> Known.NEW_LABELS + NULL_ROW_COUNT -> Known.NULL_ROW_COUNT + PP_SCORE -> Known.PP_SCORE + QUASI_CONSTANT_FEATURES -> Known.QUASI_CONSTANT_FEATURES + SENTENCE_LENGTH -> Known.SENTENCE_LENGTH + SIZE_RATIO -> Known.SIZE_RATIO + SPECIAL_CHARACTERS -> Known.SPECIAL_CHARACTERS + STRING_VALIDATION -> Known.STRING_VALIDATION + TRAIN_VAL_LEAKAGE_ROW_COUNT -> Known.TRAIN_VAL_LEAKAGE_ROW_COUNT + else -> + throw OpenlayerInvalidDataException("Unknown InsightName: $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 OpenlayerInvalidDataException if this class instance's value does not + * have the expected primitive type. + */ + fun asString(): String = + _value().asString().orElseThrow { + OpenlayerInvalidDataException("Value is not a String") + } + + private var validated: Boolean = false + + fun validate(): InsightName = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OpenlayerInvalidDataException) { + false + } + + /** + * Returns a 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 InsightName && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + class InsightParameter + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val name: JsonField, + private val value: JsonValue, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("name") + @ExcludeMissing + name: JsonField = JsonMissing.of(), + @JsonProperty("value") @ExcludeMissing value: JsonValue = JsonMissing.of(), + ) : this(name, value, mutableMapOf()) + + /** + * The name of the insight filter. + * + * @throws OpenlayerInvalidDataException if 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") + + @JsonProperty("value") @ExcludeMissing fun _value(): JsonValue = value + + /** + * Returns the raw JSON value of [name]. + * + * Unlike [name], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("name") @ExcludeMissing fun _name(): JsonField = name + + @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 + * [InsightParameter]. + * + * The following fields are required: + * ```java + * .name() + * .value() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [InsightParameter]. */ + class Builder internal constructor() { + + private var name: JsonField? = null + private var value: JsonValue? = null + private var additionalProperties: MutableMap = + mutableMapOf() + + @JvmSynthetic + internal fun from(insightParameter: InsightParameter) = apply { + name = insightParameter.name + value = insightParameter.value + additionalProperties = + insightParameter.additionalProperties.toMutableMap() + } + + /** The name of the insight filter. */ + 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 } + + fun value(value: JsonValue) = 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 [InsightParameter]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .name() + * .value() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): InsightParameter = + InsightParameter( + checkRequired("name", name), + checkRequired("value", value), + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): InsightParameter = apply { + if (validated) { + return@apply + } + + name() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OpenlayerInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = (if (name.asKnown().isPresent) 1 else 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is InsightParameter && + name == other.name && + value == other.value && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(name, value, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "InsightParameter{name=$name, value=$value, additionalProperties=$additionalProperties}" + } + + /** The operator to be used for the evaluation. */ + class Operator + @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 IS = of("is") + + @JvmField val GREATER = of(">") + + @JvmField val GREATER_OR_EQUALS = of(">=") + + @JvmField val LESS = of("<") + + @JvmField val LESS_OR_EQUALS = of("<=") + + @JvmField val NOT_EQUALS = of("!=") + + @JvmStatic fun of(value: String) = Operator(JsonField.of(value)) + } + + /** An enum containing [Operator]'s known values. */ + enum class Known { + IS, + GREATER, + GREATER_OR_EQUALS, + LESS, + LESS_OR_EQUALS, + NOT_EQUALS, + } + + /** + * An enum containing [Operator]'s known values, as well as an [_UNKNOWN] + * member. + * + * An instance of [Operator] 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 { + IS, + GREATER, + GREATER_OR_EQUALS, + LESS, + LESS_OR_EQUALS, + NOT_EQUALS, + /** + * An enum member indicating that [Operator] 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) { + IS -> Value.IS + GREATER -> Value.GREATER + GREATER_OR_EQUALS -> Value.GREATER_OR_EQUALS + LESS -> Value.LESS + LESS_OR_EQUALS -> Value.LESS_OR_EQUALS + NOT_EQUALS -> Value.NOT_EQUALS + 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 OpenlayerInvalidDataException if this class instance's value is a not + * a known member. + */ + fun known(): Known = + when (this) { + IS -> Known.IS + GREATER -> Known.GREATER + GREATER_OR_EQUALS -> Known.GREATER_OR_EQUALS + LESS -> Known.LESS + LESS_OR_EQUALS -> Known.LESS_OR_EQUALS + NOT_EQUALS -> Known.NOT_EQUALS + else -> throw OpenlayerInvalidDataException("Unknown Operator: $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 OpenlayerInvalidDataException if this class instance's value does not + * have the expected primitive type. + */ + fun asString(): String = + _value().asString().orElseThrow { + OpenlayerInvalidDataException("Value is not a String") + } + + private var validated: Boolean = false + + fun validate(): Operator = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OpenlayerInvalidDataException) { + false + } + + /** + * Returns a 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 Operator && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + /** Whether to use automatic anomaly detection or manual thresholds */ + class ThresholdMode + @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 AUTOMATIC = of("automatic") + + @JvmField val MANUAL = of("manual") + + @JvmStatic fun of(value: String) = ThresholdMode(JsonField.of(value)) + } + + /** An enum containing [ThresholdMode]'s known values. */ + enum class Known { + AUTOMATIC, + MANUAL, + } + + /** + * An enum containing [ThresholdMode]'s known values, as well as an [_UNKNOWN] + * member. + * + * An instance of [ThresholdMode] 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 { + AUTOMATIC, + MANUAL, + /** + * An enum member indicating that [ThresholdMode] 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) { + AUTOMATIC -> Value.AUTOMATIC + MANUAL -> Value.MANUAL + 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 OpenlayerInvalidDataException if this class instance's value is a not + * a known member. + */ + fun known(): Known = + when (this) { + AUTOMATIC -> Known.AUTOMATIC + MANUAL -> Known.MANUAL + else -> + throw OpenlayerInvalidDataException("Unknown ThresholdMode: $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 OpenlayerInvalidDataException if this class instance's value does not + * have the expected primitive type. + */ + fun asString(): String = + _value().asString().orElseThrow { + OpenlayerInvalidDataException("Value is not a String") + } + + private var validated: Boolean = false + + fun validate(): ThresholdMode = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OpenlayerInvalidDataException) { + false + } + + /** + * Returns a 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 ThresholdMode && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + /** The value to be compared. */ + @JsonDeserialize(using = Value.Deserializer::class) + @JsonSerialize(using = Value.Serializer::class) + class Value + private constructor( + private val number: Double? = null, + private val bool: Boolean? = null, + private val string: String? = null, + private val strings: List? = null, + private val _json: JsonValue? = null, + ) { + + fun number(): Optional = Optional.ofNullable(number) + + fun bool(): Optional = Optional.ofNullable(bool) + + fun string(): Optional = Optional.ofNullable(string) + + fun strings(): Optional> = Optional.ofNullable(strings) + + fun isNumber(): Boolean = number != null + + fun isBool(): Boolean = bool != null + + fun isString(): Boolean = string != null + + fun isStrings(): Boolean = strings != null + + fun asNumber(): Double = number.getOrThrow("number") + + fun asBool(): Boolean = bool.getOrThrow("bool") + + fun asString(): String = string.getOrThrow("string") + + fun asStrings(): List = strings.getOrThrow("strings") + + fun _json(): Optional = Optional.ofNullable(_json) + + fun accept(visitor: Visitor): T = + when { + number != null -> visitor.visitNumber(number) + bool != null -> visitor.visitBool(bool) + string != null -> visitor.visitString(string) + strings != null -> visitor.visitStrings(strings) + else -> visitor.unknown(_json) + } + + private var validated: Boolean = false + + fun validate(): Value = apply { + if (validated) { + return@apply + } + + accept( + object : Visitor { + override fun visitNumber(number: Double) {} + + override fun visitBool(bool: Boolean) {} + + override fun visitString(string: String) {} + + override fun visitStrings(strings: List) {} + } + ) + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OpenlayerInvalidDataException) { + false + } + + /** + * Returns 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 visitNumber(number: Double) = 1 + + override fun visitBool(bool: Boolean) = 1 + + override fun visitString(string: String) = 1 + + override fun visitStrings(strings: List) = strings.size + + override fun unknown(json: JsonValue?) = 0 + } + ) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Value && + number == other.number && + bool == other.bool && + string == other.string && + strings == other.strings + } + + override fun hashCode(): Int = Objects.hash(number, bool, string, strings) + + override fun toString(): String = + when { + number != null -> "Value{number=$number}" + bool != null -> "Value{bool=$bool}" + string != null -> "Value{string=$string}" + strings != null -> "Value{strings=$strings}" + _json != null -> "Value{_unknown=$_json}" + else -> throw IllegalStateException("Invalid Value") + } + + companion object { + + @JvmStatic fun ofNumber(number: Double) = Value(number = number) + + @JvmStatic fun ofBool(bool: Boolean) = Value(bool = bool) + + @JvmStatic fun ofString(string: String) = Value(string = string) + + @JvmStatic + fun ofStrings(strings: List) = + Value(strings = strings.toImmutable()) + } + + /** + * An interface that defines how to map each variant of [Value] to a value of + * type [T]. + */ + interface Visitor { + + fun visitNumber(number: Double): T + + fun visitBool(bool: Boolean): T + + fun visitString(string: String): T + + fun visitStrings(strings: List): T + + /** + * Maps an unknown variant of [Value] to a value of type [T]. + * + * An instance of [Value] 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 OpenlayerInvalidDataException in the default implementation. + */ + fun unknown(json: JsonValue?): T { + throw OpenlayerInvalidDataException("Unknown Value: $json") + } + } + + internal class Deserializer : BaseDeserializer(Value::class) { + + override fun ObjectCodec.deserialize(node: JsonNode): Value { + val json = JsonValue.fromJsonNode(node) + + val bestMatches = + sequenceOf( + tryDeserialize(node, jacksonTypeRef())?.let { + Value(number = it, _json = json) + }, + tryDeserialize(node, jacksonTypeRef())?.let { + Value(bool = it, _json = json) + }, + tryDeserialize(node, jacksonTypeRef())?.let { + Value(string = it, _json = json) + }, + tryDeserialize(node, jacksonTypeRef>())?.let { + Value(strings = it, _json = json) + }, + ) + .filterNotNull() + .allMaxBy { it.validity() } + .toList() + return when (bestMatches.size) { + // This can happen if what we're deserializing is completely + // incompatible with all the possible variants (e.g. deserializing + // from object). + 0 -> Value(_json = json) + 1 -> bestMatches.single() + // If there's more than one match with the highest validity, then + // use the first completely valid match, or simply the first match + // if none are completely valid. + else -> + bestMatches.firstOrNull { it.isValid() } ?: bestMatches.first() + } + } + } + + internal class Serializer : BaseSerializer(Value::class) { + + override fun serialize( + value: Value, + generator: JsonGenerator, + provider: SerializerProvider, + ) { + when { + value.number != null -> generator.writeObject(value.number) + value.bool != null -> generator.writeObject(value.bool) + value.string != null -> generator.writeObject(value.string) + value.strings != null -> generator.writeObject(value.strings) + value._json != null -> generator.writeObject(value._json) + else -> throw IllegalStateException("Invalid Value") + } + } + } + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Threshold && + insightName == other.insightName && + insightParameters == other.insightParameters && + measurement == other.measurement && + operator == other.operator && + thresholdMode == other.thresholdMode && + value == other.value && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + insightName, + insightParameters, + measurement, + operator, + thresholdMode, + value, + additionalProperties, + ) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Threshold{insightName=$insightName, insightParameters=$insightParameters, measurement=$measurement, operator=$operator, thresholdMode=$thresholdMode, value=$value, additionalProperties=$additionalProperties}" + } + + /** The test 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 INTEGRITY = of("integrity") + + @JvmField val CONSISTENCY = of("consistency") + + @JvmField val PERFORMANCE = of("performance") + + @JvmStatic fun of(value: String) = Type(JsonField.of(value)) + } + + /** An enum containing [Type]'s known values. */ + enum class Known { + INTEGRITY, + CONSISTENCY, + PERFORMANCE, + } + + /** + * 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 { + INTEGRITY, + CONSISTENCY, + PERFORMANCE, + /** + * 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) { + INTEGRITY -> Value.INTEGRITY + CONSISTENCY -> Value.CONSISTENCY + PERFORMANCE -> Value.PERFORMANCE + 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 OpenlayerInvalidDataException if this class instance's value is a not a + * known member. + */ + fun known(): Known = + when (this) { + INTEGRITY -> Known.INTEGRITY + CONSISTENCY -> Known.CONSISTENCY + PERFORMANCE -> Known.PERFORMANCE + else -> throw OpenlayerInvalidDataException("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 OpenlayerInvalidDataException if this class instance's value does not + * have the expected primitive type. + */ + fun asString(): String = + _value().asString().orElseThrow { + OpenlayerInvalidDataException("Value is not a String") + } + + private var validated: Boolean = false + + fun validate(): Type = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OpenlayerInvalidDataException) { + false + } + + /** + * Returns a 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 Goal && + id == other.id && + commentCount == other.commentCount && + creatorId == other.creatorId && + dateArchived == other.dateArchived && + dateCreated == other.dateCreated && + dateUpdated == other.dateUpdated && + description == other.description && + name == other.name && + number == other.number && + originProjectVersionId == other.originProjectVersionId && + subtype == other.subtype && + suggested == other.suggested && + thresholds == other.thresholds && + type == other.type && + archived == other.archived && + delayWindow == other.delayWindow && + evaluationWindow == other.evaluationWindow && + usesMlModel == other.usesMlModel && + usesProductionData == other.usesProductionData && + usesReferenceDataset == other.usesReferenceDataset && + usesTrainingDataset == other.usesTrainingDataset && + usesValidationDataset == other.usesValidationDataset && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + id, + commentCount, + creatorId, + dateArchived, + dateCreated, + dateUpdated, + description, + name, + number, + originProjectVersionId, + subtype, + suggested, + thresholds, + type, + archived, + delayWindow, + evaluationWindow, + usesMlModel, + usesProductionData, + usesReferenceDataset, + usesTrainingDataset, + usesValidationDataset, + additionalProperties, + ) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Goal{id=$id, commentCount=$commentCount, creatorId=$creatorId, dateArchived=$dateArchived, dateCreated=$dateCreated, dateUpdated=$dateUpdated, description=$description, name=$name, number=$number, originProjectVersionId=$originProjectVersionId, subtype=$subtype, suggested=$suggested, thresholds=$thresholds, type=$type, archived=$archived, delayWindow=$delayWindow, evaluationWindow=$evaluationWindow, usesMlModel=$usesMlModel, usesProductionData=$usesProductionData, usesReferenceDataset=$usesReferenceDataset, usesTrainingDataset=$usesTrainingDataset, usesValidationDataset=$usesValidationDataset, additionalProperties=$additionalProperties}" + } + + /** The body of the rows request. */ + class RowsBody + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val columnFilters: JsonField>, + private val excludeRowIdList: JsonField>, + private val notSearchQueryAnd: JsonField>, + private val notSearchQueryOr: JsonField>, + private val rowIdList: JsonField>, + private val searchQueryAnd: JsonField>, + private val searchQueryOr: JsonField>, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("columnFilters") + @ExcludeMissing + columnFilters: JsonField> = JsonMissing.of(), + @JsonProperty("excludeRowIdList") + @ExcludeMissing + excludeRowIdList: JsonField> = JsonMissing.of(), + @JsonProperty("notSearchQueryAnd") + @ExcludeMissing + notSearchQueryAnd: JsonField> = JsonMissing.of(), + @JsonProperty("notSearchQueryOr") + @ExcludeMissing + notSearchQueryOr: JsonField> = JsonMissing.of(), + @JsonProperty("rowIdList") + @ExcludeMissing + rowIdList: JsonField> = JsonMissing.of(), + @JsonProperty("searchQueryAnd") + @ExcludeMissing + searchQueryAnd: JsonField> = JsonMissing.of(), + @JsonProperty("searchQueryOr") + @ExcludeMissing + searchQueryOr: JsonField> = JsonMissing.of(), + ) : this( + columnFilters, + excludeRowIdList, + notSearchQueryAnd, + notSearchQueryOr, + rowIdList, + searchQueryAnd, + searchQueryOr, + mutableMapOf(), + ) + + /** + * @throws OpenlayerInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun columnFilters(): Optional> = + columnFilters.getOptional("columnFilters") + + /** + * @throws OpenlayerInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun excludeRowIdList(): Optional> = + excludeRowIdList.getOptional("excludeRowIdList") + + /** + * @throws OpenlayerInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun notSearchQueryAnd(): Optional> = + notSearchQueryAnd.getOptional("notSearchQueryAnd") + + /** + * @throws OpenlayerInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun notSearchQueryOr(): Optional> = + notSearchQueryOr.getOptional("notSearchQueryOr") + + /** + * @throws OpenlayerInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun rowIdList(): Optional> = rowIdList.getOptional("rowIdList") + + /** + * @throws OpenlayerInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun searchQueryAnd(): Optional> = + searchQueryAnd.getOptional("searchQueryAnd") + + /** + * @throws OpenlayerInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun searchQueryOr(): Optional> = searchQueryOr.getOptional("searchQueryOr") + + /** + * Returns the raw JSON value of [columnFilters]. + * + * Unlike [columnFilters], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("columnFilters") + @ExcludeMissing + fun _columnFilters(): JsonField> = columnFilters + + /** + * Returns the raw JSON value of [excludeRowIdList]. + * + * Unlike [excludeRowIdList], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("excludeRowIdList") + @ExcludeMissing + fun _excludeRowIdList(): JsonField> = excludeRowIdList + + /** + * Returns the raw JSON value of [notSearchQueryAnd]. + * + * Unlike [notSearchQueryAnd], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("notSearchQueryAnd") + @ExcludeMissing + fun _notSearchQueryAnd(): JsonField> = notSearchQueryAnd + + /** + * Returns the raw JSON value of [notSearchQueryOr]. + * + * Unlike [notSearchQueryOr], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("notSearchQueryOr") + @ExcludeMissing + fun _notSearchQueryOr(): JsonField> = notSearchQueryOr + + /** + * Returns the raw JSON value of [rowIdList]. + * + * Unlike [rowIdList], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("rowIdList") + @ExcludeMissing + fun _rowIdList(): JsonField> = rowIdList + + /** + * Returns the raw JSON value of [searchQueryAnd]. + * + * Unlike [searchQueryAnd], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("searchQueryAnd") + @ExcludeMissing + fun _searchQueryAnd(): JsonField> = searchQueryAnd + + /** + * Returns the raw JSON value of [searchQueryOr]. + * + * Unlike [searchQueryOr], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("searchQueryOr") + @ExcludeMissing + fun _searchQueryOr(): JsonField> = searchQueryOr + + @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 [RowsBody]. */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [RowsBody]. */ + class Builder internal constructor() { + + private var columnFilters: JsonField>? = null + private var excludeRowIdList: JsonField>? = null + private var notSearchQueryAnd: JsonField>? = null + private var notSearchQueryOr: JsonField>? = null + private var rowIdList: JsonField>? = null + private var searchQueryAnd: JsonField>? = null + private var searchQueryOr: JsonField>? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(rowsBody: RowsBody) = apply { + columnFilters = rowsBody.columnFilters.map { it.toMutableList() } + excludeRowIdList = rowsBody.excludeRowIdList.map { it.toMutableList() } + notSearchQueryAnd = rowsBody.notSearchQueryAnd.map { it.toMutableList() } + notSearchQueryOr = rowsBody.notSearchQueryOr.map { it.toMutableList() } + rowIdList = rowsBody.rowIdList.map { it.toMutableList() } + searchQueryAnd = rowsBody.searchQueryAnd.map { it.toMutableList() } + searchQueryOr = rowsBody.searchQueryOr.map { it.toMutableList() } + additionalProperties = rowsBody.additionalProperties.toMutableMap() + } + + fun columnFilters(columnFilters: List?) = + columnFilters(JsonField.ofNullable(columnFilters)) + + /** Alias for calling [Builder.columnFilters] with `columnFilters.orElse(null)`. */ + fun columnFilters(columnFilters: Optional>) = + columnFilters(columnFilters.getOrNull()) + + /** + * Sets [Builder.columnFilters] to an arbitrary JSON value. + * + * You should usually call [Builder.columnFilters] with a well-typed + * `List` value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. + */ + fun columnFilters(columnFilters: JsonField>) = apply { + this.columnFilters = columnFilters.map { it.toMutableList() } + } + + /** + * Adds a single [ColumnFilter] to [columnFilters]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addColumnFilter(columnFilter: ColumnFilter) = apply { + columnFilters = + (columnFilters ?: JsonField.of(mutableListOf())).also { + checkKnown("columnFilters", it).add(columnFilter) + } + } + + /** Alias for calling [addColumnFilter] with `ColumnFilter.ofSet(set)`. */ + fun addColumnFilter(set: ColumnFilter.SetColumnFilter) = + addColumnFilter(ColumnFilter.ofSet(set)) + + /** Alias for calling [addColumnFilter] with `ColumnFilter.ofNumeric(numeric)`. */ + fun addColumnFilter(numeric: ColumnFilter.NumericColumnFilter) = + addColumnFilter(ColumnFilter.ofNumeric(numeric)) + + /** Alias for calling [addColumnFilter] with `ColumnFilter.ofString(string)`. */ + fun addColumnFilter(string: ColumnFilter.StringColumnFilter) = + addColumnFilter(ColumnFilter.ofString(string)) + + fun excludeRowIdList(excludeRowIdList: List?) = + excludeRowIdList(JsonField.ofNullable(excludeRowIdList)) + + /** + * Alias for calling [Builder.excludeRowIdList] with + * `excludeRowIdList.orElse(null)`. + */ + fun excludeRowIdList(excludeRowIdList: Optional>) = + excludeRowIdList(excludeRowIdList.getOrNull()) + + /** + * Sets [Builder.excludeRowIdList] to an arbitrary JSON value. + * + * You should usually call [Builder.excludeRowIdList] with a well-typed `List` + * value instead. This method is primarily for setting the field to an undocumented + * or not yet supported value. + */ + fun excludeRowIdList(excludeRowIdList: JsonField>) = apply { + this.excludeRowIdList = excludeRowIdList.map { it.toMutableList() } + } + + /** + * Adds a single [Long] to [Builder.excludeRowIdList]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addExcludeRowIdList(excludeRowIdList: Long) = apply { + this.excludeRowIdList = + (this.excludeRowIdList ?: JsonField.of(mutableListOf())).also { + checkKnown("excludeRowIdList", it).add(excludeRowIdList) + } + } + + fun notSearchQueryAnd(notSearchQueryAnd: List?) = + notSearchQueryAnd(JsonField.ofNullable(notSearchQueryAnd)) + + /** + * Alias for calling [Builder.notSearchQueryAnd] with + * `notSearchQueryAnd.orElse(null)`. + */ + fun notSearchQueryAnd(notSearchQueryAnd: Optional>) = + notSearchQueryAnd(notSearchQueryAnd.getOrNull()) + + /** + * Sets [Builder.notSearchQueryAnd] to an arbitrary JSON value. + * + * You should usually call [Builder.notSearchQueryAnd] with a well-typed + * `List` value instead. This method is primarily for setting the field to + * an undocumented or not yet supported value. + */ + fun notSearchQueryAnd(notSearchQueryAnd: JsonField>) = apply { + this.notSearchQueryAnd = notSearchQueryAnd.map { it.toMutableList() } + } + + /** + * Adds a single [String] to [Builder.notSearchQueryAnd]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addNotSearchQueryAnd(notSearchQueryAnd: String) = apply { + this.notSearchQueryAnd = + (this.notSearchQueryAnd ?: JsonField.of(mutableListOf())).also { + checkKnown("notSearchQueryAnd", it).add(notSearchQueryAnd) + } + } + + fun notSearchQueryOr(notSearchQueryOr: List?) = + notSearchQueryOr(JsonField.ofNullable(notSearchQueryOr)) + + /** + * Alias for calling [Builder.notSearchQueryOr] with + * `notSearchQueryOr.orElse(null)`. + */ + fun notSearchQueryOr(notSearchQueryOr: Optional>) = + notSearchQueryOr(notSearchQueryOr.getOrNull()) + + /** + * Sets [Builder.notSearchQueryOr] to an arbitrary JSON value. + * + * You should usually call [Builder.notSearchQueryOr] with a well-typed + * `List` value instead. This method is primarily for setting the field to + * an undocumented or not yet supported value. + */ + fun notSearchQueryOr(notSearchQueryOr: JsonField>) = apply { + this.notSearchQueryOr = notSearchQueryOr.map { it.toMutableList() } + } + + /** + * Adds a single [String] to [Builder.notSearchQueryOr]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addNotSearchQueryOr(notSearchQueryOr: String) = apply { + this.notSearchQueryOr = + (this.notSearchQueryOr ?: JsonField.of(mutableListOf())).also { + checkKnown("notSearchQueryOr", it).add(notSearchQueryOr) + } + } + + fun rowIdList(rowIdList: List?) = rowIdList(JsonField.ofNullable(rowIdList)) + + /** Alias for calling [Builder.rowIdList] with `rowIdList.orElse(null)`. */ + fun rowIdList(rowIdList: Optional>) = rowIdList(rowIdList.getOrNull()) + + /** + * Sets [Builder.rowIdList] to an arbitrary JSON value. + * + * You should usually call [Builder.rowIdList] with a well-typed `List` value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun rowIdList(rowIdList: JsonField>) = apply { + this.rowIdList = rowIdList.map { it.toMutableList() } + } + + /** + * Adds a single [Long] to [Builder.rowIdList]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addRowIdList(rowIdList: Long) = apply { + this.rowIdList = + (this.rowIdList ?: JsonField.of(mutableListOf())).also { + checkKnown("rowIdList", it).add(rowIdList) + } + } + + fun searchQueryAnd(searchQueryAnd: List?) = + searchQueryAnd(JsonField.ofNullable(searchQueryAnd)) + + /** + * Alias for calling [Builder.searchQueryAnd] with `searchQueryAnd.orElse(null)`. + */ + fun searchQueryAnd(searchQueryAnd: Optional>) = + searchQueryAnd(searchQueryAnd.getOrNull()) + + /** + * Sets [Builder.searchQueryAnd] to an arbitrary JSON value. + * + * You should usually call [Builder.searchQueryAnd] with a well-typed `List` + * value instead. This method is primarily for setting the field to an undocumented + * or not yet supported value. + */ + fun searchQueryAnd(searchQueryAnd: JsonField>) = apply { + this.searchQueryAnd = searchQueryAnd.map { it.toMutableList() } + } + + /** + * Adds a single [String] to [Builder.searchQueryAnd]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addSearchQueryAnd(searchQueryAnd: String) = apply { + this.searchQueryAnd = + (this.searchQueryAnd ?: JsonField.of(mutableListOf())).also { + checkKnown("searchQueryAnd", it).add(searchQueryAnd) + } + } + + fun searchQueryOr(searchQueryOr: List?) = + searchQueryOr(JsonField.ofNullable(searchQueryOr)) + + /** Alias for calling [Builder.searchQueryOr] with `searchQueryOr.orElse(null)`. */ + fun searchQueryOr(searchQueryOr: Optional>) = + searchQueryOr(searchQueryOr.getOrNull()) + + /** + * Sets [Builder.searchQueryOr] to an arbitrary JSON value. + * + * You should usually call [Builder.searchQueryOr] with a well-typed `List` + * value instead. This method is primarily for setting the field to an undocumented + * or not yet supported value. + */ + fun searchQueryOr(searchQueryOr: JsonField>) = apply { + this.searchQueryOr = searchQueryOr.map { it.toMutableList() } + } + + /** + * Adds a single [String] to [Builder.searchQueryOr]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addSearchQueryOr(searchQueryOr: String) = apply { + this.searchQueryOr = + (this.searchQueryOr ?: JsonField.of(mutableListOf())).also { + checkKnown("searchQueryOr", it).add(searchQueryOr) + } + } + + 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 [RowsBody]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): RowsBody = + RowsBody( + (columnFilters ?: JsonMissing.of()).map { it.toImmutable() }, + (excludeRowIdList ?: JsonMissing.of()).map { it.toImmutable() }, + (notSearchQueryAnd ?: JsonMissing.of()).map { it.toImmutable() }, + (notSearchQueryOr ?: JsonMissing.of()).map { it.toImmutable() }, + (rowIdList ?: JsonMissing.of()).map { it.toImmutable() }, + (searchQueryAnd ?: JsonMissing.of()).map { it.toImmutable() }, + (searchQueryOr ?: JsonMissing.of()).map { it.toImmutable() }, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): RowsBody = apply { + if (validated) { + return@apply + } + + columnFilters().ifPresent { it.forEach { it.validate() } } + excludeRowIdList() + notSearchQueryAnd() + notSearchQueryOr() + rowIdList() + searchQueryAnd() + searchQueryOr() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OpenlayerInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (columnFilters.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + + (excludeRowIdList.asKnown().getOrNull()?.size ?: 0) + + (notSearchQueryAnd.asKnown().getOrNull()?.size ?: 0) + + (notSearchQueryOr.asKnown().getOrNull()?.size ?: 0) + + (rowIdList.asKnown().getOrNull()?.size ?: 0) + + (searchQueryAnd.asKnown().getOrNull()?.size ?: 0) + + (searchQueryOr.asKnown().getOrNull()?.size ?: 0) + + @JsonDeserialize(using = ColumnFilter.Deserializer::class) + @JsonSerialize(using = ColumnFilter.Serializer::class) + class ColumnFilter + private constructor( + private val set: SetColumnFilter? = null, + private val numeric: NumericColumnFilter? = null, + private val string: StringColumnFilter? = null, + private val _json: JsonValue? = null, + ) { + + fun set(): Optional = Optional.ofNullable(set) + + fun numeric(): Optional = Optional.ofNullable(numeric) + + fun string(): Optional = Optional.ofNullable(string) + + fun isSet(): Boolean = set != null + + fun isNumeric(): Boolean = numeric != null + + fun isString(): Boolean = string != null + + fun asSet(): SetColumnFilter = set.getOrThrow("set") + + fun asNumeric(): NumericColumnFilter = numeric.getOrThrow("numeric") + + fun asString(): StringColumnFilter = string.getOrThrow("string") + + fun _json(): Optional = Optional.ofNullable(_json) + + fun accept(visitor: Visitor): T = + when { + set != null -> visitor.visitSet(set) + numeric != null -> visitor.visitNumeric(numeric) + string != null -> visitor.visitString(string) + else -> visitor.unknown(_json) + } + + private var validated: Boolean = false + + fun validate(): ColumnFilter = apply { + if (validated) { + return@apply + } + + accept( + object : Visitor { + override fun visitSet(set: SetColumnFilter) { + set.validate() + } + + override fun visitNumeric(numeric: NumericColumnFilter) { + numeric.validate() + } + + override fun visitString(string: StringColumnFilter) { + string.validate() + } + } + ) + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OpenlayerInvalidDataException) { + false + } + + /** + * Returns 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 visitSet(set: SetColumnFilter) = set.validity() + + override fun visitNumeric(numeric: NumericColumnFilter) = + numeric.validity() + + override fun visitString(string: StringColumnFilter) = string.validity() + + override fun unknown(json: JsonValue?) = 0 + } + ) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is ColumnFilter && + set == other.set && + numeric == other.numeric && + string == other.string + } + + override fun hashCode(): Int = Objects.hash(set, numeric, string) + + override fun toString(): String = + when { + set != null -> "ColumnFilter{set=$set}" + numeric != null -> "ColumnFilter{numeric=$numeric}" + string != null -> "ColumnFilter{string=$string}" + _json != null -> "ColumnFilter{_unknown=$_json}" + else -> throw IllegalStateException("Invalid ColumnFilter") + } + + companion object { + + @JvmStatic fun ofSet(set: SetColumnFilter) = ColumnFilter(set = set) + + @JvmStatic + fun ofNumeric(numeric: NumericColumnFilter) = ColumnFilter(numeric = numeric) + + @JvmStatic + fun ofString(string: StringColumnFilter) = ColumnFilter(string = string) + } + + /** + * An interface that defines how to map each variant of [ColumnFilter] to a value of + * type [T]. + */ + interface Visitor { + + fun visitSet(set: SetColumnFilter): T + + fun visitNumeric(numeric: NumericColumnFilter): T + + fun visitString(string: StringColumnFilter): T + + /** + * Maps an unknown variant of [ColumnFilter] to a value of type [T]. + * + * An instance of [ColumnFilter] 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 OpenlayerInvalidDataException in the default implementation. + */ + fun unknown(json: JsonValue?): T { + throw OpenlayerInvalidDataException("Unknown ColumnFilter: $json") + } + } + + internal class Deserializer : BaseDeserializer(ColumnFilter::class) { + + override fun ObjectCodec.deserialize(node: JsonNode): ColumnFilter { + val json = JsonValue.fromJsonNode(node) + + val bestMatches = + sequenceOf( + tryDeserialize(node, jacksonTypeRef())?.let { + ColumnFilter(set = it, _json = json) + }, + tryDeserialize(node, jacksonTypeRef()) + ?.let { ColumnFilter(numeric = it, _json = json) }, + tryDeserialize(node, jacksonTypeRef()) + ?.let { ColumnFilter(string = it, _json = json) }, + ) + .filterNotNull() + .allMaxBy { it.validity() } + .toList() + return when (bestMatches.size) { + // This can happen if what we're deserializing is completely + // incompatible with all the possible variants (e.g. deserializing from + // boolean). + 0 -> ColumnFilter(_json = json) + 1 -> bestMatches.single() + // If there's more than one match with the highest validity, then use + // the first completely valid match, or simply the first match if none + // are completely valid. + else -> bestMatches.firstOrNull { it.isValid() } ?: bestMatches.first() + } + } + } + + internal class Serializer : BaseSerializer(ColumnFilter::class) { + + override fun serialize( + value: ColumnFilter, + generator: JsonGenerator, + provider: SerializerProvider, + ) { + when { + value.set != null -> generator.writeObject(value.set) + value.numeric != null -> generator.writeObject(value.numeric) + value.string != null -> generator.writeObject(value.string) + value._json != null -> generator.writeObject(value._json) + else -> throw IllegalStateException("Invalid ColumnFilter") + } + } + } + + class SetColumnFilter + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val measurement: JsonField, + private val operator: JsonField, + private val value: JsonField>, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("measurement") + @ExcludeMissing + measurement: JsonField = JsonMissing.of(), + @JsonProperty("operator") + @ExcludeMissing + operator: JsonField = JsonMissing.of(), + @JsonProperty("value") + @ExcludeMissing + value: JsonField> = JsonMissing.of(), + ) : this(measurement, operator, value, mutableMapOf()) + + /** + * The name of the column. + * + * @throws OpenlayerInvalidDataException if the JSON field has an unexpected + * type or is unexpectedly missing or null (e.g. if the server responded with + * an unexpected value). + */ + fun measurement(): String = measurement.getRequired("measurement") + + /** + * @throws OpenlayerInvalidDataException if the JSON field has an unexpected + * type or is unexpectedly missing or null (e.g. if the server responded with + * an unexpected value). + */ + fun operator(): Operator = operator.getRequired("operator") + + /** + * @throws OpenlayerInvalidDataException if the JSON field has an unexpected + * type or is unexpectedly missing or null (e.g. if the server responded with + * an unexpected value). + */ + fun value(): List = value.getRequired("value") + + /** + * Returns the raw JSON value of [measurement]. + * + * Unlike [measurement], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("measurement") + @ExcludeMissing + fun _measurement(): JsonField = measurement + + /** + * Returns the raw JSON value of [operator]. + * + * Unlike [operator], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("operator") + @ExcludeMissing + fun _operator(): JsonField = operator + + /** + * 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 + * [SetColumnFilter]. + * + * The following fields are required: + * ```java + * .measurement() + * .operator() + * .value() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [SetColumnFilter]. */ + class Builder internal constructor() { + + private var measurement: JsonField? = null + private var operator: JsonField? = null + private var value: JsonField>? = null + private var additionalProperties: MutableMap = + mutableMapOf() + + @JvmSynthetic + internal fun from(setColumnFilter: SetColumnFilter) = apply { + measurement = setColumnFilter.measurement + operator = setColumnFilter.operator + value = setColumnFilter.value.map { it.toMutableList() } + additionalProperties = + setColumnFilter.additionalProperties.toMutableMap() + } + + /** The name of the column. */ + fun measurement(measurement: String) = + measurement(JsonField.of(measurement)) + + /** + * Sets [Builder.measurement] to an arbitrary JSON value. + * + * You should usually call [Builder.measurement] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun measurement(measurement: JsonField) = apply { + this.measurement = measurement + } + + fun operator(operator: Operator) = operator(JsonField.of(operator)) + + /** + * Sets [Builder.operator] to an arbitrary JSON value. + * + * You should usually call [Builder.operator] with a well-typed [Operator] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun operator(operator: JsonField) = apply { + this.operator = operator + } + + fun value(value: List) = value(JsonField.of(value)) + + /** + * Sets [Builder.value] to an arbitrary JSON value. + * + * You should usually call [Builder.value] with a well-typed `List` + * 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.map { it.toMutableList() } + } + + /** + * Adds a single [Value] to [Builder.value]. + * + * @throws IllegalStateException if the field was previously set to a + * non-list. + */ + fun addValue(value: Value) = apply { + this.value = + (this.value ?: JsonField.of(mutableListOf())).also { + checkKnown("value", it).add(value) + } + } + + /** Alias for calling [addValue] with `Value.ofString(string)`. */ + fun addValue(string: String) = addValue(Value.ofString(string)) + + /** Alias for calling [addValue] with `Value.ofNumber(number)`. */ + fun addValue(number: Double) = addValue(Value.ofNumber(number)) + + 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 [SetColumnFilter]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .measurement() + * .operator() + * .value() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): SetColumnFilter = + SetColumnFilter( + checkRequired("measurement", measurement), + checkRequired("operator", operator), + checkRequired("value", value).map { it.toImmutable() }, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): SetColumnFilter = apply { + if (validated) { + return@apply + } + + measurement() + operator().validate() + value().forEach { it.validate() } + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OpenlayerInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (if (measurement.asKnown().isPresent) 1 else 0) + + (operator.asKnown().getOrNull()?.validity() ?: 0) + + (value.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + + class Operator + @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 CONTAINS_NONE = of("contains_none") + + @JvmField val CONTAINS_ANY = of("contains_any") + + @JvmField val CONTAINS_ALL = of("contains_all") + + @JvmField val ONE_OF = of("one_of") + + @JvmField val NONE_OF = of("none_of") + + @JvmStatic fun of(value: String) = Operator(JsonField.of(value)) + } + + /** An enum containing [Operator]'s known values. */ + enum class Known { + CONTAINS_NONE, + CONTAINS_ANY, + CONTAINS_ALL, + ONE_OF, + NONE_OF, + } + + /** + * An enum containing [Operator]'s known values, as well as an [_UNKNOWN] + * member. + * + * An instance of [Operator] 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 { + CONTAINS_NONE, + CONTAINS_ANY, + CONTAINS_ALL, + ONE_OF, + NONE_OF, + /** + * An enum member indicating that [Operator] 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) { + CONTAINS_NONE -> Value.CONTAINS_NONE + CONTAINS_ANY -> Value.CONTAINS_ANY + CONTAINS_ALL -> Value.CONTAINS_ALL + ONE_OF -> Value.ONE_OF + NONE_OF -> Value.NONE_OF + 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 OpenlayerInvalidDataException if this class instance's value is a + * not a known member. + */ + fun known(): Known = + when (this) { + CONTAINS_NONE -> Known.CONTAINS_NONE + CONTAINS_ANY -> Known.CONTAINS_ANY + CONTAINS_ALL -> Known.CONTAINS_ALL + ONE_OF -> Known.ONE_OF + NONE_OF -> Known.NONE_OF + else -> + throw OpenlayerInvalidDataException("Unknown Operator: $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 OpenlayerInvalidDataException if this class instance's value does + * not have the expected primitive type. + */ + fun asString(): String = + _value().asString().orElseThrow { + OpenlayerInvalidDataException("Value is not a String") + } + + private var validated: Boolean = false + + fun validate(): Operator = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OpenlayerInvalidDataException) { + false + } + + /** + * Returns a 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 Operator && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + @JsonDeserialize(using = Value.Deserializer::class) + @JsonSerialize(using = Value.Serializer::class) + class Value + private constructor( + private val string: String? = null, + private val number: Double? = null, + private val _json: JsonValue? = null, + ) { + + fun string(): Optional = Optional.ofNullable(string) + + fun number(): Optional = Optional.ofNullable(number) + + fun isString(): Boolean = string != null + + fun isNumber(): Boolean = number != null + + fun asString(): String = string.getOrThrow("string") + + fun asNumber(): Double = number.getOrThrow("number") + + fun _json(): Optional = Optional.ofNullable(_json) + + fun accept(visitor: Visitor): T = + when { + string != null -> visitor.visitString(string) + number != null -> visitor.visitNumber(number) + else -> visitor.unknown(_json) + } + + private var validated: Boolean = false + + fun validate(): Value = apply { + if (validated) { + return@apply + } + + accept( + object : Visitor { + override fun visitString(string: String) {} + + override fun visitNumber(number: Double) {} + } + ) + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OpenlayerInvalidDataException) { + false + } + + /** + * Returns 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 visitString(string: String) = 1 + + override fun visitNumber(number: Double) = 1 + + override fun unknown(json: JsonValue?) = 0 + } + ) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Value && + string == other.string && + number == other.number + } + + override fun hashCode(): Int = Objects.hash(string, number) + + override fun toString(): String = + when { + string != null -> "Value{string=$string}" + number != null -> "Value{number=$number}" + _json != null -> "Value{_unknown=$_json}" + else -> throw IllegalStateException("Invalid Value") + } + + companion object { + + @JvmStatic fun ofString(string: String) = Value(string = string) + + @JvmStatic fun ofNumber(number: Double) = Value(number = number) + } + + /** + * An interface that defines how to map each variant of [Value] to a value + * of type [T]. + */ + interface Visitor { + + fun visitString(string: String): T + + fun visitNumber(number: Double): T + + /** + * Maps an unknown variant of [Value] to a value of type [T]. + * + * An instance of [Value] 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 OpenlayerInvalidDataException in the default implementation. + */ + fun unknown(json: JsonValue?): T { + throw OpenlayerInvalidDataException("Unknown Value: $json") + } + } + + internal class Deserializer : BaseDeserializer(Value::class) { + + override fun ObjectCodec.deserialize(node: JsonNode): Value { + val json = JsonValue.fromJsonNode(node) + + val bestMatches = + sequenceOf( + tryDeserialize(node, jacksonTypeRef())?.let { + Value(string = it, _json = json) + }, + tryDeserialize(node, jacksonTypeRef())?.let { + Value(number = it, _json = json) + }, + ) + .filterNotNull() + .allMaxBy { it.validity() } + .toList() + return when (bestMatches.size) { + // This can happen if what we're deserializing is completely + // incompatible with all the possible variants (e.g. + // deserializing from object). + 0 -> Value(_json = json) + 1 -> bestMatches.single() + // If there's more than one match with the highest validity, + // then use the first completely valid match, or simply the + // first match if none are completely valid. + else -> + bestMatches.firstOrNull { it.isValid() } + ?: bestMatches.first() + } + } + } + + internal class Serializer : BaseSerializer(Value::class) { + + override fun serialize( + value: Value, + generator: JsonGenerator, + provider: SerializerProvider, + ) { + when { + value.string != null -> generator.writeObject(value.string) + value.number != null -> generator.writeObject(value.number) + value._json != null -> generator.writeObject(value._json) + else -> throw IllegalStateException("Invalid Value") + } + } + } + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is SetColumnFilter && + measurement == other.measurement && + operator == other.operator && + value == other.value && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(measurement, operator, value, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "SetColumnFilter{measurement=$measurement, operator=$operator, value=$value, additionalProperties=$additionalProperties}" + } + + class NumericColumnFilter + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val measurement: JsonField, + private val operator: JsonField, + private val value: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("measurement") + @ExcludeMissing + measurement: JsonField = JsonMissing.of(), + @JsonProperty("operator") + @ExcludeMissing + operator: JsonField = JsonMissing.of(), + @JsonProperty("value") + @ExcludeMissing + value: JsonField = JsonMissing.of(), + ) : this(measurement, operator, value, mutableMapOf()) + + /** + * The name of the column. + * + * @throws OpenlayerInvalidDataException if the JSON field has an unexpected + * type or is unexpectedly missing or null (e.g. if the server responded with + * an unexpected value). + */ + fun measurement(): String = measurement.getRequired("measurement") + + /** + * @throws OpenlayerInvalidDataException if the JSON field has an unexpected + * type or is unexpectedly missing or null (e.g. if the server responded with + * an unexpected value). + */ + fun operator(): Operator = operator.getRequired("operator") + + /** + * @throws OpenlayerInvalidDataException 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 [measurement]. + * + * Unlike [measurement], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("measurement") + @ExcludeMissing + fun _measurement(): JsonField = measurement + + /** + * Returns the raw JSON value of [operator]. + * + * Unlike [operator], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("operator") + @ExcludeMissing + fun _operator(): JsonField = operator + + /** + * 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 + * [NumericColumnFilter]. + * + * The following fields are required: + * ```java + * .measurement() + * .operator() + * .value() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [NumericColumnFilter]. */ + class Builder internal constructor() { + + private var measurement: JsonField? = null + private var operator: JsonField? = null + private var value: JsonField? = null + private var additionalProperties: MutableMap = + mutableMapOf() + + @JvmSynthetic + internal fun from(numericColumnFilter: NumericColumnFilter) = apply { + measurement = numericColumnFilter.measurement + operator = numericColumnFilter.operator + value = numericColumnFilter.value + additionalProperties = + numericColumnFilter.additionalProperties.toMutableMap() + } + + /** The name of the column. */ + fun measurement(measurement: String) = + measurement(JsonField.of(measurement)) + + /** + * Sets [Builder.measurement] to an arbitrary JSON value. + * + * You should usually call [Builder.measurement] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun measurement(measurement: JsonField) = apply { + this.measurement = measurement + } + + fun operator(operator: Operator) = operator(JsonField.of(operator)) + + /** + * Sets [Builder.operator] to an arbitrary JSON value. + * + * You should usually call [Builder.operator] with a well-typed [Operator] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun operator(operator: JsonField) = apply { + this.operator = operator + } + + fun value(value: Float?) = value(JsonField.ofNullable(value)) + + /** + * Alias for [Builder.value]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun value(value: Float) = value(value as Float?) + + /** Alias for calling [Builder.value] with `value.orElse(null)`. */ + fun value(value: Optional) = value(value.getOrNull()) + + /** + * Sets [Builder.value] to an arbitrary JSON value. + * + * You should usually call [Builder.value] with a well-typed [Float] 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 [NumericColumnFilter]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .measurement() + * .operator() + * .value() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): NumericColumnFilter = + NumericColumnFilter( + checkRequired("measurement", measurement), + checkRequired("operator", operator), + checkRequired("value", value), + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): NumericColumnFilter = apply { + if (validated) { + return@apply + } + + measurement() + operator().validate() + value() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OpenlayerInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (if (measurement.asKnown().isPresent) 1 else 0) + + (operator.asKnown().getOrNull()?.validity() ?: 0) + + (if (value.asKnown().isPresent) 1 else 0) + + class Operator + @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 GREATER = of(">") + + @JvmField val GREATER_OR_EQUALS = of(">=") + + @JvmField val IS = of("is") + + @JvmField val LESS = of("<") + + @JvmField val LESS_OR_EQUALS = of("<=") + + @JvmField val NOT_EQUALS = of("!=") + + @JvmStatic fun of(value: String) = Operator(JsonField.of(value)) + } + + /** An enum containing [Operator]'s known values. */ + enum class Known { + GREATER, + GREATER_OR_EQUALS, + IS, + LESS, + LESS_OR_EQUALS, + NOT_EQUALS, + } + + /** + * An enum containing [Operator]'s known values, as well as an [_UNKNOWN] + * member. + * + * An instance of [Operator] 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 { + GREATER, + GREATER_OR_EQUALS, + IS, + LESS, + LESS_OR_EQUALS, + NOT_EQUALS, + /** + * An enum member indicating that [Operator] 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) { + GREATER -> Value.GREATER + GREATER_OR_EQUALS -> Value.GREATER_OR_EQUALS + IS -> Value.IS + LESS -> Value.LESS + LESS_OR_EQUALS -> Value.LESS_OR_EQUALS + NOT_EQUALS -> Value.NOT_EQUALS + 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 OpenlayerInvalidDataException if this class instance's value is a + * not a known member. + */ + fun known(): Known = + when (this) { + GREATER -> Known.GREATER + GREATER_OR_EQUALS -> Known.GREATER_OR_EQUALS + IS -> Known.IS + LESS -> Known.LESS + LESS_OR_EQUALS -> Known.LESS_OR_EQUALS + NOT_EQUALS -> Known.NOT_EQUALS + else -> + throw OpenlayerInvalidDataException("Unknown Operator: $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 OpenlayerInvalidDataException if this class instance's value does + * not have the expected primitive type. + */ + fun asString(): String = + _value().asString().orElseThrow { + OpenlayerInvalidDataException("Value is not a String") + } + + private var validated: Boolean = false + + fun validate(): Operator = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OpenlayerInvalidDataException) { + false + } + + /** + * Returns a 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 Operator && 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 NumericColumnFilter && + measurement == other.measurement && + operator == other.operator && + value == other.value && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(measurement, operator, value, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "NumericColumnFilter{measurement=$measurement, operator=$operator, value=$value, additionalProperties=$additionalProperties}" + } + + class StringColumnFilter + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val measurement: JsonField, + private val operator: JsonField, + private val value: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("measurement") + @ExcludeMissing + measurement: JsonField = JsonMissing.of(), + @JsonProperty("operator") + @ExcludeMissing + operator: JsonField = JsonMissing.of(), + @JsonProperty("value") + @ExcludeMissing + value: JsonField = JsonMissing.of(), + ) : this(measurement, operator, value, mutableMapOf()) + + /** + * The name of the column. + * + * @throws OpenlayerInvalidDataException if the JSON field has an unexpected + * type or is unexpectedly missing or null (e.g. if the server responded with + * an unexpected value). + */ + fun measurement(): String = measurement.getRequired("measurement") + + /** + * @throws OpenlayerInvalidDataException if the JSON field has an unexpected + * type or is unexpectedly missing or null (e.g. if the server responded with + * an unexpected value). + */ + fun operator(): Operator = operator.getRequired("operator") + + /** + * @throws OpenlayerInvalidDataException if the JSON field has an unexpected + * type or is unexpectedly missing or null (e.g. if the server responded with + * an unexpected value). + */ + fun value(): Value = value.getRequired("value") + + /** + * Returns the raw JSON value of [measurement]. + * + * Unlike [measurement], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("measurement") + @ExcludeMissing + fun _measurement(): JsonField = measurement + + /** + * Returns the raw JSON value of [operator]. + * + * Unlike [operator], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("operator") + @ExcludeMissing + fun _operator(): JsonField = operator + + /** + * 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 + * [StringColumnFilter]. + * + * The following fields are required: + * ```java + * .measurement() + * .operator() + * .value() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [StringColumnFilter]. */ + class Builder internal constructor() { + + private var measurement: JsonField? = null + private var operator: JsonField? = null + private var value: JsonField? = null + private var additionalProperties: MutableMap = + mutableMapOf() + + @JvmSynthetic + internal fun from(stringColumnFilter: StringColumnFilter) = apply { + measurement = stringColumnFilter.measurement + operator = stringColumnFilter.operator + value = stringColumnFilter.value + additionalProperties = + stringColumnFilter.additionalProperties.toMutableMap() + } + + /** The name of the column. */ + fun measurement(measurement: String) = + measurement(JsonField.of(measurement)) + + /** + * Sets [Builder.measurement] to an arbitrary JSON value. + * + * You should usually call [Builder.measurement] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun measurement(measurement: JsonField) = apply { + this.measurement = measurement + } + + fun operator(operator: Operator) = operator(JsonField.of(operator)) + + /** + * Sets [Builder.operator] to an arbitrary JSON value. + * + * You should usually call [Builder.operator] with a well-typed [Operator] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun operator(operator: JsonField) = apply { + this.operator = operator + } + + fun value(value: Value) = value(JsonField.of(value)) + + /** + * Sets [Builder.value] to an arbitrary JSON value. + * + * You should usually call [Builder.value] with a well-typed [Value] 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 } + + /** Alias for calling [value] with `Value.ofString(string)`. */ + fun value(string: String) = value(Value.ofString(string)) + + /** Alias for calling [value] with `Value.ofBool(bool)`. */ + fun value(bool: Boolean) = value(Value.ofBool(bool)) + + 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 [StringColumnFilter]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .measurement() + * .operator() + * .value() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): StringColumnFilter = + StringColumnFilter( + checkRequired("measurement", measurement), + checkRequired("operator", operator), + checkRequired("value", value), + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): StringColumnFilter = apply { + if (validated) { + return@apply + } + + measurement() + operator().validate() + value().validate() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OpenlayerInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (if (measurement.asKnown().isPresent) 1 else 0) + + (operator.asKnown().getOrNull()?.validity() ?: 0) + + (value.asKnown().getOrNull()?.validity() ?: 0) + + class Operator + @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 IS = of("is") + + @JvmField val NOT_EQUALS = of("!=") + + @JvmStatic fun of(value: String) = Operator(JsonField.of(value)) + } + + /** An enum containing [Operator]'s known values. */ + enum class Known { + IS, + NOT_EQUALS, + } + + /** + * An enum containing [Operator]'s known values, as well as an [_UNKNOWN] + * member. + * + * An instance of [Operator] 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 { + IS, + NOT_EQUALS, + /** + * An enum member indicating that [Operator] 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) { + IS -> Value.IS + NOT_EQUALS -> Value.NOT_EQUALS + 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 OpenlayerInvalidDataException if this class instance's value is a + * not a known member. + */ + fun known(): Known = + when (this) { + IS -> Known.IS + NOT_EQUALS -> Known.NOT_EQUALS + else -> + throw OpenlayerInvalidDataException("Unknown Operator: $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 OpenlayerInvalidDataException if this class instance's value does + * not have the expected primitive type. + */ + fun asString(): String = + _value().asString().orElseThrow { + OpenlayerInvalidDataException("Value is not a String") + } + + private var validated: Boolean = false + + fun validate(): Operator = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OpenlayerInvalidDataException) { + false + } + + /** + * Returns a 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 Operator && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + @JsonDeserialize(using = Value.Deserializer::class) + @JsonSerialize(using = Value.Serializer::class) + class Value + private constructor( + private val string: String? = null, + private val bool: Boolean? = null, + private val _json: JsonValue? = null, + ) { + + fun string(): Optional = Optional.ofNullable(string) + + fun bool(): Optional = Optional.ofNullable(bool) + + fun isString(): Boolean = string != null + + fun isBool(): Boolean = bool != null + + fun asString(): String = string.getOrThrow("string") + + fun asBool(): Boolean = bool.getOrThrow("bool") + + fun _json(): Optional = Optional.ofNullable(_json) + + fun accept(visitor: Visitor): T = + when { + string != null -> visitor.visitString(string) + bool != null -> visitor.visitBool(bool) + else -> visitor.unknown(_json) + } + + private var validated: Boolean = false + + fun validate(): Value = apply { + if (validated) { + return@apply + } + + accept( + object : Visitor { + override fun visitString(string: String) {} + + override fun visitBool(bool: Boolean) {} + } + ) + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OpenlayerInvalidDataException) { + false + } + + /** + * Returns 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 visitString(string: String) = 1 + + override fun visitBool(bool: Boolean) = 1 + + override fun unknown(json: JsonValue?) = 0 + } + ) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Value && string == other.string && bool == other.bool + } + + override fun hashCode(): Int = Objects.hash(string, bool) + + override fun toString(): String = + when { + string != null -> "Value{string=$string}" + bool != null -> "Value{bool=$bool}" + _json != null -> "Value{_unknown=$_json}" + else -> throw IllegalStateException("Invalid Value") + } + + companion object { + + @JvmStatic fun ofString(string: String) = Value(string = string) + + @JvmStatic fun ofBool(bool: Boolean) = Value(bool = bool) + } + + /** + * An interface that defines how to map each variant of [Value] to a value + * of type [T]. + */ + interface Visitor { + + fun visitString(string: String): T + + fun visitBool(bool: Boolean): T + + /** + * Maps an unknown variant of [Value] to a value of type [T]. + * + * An instance of [Value] 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 OpenlayerInvalidDataException in the default implementation. + */ + fun unknown(json: JsonValue?): T { + throw OpenlayerInvalidDataException("Unknown Value: $json") + } + } + + internal class Deserializer : BaseDeserializer(Value::class) { + + override fun ObjectCodec.deserialize(node: JsonNode): Value { + val json = JsonValue.fromJsonNode(node) + + val bestMatches = + sequenceOf( + tryDeserialize(node, jacksonTypeRef())?.let { + Value(string = it, _json = json) + }, + tryDeserialize(node, jacksonTypeRef())?.let { + Value(bool = it, _json = json) + }, + ) + .filterNotNull() + .allMaxBy { it.validity() } + .toList() + return when (bestMatches.size) { + // This can happen if what we're deserializing is completely + // incompatible with all the possible variants (e.g. + // deserializing from object). + 0 -> Value(_json = json) + 1 -> bestMatches.single() + // If there's more than one match with the highest validity, + // then use the first completely valid match, or simply the + // first match if none are completely valid. + else -> + bestMatches.firstOrNull { it.isValid() } + ?: bestMatches.first() + } + } + } + + internal class Serializer : BaseSerializer(Value::class) { + + override fun serialize( + value: Value, + generator: JsonGenerator, + provider: SerializerProvider, + ) { + when { + value.string != null -> generator.writeObject(value.string) + value.bool != null -> generator.writeObject(value.bool) + value._json != null -> generator.writeObject(value._json) + else -> throw IllegalStateException("Invalid Value") + } + } + } + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is StringColumnFilter && + measurement == other.measurement && + operator == other.operator && + value == other.value && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(measurement, operator, value, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "StringColumnFilter{measurement=$measurement, operator=$operator, value=$value, additionalProperties=$additionalProperties}" + } + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is RowsBody && + columnFilters == other.columnFilters && + excludeRowIdList == other.excludeRowIdList && + notSearchQueryAnd == other.notSearchQueryAnd && + notSearchQueryOr == other.notSearchQueryOr && + rowIdList == other.rowIdList && + searchQueryAnd == other.searchQueryAnd && + searchQueryOr == other.searchQueryOr && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + columnFilters, + excludeRowIdList, + notSearchQueryAnd, + notSearchQueryOr, + rowIdList, + searchQueryAnd, + searchQueryOr, + additionalProperties, + ) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "RowsBody{columnFilters=$columnFilters, excludeRowIdList=$excludeRowIdList, notSearchQueryAnd=$notSearchQueryAnd, notSearchQueryOr=$notSearchQueryOr, rowIdList=$rowIdList, searchQueryAnd=$searchQueryAnd, searchQueryOr=$searchQueryOr, additionalProperties=$additionalProperties}" + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is LastUnskippedResult && + id == other.id && + dateCreated == other.dateCreated && + dateDataEnds == other.dateDataEnds && + dateDataStarts == other.dateDataStarts && + dateUpdated == other.dateUpdated && + inferencePipelineId == other.inferencePipelineId && + projectVersionId == other.projectVersionId && + status == other.status && + statusMessage == other.statusMessage && + expectedValues == other.expectedValues && + goal == other.goal && + goalId == other.goalId && + rows == other.rows && + rowsBody == other.rowsBody && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + id, + dateCreated, + dateDataEnds, + dateDataStarts, + dateUpdated, + inferencePipelineId, + projectVersionId, + status, + statusMessage, + expectedValues, + goal, + goalId, + rows, + rowsBody, + additionalProperties, + ) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "LastUnskippedResult{id=$id, dateCreated=$dateCreated, dateDataEnds=$dateDataEnds, dateDataStarts=$dateDataStarts, dateUpdated=$dateUpdated, inferencePipelineId=$inferencePipelineId, projectVersionId=$projectVersionId, status=$status, statusMessage=$statusMessage, expectedValues=$expectedValues, goal=$goal, goalId=$goalId, rows=$rows, rowsBody=$rowsBody, additionalProperties=$additionalProperties}" + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is TestListResultsResponse && + items == other.items && + lastUnskippedResult == other.lastUnskippedResult && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(items, lastUnskippedResult, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "TestListResultsResponse{items=$items, lastUnskippedResult=$lastUnskippedResult, additionalProperties=$additionalProperties}" +} diff --git a/openlayer-java-core/src/main/kotlin/com/openlayer/api/services/async/TestServiceAsync.kt b/openlayer-java-core/src/main/kotlin/com/openlayer/api/services/async/TestServiceAsync.kt index 2a37b8d3..01418b7a 100644 --- a/openlayer-java-core/src/main/kotlin/com/openlayer/api/services/async/TestServiceAsync.kt +++ b/openlayer-java-core/src/main/kotlin/com/openlayer/api/services/async/TestServiceAsync.kt @@ -7,6 +7,8 @@ import com.openlayer.api.core.RequestOptions import com.openlayer.api.core.http.HttpResponseFor import com.openlayer.api.models.tests.TestEvaluateParams import com.openlayer.api.models.tests.TestEvaluateResponse +import com.openlayer.api.models.tests.TestListResultsParams +import com.openlayer.api.models.tests.TestListResultsResponse import java.util.concurrent.CompletableFuture import java.util.function.Consumer @@ -52,6 +54,42 @@ interface TestServiceAsync { requestOptions: RequestOptions = RequestOptions.none(), ): CompletableFuture + /** List the test results for a test. */ + fun listResults(testId: String): CompletableFuture = + listResults(testId, TestListResultsParams.none()) + + /** @see listResults */ + fun listResults( + testId: String, + params: TestListResultsParams = TestListResultsParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture = + listResults(params.toBuilder().testId(testId).build(), requestOptions) + + /** @see listResults */ + fun listResults( + testId: String, + params: TestListResultsParams = TestListResultsParams.none(), + ): CompletableFuture = + listResults(testId, params, RequestOptions.none()) + + /** @see listResults */ + fun listResults( + params: TestListResultsParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture + + /** @see listResults */ + fun listResults(params: TestListResultsParams): CompletableFuture = + listResults(params, RequestOptions.none()) + + /** @see listResults */ + fun listResults( + testId: String, + requestOptions: RequestOptions, + ): CompletableFuture = + listResults(testId, TestListResultsParams.none(), requestOptions) + /** A view of [TestServiceAsync] that provides access to raw HTTP responses for each method. */ interface WithRawResponse { @@ -91,5 +129,48 @@ interface TestServiceAsync { params: TestEvaluateParams, requestOptions: RequestOptions = RequestOptions.none(), ): CompletableFuture> + + /** + * Returns a raw HTTP response for `get /tests/{testId}/results`, but is otherwise the same + * as [TestServiceAsync.listResults]. + */ + fun listResults( + testId: String + ): CompletableFuture> = + listResults(testId, TestListResultsParams.none()) + + /** @see listResults */ + fun listResults( + testId: String, + params: TestListResultsParams = TestListResultsParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture> = + listResults(params.toBuilder().testId(testId).build(), requestOptions) + + /** @see listResults */ + fun listResults( + testId: String, + params: TestListResultsParams = TestListResultsParams.none(), + ): CompletableFuture> = + listResults(testId, params, RequestOptions.none()) + + /** @see listResults */ + fun listResults( + params: TestListResultsParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture> + + /** @see listResults */ + fun listResults( + params: TestListResultsParams + ): CompletableFuture> = + listResults(params, RequestOptions.none()) + + /** @see listResults */ + fun listResults( + testId: String, + requestOptions: RequestOptions, + ): CompletableFuture> = + listResults(testId, TestListResultsParams.none(), requestOptions) } } diff --git a/openlayer-java-core/src/main/kotlin/com/openlayer/api/services/async/TestServiceAsyncImpl.kt b/openlayer-java-core/src/main/kotlin/com/openlayer/api/services/async/TestServiceAsyncImpl.kt index b5699301..eef1745a 100644 --- a/openlayer-java-core/src/main/kotlin/com/openlayer/api/services/async/TestServiceAsyncImpl.kt +++ b/openlayer-java-core/src/main/kotlin/com/openlayer/api/services/async/TestServiceAsyncImpl.kt @@ -18,6 +18,8 @@ import com.openlayer.api.core.http.parseable import com.openlayer.api.core.prepareAsync import com.openlayer.api.models.tests.TestEvaluateParams import com.openlayer.api.models.tests.TestEvaluateResponse +import com.openlayer.api.models.tests.TestListResultsParams +import com.openlayer.api.models.tests.TestListResultsResponse import java.util.concurrent.CompletableFuture import java.util.function.Consumer import kotlin.jvm.optionals.getOrNull @@ -41,6 +43,13 @@ class TestServiceAsyncImpl internal constructor(private val clientOptions: Clien // post /tests/{testId}/evaluate withRawResponse().evaluate(params, requestOptions).thenApply { it.parse() } + override fun listResults( + params: TestListResultsParams, + requestOptions: RequestOptions, + ): CompletableFuture = + // get /tests/{testId}/results + withRawResponse().listResults(params, requestOptions).thenApply { it.parse() } + class WithRawResponseImpl internal constructor(private val clientOptions: ClientOptions) : TestServiceAsync.WithRawResponse { @@ -87,5 +96,38 @@ class TestServiceAsyncImpl internal constructor(private val clientOptions: Clien } } } + + private val listResultsHandler: Handler = + jsonHandler(clientOptions.jsonMapper) + + override fun listResults( + params: TestListResultsParams, + requestOptions: RequestOptions, + ): CompletableFuture> { + // We check here instead of in the params builder because this can be specified + // positionally or in the params class. + checkRequired("testId", params.testId().getOrNull()) + val request = + HttpRequest.builder() + .method(HttpMethod.GET) + .baseUrl(clientOptions.baseUrl()) + .addPathSegments("tests", params._pathParam(0), "results") + .build() + .prepareAsync(clientOptions, params) + val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) + return request + .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } + .thenApply { response -> + errorHandler.handle(response).parseable { + response + .use { listResultsHandler.handle(it) } + .also { + if (requestOptions.responseValidation!!) { + it.validate() + } + } + } + } + } } } diff --git a/openlayer-java-core/src/main/kotlin/com/openlayer/api/services/blocking/TestService.kt b/openlayer-java-core/src/main/kotlin/com/openlayer/api/services/blocking/TestService.kt index bcb91b39..61147499 100644 --- a/openlayer-java-core/src/main/kotlin/com/openlayer/api/services/blocking/TestService.kt +++ b/openlayer-java-core/src/main/kotlin/com/openlayer/api/services/blocking/TestService.kt @@ -8,6 +8,8 @@ import com.openlayer.api.core.RequestOptions import com.openlayer.api.core.http.HttpResponseFor import com.openlayer.api.models.tests.TestEvaluateParams import com.openlayer.api.models.tests.TestEvaluateResponse +import com.openlayer.api.models.tests.TestListResultsParams +import com.openlayer.api.models.tests.TestListResultsResponse import java.util.function.Consumer interface TestService { @@ -49,6 +51,38 @@ interface TestService { requestOptions: RequestOptions = RequestOptions.none(), ): TestEvaluateResponse + /** List the test results for a test. */ + fun listResults(testId: String): TestListResultsResponse = + listResults(testId, TestListResultsParams.none()) + + /** @see listResults */ + fun listResults( + testId: String, + params: TestListResultsParams = TestListResultsParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): TestListResultsResponse = + listResults(params.toBuilder().testId(testId).build(), requestOptions) + + /** @see listResults */ + fun listResults( + testId: String, + params: TestListResultsParams = TestListResultsParams.none(), + ): TestListResultsResponse = listResults(testId, params, RequestOptions.none()) + + /** @see listResults */ + fun listResults( + params: TestListResultsParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): TestListResultsResponse + + /** @see listResults */ + fun listResults(params: TestListResultsParams): TestListResultsResponse = + listResults(params, RequestOptions.none()) + + /** @see listResults */ + fun listResults(testId: String, requestOptions: RequestOptions): TestListResultsResponse = + listResults(testId, TestListResultsParams.none(), requestOptions) + /** A view of [TestService] that provides access to raw HTTP responses for each method. */ interface WithRawResponse { @@ -89,5 +123,50 @@ interface TestService { params: TestEvaluateParams, requestOptions: RequestOptions = RequestOptions.none(), ): HttpResponseFor + + /** + * Returns a raw HTTP response for `get /tests/{testId}/results`, but is otherwise the same + * as [TestService.listResults]. + */ + @MustBeClosed + fun listResults(testId: String): HttpResponseFor = + listResults(testId, TestListResultsParams.none()) + + /** @see listResults */ + @MustBeClosed + fun listResults( + testId: String, + params: TestListResultsParams = TestListResultsParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): HttpResponseFor = + listResults(params.toBuilder().testId(testId).build(), requestOptions) + + /** @see listResults */ + @MustBeClosed + fun listResults( + testId: String, + params: TestListResultsParams = TestListResultsParams.none(), + ): HttpResponseFor = + listResults(testId, params, RequestOptions.none()) + + /** @see listResults */ + @MustBeClosed + fun listResults( + params: TestListResultsParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): HttpResponseFor + + /** @see listResults */ + @MustBeClosed + fun listResults(params: TestListResultsParams): HttpResponseFor = + listResults(params, RequestOptions.none()) + + /** @see listResults */ + @MustBeClosed + fun listResults( + testId: String, + requestOptions: RequestOptions, + ): HttpResponseFor = + listResults(testId, TestListResultsParams.none(), requestOptions) } } diff --git a/openlayer-java-core/src/main/kotlin/com/openlayer/api/services/blocking/TestServiceImpl.kt b/openlayer-java-core/src/main/kotlin/com/openlayer/api/services/blocking/TestServiceImpl.kt index 70e2338f..79ef8b23 100644 --- a/openlayer-java-core/src/main/kotlin/com/openlayer/api/services/blocking/TestServiceImpl.kt +++ b/openlayer-java-core/src/main/kotlin/com/openlayer/api/services/blocking/TestServiceImpl.kt @@ -18,6 +18,8 @@ import com.openlayer.api.core.http.parseable import com.openlayer.api.core.prepare import com.openlayer.api.models.tests.TestEvaluateParams import com.openlayer.api.models.tests.TestEvaluateResponse +import com.openlayer.api.models.tests.TestListResultsParams +import com.openlayer.api.models.tests.TestListResultsResponse import java.util.function.Consumer import kotlin.jvm.optionals.getOrNull @@ -39,6 +41,13 @@ class TestServiceImpl internal constructor(private val clientOptions: ClientOpti // post /tests/{testId}/evaluate withRawResponse().evaluate(params, requestOptions).parse() + override fun listResults( + params: TestListResultsParams, + requestOptions: RequestOptions, + ): TestListResultsResponse = + // get /tests/{testId}/results + withRawResponse().listResults(params, requestOptions).parse() + class WithRawResponseImpl internal constructor(private val clientOptions: ClientOptions) : TestService.WithRawResponse { @@ -82,5 +91,35 @@ class TestServiceImpl internal constructor(private val clientOptions: ClientOpti } } } + + private val listResultsHandler: Handler = + jsonHandler(clientOptions.jsonMapper) + + override fun listResults( + params: TestListResultsParams, + requestOptions: RequestOptions, + ): HttpResponseFor { + // We check here instead of in the params builder because this can be specified + // positionally or in the params class. + checkRequired("testId", params.testId().getOrNull()) + val request = + HttpRequest.builder() + .method(HttpMethod.GET) + .baseUrl(clientOptions.baseUrl()) + .addPathSegments("tests", params._pathParam(0), "results") + .build() + .prepare(clientOptions, params) + val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) + val response = clientOptions.httpClient.execute(request, requestOptions) + return errorHandler.handle(response).parseable { + response + .use { listResultsHandler.handle(it) } + .also { + if (requestOptions.responseValidation!!) { + it.validate() + } + } + } + } } } diff --git a/openlayer-java-core/src/test/kotlin/com/openlayer/api/models/commits/testresults/TestResultListResponseTest.kt b/openlayer-java-core/src/test/kotlin/com/openlayer/api/models/commits/testresults/TestResultListResponseTest.kt index 5045cc8f..8aae5825 100644 --- a/openlayer-java-core/src/test/kotlin/com/openlayer/api/models/commits/testresults/TestResultListResponseTest.kt +++ b/openlayer-java-core/src/test/kotlin/com/openlayer/api/models/commits/testresults/TestResultListResponseTest.kt @@ -26,6 +26,13 @@ internal class TestResultListResponseTest { .projectVersionId("3fa85f64-5717-4562-b3fc-2c963f66afa6") .status(TestResultListResponse.Item.Status.PASSING) .statusMessage("Test successfully processed.") + .addExpectedValue( + TestResultListResponse.Item.ExpectedValue.builder() + .lowerThreshold(0.0f) + .measurement("measurement") + .upperThreshold(0.0f) + .build() + ) .goal( TestResultListResponse.Item.Goal.builder() .id("3fa85f64-5717-4562-b3fc-2c963f66afa6") @@ -84,6 +91,33 @@ internal class TestResultListResponseTest { .build() ) .goalId("3fa85f64-5717-4562-b3fc-2c963f66afa6") + .rows( + "https://api.openlayer.com/v1/versions/3fa85f64-5717-4562-b3fc-2c963f66afa6/rows?label=validation" + ) + .rowsBody( + TestResultListResponse.Item.RowsBody.builder() + .addColumnFilter( + TestResultListResponse.Item.RowsBody.ColumnFilter + .SetColumnFilter + .builder() + .measurement("openlayer_token_set") + .operator( + TestResultListResponse.Item.RowsBody.ColumnFilter + .SetColumnFilter + .Operator + .CONTAINS_NONE + ) + .addValue("cat") + .build() + ) + .addExcludeRowIdList(0L) + .addNotSearchQueryAnd("string") + .addNotSearchQueryOr("string") + .addRowIdList(0L) + .addSearchQueryAnd("string") + .addSearchQueryOr("string") + .build() + ) .build() ) .build() @@ -100,6 +134,13 @@ internal class TestResultListResponseTest { .projectVersionId("3fa85f64-5717-4562-b3fc-2c963f66afa6") .status(TestResultListResponse.Item.Status.PASSING) .statusMessage("Test successfully processed.") + .addExpectedValue( + TestResultListResponse.Item.ExpectedValue.builder() + .lowerThreshold(0.0f) + .measurement("measurement") + .upperThreshold(0.0f) + .build() + ) .goal( TestResultListResponse.Item.Goal.builder() .id("3fa85f64-5717-4562-b3fc-2c963f66afa6") @@ -155,6 +196,32 @@ internal class TestResultListResponseTest { .build() ) .goalId("3fa85f64-5717-4562-b3fc-2c963f66afa6") + .rows( + "https://api.openlayer.com/v1/versions/3fa85f64-5717-4562-b3fc-2c963f66afa6/rows?label=validation" + ) + .rowsBody( + TestResultListResponse.Item.RowsBody.builder() + .addColumnFilter( + TestResultListResponse.Item.RowsBody.ColumnFilter.SetColumnFilter + .builder() + .measurement("openlayer_token_set") + .operator( + TestResultListResponse.Item.RowsBody.ColumnFilter + .SetColumnFilter + .Operator + .CONTAINS_NONE + ) + .addValue("cat") + .build() + ) + .addExcludeRowIdList(0L) + .addNotSearchQueryAnd("string") + .addNotSearchQueryOr("string") + .addRowIdList(0L) + .addSearchQueryAnd("string") + .addSearchQueryOr("string") + .build() + ) .build() ) } @@ -175,6 +242,13 @@ internal class TestResultListResponseTest { .projectVersionId("3fa85f64-5717-4562-b3fc-2c963f66afa6") .status(TestResultListResponse.Item.Status.PASSING) .statusMessage("Test successfully processed.") + .addExpectedValue( + TestResultListResponse.Item.ExpectedValue.builder() + .lowerThreshold(0.0f) + .measurement("measurement") + .upperThreshold(0.0f) + .build() + ) .goal( TestResultListResponse.Item.Goal.builder() .id("3fa85f64-5717-4562-b3fc-2c963f66afa6") @@ -233,6 +307,33 @@ internal class TestResultListResponseTest { .build() ) .goalId("3fa85f64-5717-4562-b3fc-2c963f66afa6") + .rows( + "https://api.openlayer.com/v1/versions/3fa85f64-5717-4562-b3fc-2c963f66afa6/rows?label=validation" + ) + .rowsBody( + TestResultListResponse.Item.RowsBody.builder() + .addColumnFilter( + TestResultListResponse.Item.RowsBody.ColumnFilter + .SetColumnFilter + .builder() + .measurement("openlayer_token_set") + .operator( + TestResultListResponse.Item.RowsBody.ColumnFilter + .SetColumnFilter + .Operator + .CONTAINS_NONE + ) + .addValue("cat") + .build() + ) + .addExcludeRowIdList(0L) + .addNotSearchQueryAnd("string") + .addNotSearchQueryOr("string") + .addRowIdList(0L) + .addSearchQueryAnd("string") + .addSearchQueryOr("string") + .build() + ) .build() ) .build() diff --git a/openlayer-java-core/src/test/kotlin/com/openlayer/api/models/inferencepipelines/testresults/TestResultListResponseTest.kt b/openlayer-java-core/src/test/kotlin/com/openlayer/api/models/inferencepipelines/testresults/TestResultListResponseTest.kt index 6051c9ef..a3d4648b 100644 --- a/openlayer-java-core/src/test/kotlin/com/openlayer/api/models/inferencepipelines/testresults/TestResultListResponseTest.kt +++ b/openlayer-java-core/src/test/kotlin/com/openlayer/api/models/inferencepipelines/testresults/TestResultListResponseTest.kt @@ -26,6 +26,13 @@ internal class TestResultListResponseTest { .projectVersionId("3fa85f64-5717-4562-b3fc-2c963f66afa6") .status(TestResultListResponse.Item.Status.PASSING) .statusMessage("Test successfully processed.") + .addExpectedValue( + TestResultListResponse.Item.ExpectedValue.builder() + .lowerThreshold(0.0f) + .measurement("measurement") + .upperThreshold(0.0f) + .build() + ) .goal( TestResultListResponse.Item.Goal.builder() .id("3fa85f64-5717-4562-b3fc-2c963f66afa6") @@ -84,6 +91,33 @@ internal class TestResultListResponseTest { .build() ) .goalId("3fa85f64-5717-4562-b3fc-2c963f66afa6") + .rows( + "https://api.openlayer.com/v1/versions/3fa85f64-5717-4562-b3fc-2c963f66afa6/rows?label=validation" + ) + .rowsBody( + TestResultListResponse.Item.RowsBody.builder() + .addColumnFilter( + TestResultListResponse.Item.RowsBody.ColumnFilter + .SetColumnFilter + .builder() + .measurement("openlayer_token_set") + .operator( + TestResultListResponse.Item.RowsBody.ColumnFilter + .SetColumnFilter + .Operator + .CONTAINS_NONE + ) + .addValue("cat") + .build() + ) + .addExcludeRowIdList(0L) + .addNotSearchQueryAnd("string") + .addNotSearchQueryOr("string") + .addRowIdList(0L) + .addSearchQueryAnd("string") + .addSearchQueryOr("string") + .build() + ) .build() ) .build() @@ -100,6 +134,13 @@ internal class TestResultListResponseTest { .projectVersionId("3fa85f64-5717-4562-b3fc-2c963f66afa6") .status(TestResultListResponse.Item.Status.PASSING) .statusMessage("Test successfully processed.") + .addExpectedValue( + TestResultListResponse.Item.ExpectedValue.builder() + .lowerThreshold(0.0f) + .measurement("measurement") + .upperThreshold(0.0f) + .build() + ) .goal( TestResultListResponse.Item.Goal.builder() .id("3fa85f64-5717-4562-b3fc-2c963f66afa6") @@ -155,6 +196,32 @@ internal class TestResultListResponseTest { .build() ) .goalId("3fa85f64-5717-4562-b3fc-2c963f66afa6") + .rows( + "https://api.openlayer.com/v1/versions/3fa85f64-5717-4562-b3fc-2c963f66afa6/rows?label=validation" + ) + .rowsBody( + TestResultListResponse.Item.RowsBody.builder() + .addColumnFilter( + TestResultListResponse.Item.RowsBody.ColumnFilter.SetColumnFilter + .builder() + .measurement("openlayer_token_set") + .operator( + TestResultListResponse.Item.RowsBody.ColumnFilter + .SetColumnFilter + .Operator + .CONTAINS_NONE + ) + .addValue("cat") + .build() + ) + .addExcludeRowIdList(0L) + .addNotSearchQueryAnd("string") + .addNotSearchQueryOr("string") + .addRowIdList(0L) + .addSearchQueryAnd("string") + .addSearchQueryOr("string") + .build() + ) .build() ) } @@ -175,6 +242,13 @@ internal class TestResultListResponseTest { .projectVersionId("3fa85f64-5717-4562-b3fc-2c963f66afa6") .status(TestResultListResponse.Item.Status.PASSING) .statusMessage("Test successfully processed.") + .addExpectedValue( + TestResultListResponse.Item.ExpectedValue.builder() + .lowerThreshold(0.0f) + .measurement("measurement") + .upperThreshold(0.0f) + .build() + ) .goal( TestResultListResponse.Item.Goal.builder() .id("3fa85f64-5717-4562-b3fc-2c963f66afa6") @@ -233,6 +307,33 @@ internal class TestResultListResponseTest { .build() ) .goalId("3fa85f64-5717-4562-b3fc-2c963f66afa6") + .rows( + "https://api.openlayer.com/v1/versions/3fa85f64-5717-4562-b3fc-2c963f66afa6/rows?label=validation" + ) + .rowsBody( + TestResultListResponse.Item.RowsBody.builder() + .addColumnFilter( + TestResultListResponse.Item.RowsBody.ColumnFilter + .SetColumnFilter + .builder() + .measurement("openlayer_token_set") + .operator( + TestResultListResponse.Item.RowsBody.ColumnFilter + .SetColumnFilter + .Operator + .CONTAINS_NONE + ) + .addValue("cat") + .build() + ) + .addExcludeRowIdList(0L) + .addNotSearchQueryAnd("string") + .addNotSearchQueryOr("string") + .addRowIdList(0L) + .addSearchQueryAnd("string") + .addSearchQueryOr("string") + .build() + ) .build() ) .build() diff --git a/openlayer-java-core/src/test/kotlin/com/openlayer/api/models/tests/TestListResultsParamsTest.kt b/openlayer-java-core/src/test/kotlin/com/openlayer/api/models/tests/TestListResultsParamsTest.kt new file mode 100644 index 00000000..6aec5077 --- /dev/null +++ b/openlayer-java-core/src/test/kotlin/com/openlayer/api/models/tests/TestListResultsParamsTest.kt @@ -0,0 +1,77 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openlayer.api.models.tests + +import com.openlayer.api.core.http.QueryParams +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test + +internal class TestListResultsParamsTest { + + @Test + fun create() { + TestListResultsParams.builder() + .testId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .endTimestamp(0.0) + .includeInsights(true) + .inferencePipelineId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .page(1L) + .perPage(1L) + .projectVersionId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .startTimestamp(0.0) + .addStatus("string") + .build() + } + + @Test + fun pathParams() { + val params = + TestListResultsParams.builder().testId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e").build() + + assertThat(params._pathParam(0)).isEqualTo("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + // out-of-bound path param + assertThat(params._pathParam(1)).isEqualTo("") + } + + @Test + fun queryParams() { + val params = + TestListResultsParams.builder() + .testId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .endTimestamp(0.0) + .includeInsights(true) + .inferencePipelineId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .page(1L) + .perPage(1L) + .projectVersionId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .startTimestamp(0.0) + .addStatus("string") + .build() + + val queryParams = params._queryParams() + + assertThat(queryParams) + .isEqualTo( + QueryParams.builder() + .put("endTimestamp", "0.0") + .put("includeInsights", "true") + .put("inferencePipelineId", "182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .put("page", "1") + .put("perPage", "1") + .put("projectVersionId", "182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .put("startTimestamp", "0.0") + .put("status", listOf("string").joinToString(",")) + .build() + ) + } + + @Test + fun queryParamsWithoutOptionalFields() { + val params = + TestListResultsParams.builder().testId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e").build() + + val queryParams = params._queryParams() + + assertThat(queryParams).isEqualTo(QueryParams.builder().build()) + } +} diff --git a/openlayer-java-core/src/test/kotlin/com/openlayer/api/models/tests/TestListResultsResponseTest.kt b/openlayer-java-core/src/test/kotlin/com/openlayer/api/models/tests/TestListResultsResponseTest.kt new file mode 100644 index 00000000..6608f9b1 --- /dev/null +++ b/openlayer-java-core/src/test/kotlin/com/openlayer/api/models/tests/TestListResultsResponseTest.kt @@ -0,0 +1,698 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openlayer.api.models.tests + +import com.fasterxml.jackson.module.kotlin.jacksonTypeRef +import com.openlayer.api.core.JsonValue +import com.openlayer.api.core.jsonMapper +import java.time.OffsetDateTime +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test + +internal class TestListResultsResponseTest { + + @Test + fun create() { + val testListResultsResponse = + TestListResultsResponse.builder() + .addItem( + TestListResultsResponse.Item.builder() + .id("3fa85f64-5717-4562-b3fc-2c963f66afa6") + .dateCreated(OffsetDateTime.parse("2024-03-22T11:31:01.185Z")) + .dateDataEnds(OffsetDateTime.parse("2024-03-22T11:31:01.185Z")) + .dateDataStarts(OffsetDateTime.parse("2024-03-22T11:31:01.185Z")) + .dateUpdated(OffsetDateTime.parse("2024-03-22T11:31:01.185Z")) + .inferencePipelineId("3fa85f64-5717-4562-b3fc-2c963f66afa6") + .projectVersionId("3fa85f64-5717-4562-b3fc-2c963f66afa6") + .status(TestListResultsResponse.Item.Status.PASSING) + .statusMessage("Test successfully processed.") + .addExpectedValue( + TestListResultsResponse.Item.ExpectedValue.builder() + .lowerThreshold(0.0f) + .measurement("measurement") + .upperThreshold(0.0f) + .build() + ) + .goal( + TestListResultsResponse.Item.Goal.builder() + .id("3fa85f64-5717-4562-b3fc-2c963f66afa6") + .commentCount(0L) + .creatorId("589ece63-49a2-41b4-98e1-10547761d4b0") + .dateArchived(OffsetDateTime.parse("2024-03-22T11:31:01.185Z")) + .dateCreated(OffsetDateTime.parse("2024-03-22T11:31:01.185Z")) + .dateUpdated(OffsetDateTime.parse("2024-03-22T11:31:01.185Z")) + .description( + JsonValue.from( + "This test checks for duplicate rows in the dataset." + ) + ) + .name("No duplicate rows") + .number(1L) + .originProjectVersionId("3fa85f64-5717-4562-b3fc-2c963f66afa6") + .subtype( + TestListResultsResponse.Item.Goal.Subtype.DUPLICATE_ROW_COUNT + ) + .suggested(false) + .addThreshold( + TestListResultsResponse.Item.Goal.Threshold.builder() + .insightName( + TestListResultsResponse.Item.Goal.Threshold.InsightName + .DUPLICATE_ROW_COUNT + ) + .addInsightParameter( + TestListResultsResponse.Item.Goal.Threshold + .InsightParameter + .builder() + .name("column_name") + .value(JsonValue.from("Age")) + .build() + ) + .measurement("duplicateRowCount") + .operator( + TestListResultsResponse.Item.Goal.Threshold.Operator + .LESS_OR_EQUALS + ) + .thresholdMode( + TestListResultsResponse.Item.Goal.Threshold + .ThresholdMode + .AUTOMATIC + ) + .value(0.0) + .build() + ) + .type(TestListResultsResponse.Item.Goal.Type.INTEGRITY) + .archived(false) + .delayWindow(0.0) + .evaluationWindow(3600.0) + .usesMlModel(false) + .usesProductionData(false) + .usesReferenceDataset(false) + .usesTrainingDataset(false) + .usesValidationDataset(true) + .build() + ) + .goalId("3fa85f64-5717-4562-b3fc-2c963f66afa6") + .rows( + "https://api.openlayer.com/v1/versions/3fa85f64-5717-4562-b3fc-2c963f66afa6/rows?label=validation" + ) + .rowsBody( + TestListResultsResponse.Item.RowsBody.builder() + .addColumnFilter( + TestListResultsResponse.Item.RowsBody.ColumnFilter + .SetColumnFilter + .builder() + .measurement("openlayer_token_set") + .operator( + TestListResultsResponse.Item.RowsBody.ColumnFilter + .SetColumnFilter + .Operator + .CONTAINS_NONE + ) + .addValue("cat") + .build() + ) + .addExcludeRowIdList(0L) + .addNotSearchQueryAnd("string") + .addNotSearchQueryOr("string") + .addRowIdList(0L) + .addSearchQueryAnd("string") + .addSearchQueryOr("string") + .build() + ) + .build() + ) + .lastUnskippedResult( + TestListResultsResponse.LastUnskippedResult.builder() + .id("3fa85f64-5717-4562-b3fc-2c963f66afa6") + .dateCreated(OffsetDateTime.parse("2024-03-22T11:31:01.185Z")) + .dateDataEnds(OffsetDateTime.parse("2024-03-22T11:31:01.185Z")) + .dateDataStarts(OffsetDateTime.parse("2024-03-22T11:31:01.185Z")) + .dateUpdated(OffsetDateTime.parse("2024-03-22T11:31:01.185Z")) + .inferencePipelineId("3fa85f64-5717-4562-b3fc-2c963f66afa6") + .projectVersionId("3fa85f64-5717-4562-b3fc-2c963f66afa6") + .status(TestListResultsResponse.LastUnskippedResult.Status.PASSING) + .statusMessage("Test successfully processed.") + .addExpectedValue( + TestListResultsResponse.LastUnskippedResult.ExpectedValue.builder() + .lowerThreshold(0.0f) + .measurement("measurement") + .upperThreshold(0.0f) + .build() + ) + .goal( + TestListResultsResponse.LastUnskippedResult.Goal.builder() + .id("3fa85f64-5717-4562-b3fc-2c963f66afa6") + .commentCount(0L) + .creatorId("589ece63-49a2-41b4-98e1-10547761d4b0") + .dateArchived(OffsetDateTime.parse("2024-03-22T11:31:01.185Z")) + .dateCreated(OffsetDateTime.parse("2024-03-22T11:31:01.185Z")) + .dateUpdated(OffsetDateTime.parse("2024-03-22T11:31:01.185Z")) + .description( + JsonValue.from( + "This test checks for duplicate rows in the dataset." + ) + ) + .name("No duplicate rows") + .number(1L) + .originProjectVersionId("3fa85f64-5717-4562-b3fc-2c963f66afa6") + .subtype( + TestListResultsResponse.LastUnskippedResult.Goal.Subtype + .DUPLICATE_ROW_COUNT + ) + .suggested(false) + .addThreshold( + TestListResultsResponse.LastUnskippedResult.Goal.Threshold + .builder() + .insightName( + TestListResultsResponse.LastUnskippedResult.Goal + .Threshold + .InsightName + .DUPLICATE_ROW_COUNT + ) + .addInsightParameter( + TestListResultsResponse.LastUnskippedResult.Goal + .Threshold + .InsightParameter + .builder() + .name("column_name") + .value(JsonValue.from("Age")) + .build() + ) + .measurement("duplicateRowCount") + .operator( + TestListResultsResponse.LastUnskippedResult.Goal + .Threshold + .Operator + .LESS_OR_EQUALS + ) + .thresholdMode( + TestListResultsResponse.LastUnskippedResult.Goal + .Threshold + .ThresholdMode + .AUTOMATIC + ) + .value(0.0) + .build() + ) + .type( + TestListResultsResponse.LastUnskippedResult.Goal.Type.INTEGRITY + ) + .archived(false) + .delayWindow(0.0) + .evaluationWindow(3600.0) + .usesMlModel(false) + .usesProductionData(false) + .usesReferenceDataset(false) + .usesTrainingDataset(false) + .usesValidationDataset(true) + .build() + ) + .goalId("3fa85f64-5717-4562-b3fc-2c963f66afa6") + .rows( + "https://api.openlayer.com/v1/versions/3fa85f64-5717-4562-b3fc-2c963f66afa6/rows?label=validation" + ) + .rowsBody( + TestListResultsResponse.LastUnskippedResult.RowsBody.builder() + .addColumnFilter( + TestListResultsResponse.LastUnskippedResult.RowsBody + .ColumnFilter + .SetColumnFilter + .builder() + .measurement("openlayer_token_set") + .operator( + TestListResultsResponse.LastUnskippedResult.RowsBody + .ColumnFilter + .SetColumnFilter + .Operator + .CONTAINS_NONE + ) + .addValue("cat") + .build() + ) + .addExcludeRowIdList(0L) + .addNotSearchQueryAnd("string") + .addNotSearchQueryOr("string") + .addRowIdList(0L) + .addSearchQueryAnd("string") + .addSearchQueryOr("string") + .build() + ) + .build() + ) + .build() + + assertThat(testListResultsResponse.items()) + .containsExactly( + TestListResultsResponse.Item.builder() + .id("3fa85f64-5717-4562-b3fc-2c963f66afa6") + .dateCreated(OffsetDateTime.parse("2024-03-22T11:31:01.185Z")) + .dateDataEnds(OffsetDateTime.parse("2024-03-22T11:31:01.185Z")) + .dateDataStarts(OffsetDateTime.parse("2024-03-22T11:31:01.185Z")) + .dateUpdated(OffsetDateTime.parse("2024-03-22T11:31:01.185Z")) + .inferencePipelineId("3fa85f64-5717-4562-b3fc-2c963f66afa6") + .projectVersionId("3fa85f64-5717-4562-b3fc-2c963f66afa6") + .status(TestListResultsResponse.Item.Status.PASSING) + .statusMessage("Test successfully processed.") + .addExpectedValue( + TestListResultsResponse.Item.ExpectedValue.builder() + .lowerThreshold(0.0f) + .measurement("measurement") + .upperThreshold(0.0f) + .build() + ) + .goal( + TestListResultsResponse.Item.Goal.builder() + .id("3fa85f64-5717-4562-b3fc-2c963f66afa6") + .commentCount(0L) + .creatorId("589ece63-49a2-41b4-98e1-10547761d4b0") + .dateArchived(OffsetDateTime.parse("2024-03-22T11:31:01.185Z")) + .dateCreated(OffsetDateTime.parse("2024-03-22T11:31:01.185Z")) + .dateUpdated(OffsetDateTime.parse("2024-03-22T11:31:01.185Z")) + .description( + JsonValue.from( + "This test checks for duplicate rows in the dataset." + ) + ) + .name("No duplicate rows") + .number(1L) + .originProjectVersionId("3fa85f64-5717-4562-b3fc-2c963f66afa6") + .subtype(TestListResultsResponse.Item.Goal.Subtype.DUPLICATE_ROW_COUNT) + .suggested(false) + .addThreshold( + TestListResultsResponse.Item.Goal.Threshold.builder() + .insightName( + TestListResultsResponse.Item.Goal.Threshold.InsightName + .DUPLICATE_ROW_COUNT + ) + .addInsightParameter( + TestListResultsResponse.Item.Goal.Threshold.InsightParameter + .builder() + .name("column_name") + .value(JsonValue.from("Age")) + .build() + ) + .measurement("duplicateRowCount") + .operator( + TestListResultsResponse.Item.Goal.Threshold.Operator + .LESS_OR_EQUALS + ) + .thresholdMode( + TestListResultsResponse.Item.Goal.Threshold.ThresholdMode + .AUTOMATIC + ) + .value(0.0) + .build() + ) + .type(TestListResultsResponse.Item.Goal.Type.INTEGRITY) + .archived(false) + .delayWindow(0.0) + .evaluationWindow(3600.0) + .usesMlModel(false) + .usesProductionData(false) + .usesReferenceDataset(false) + .usesTrainingDataset(false) + .usesValidationDataset(true) + .build() + ) + .goalId("3fa85f64-5717-4562-b3fc-2c963f66afa6") + .rows( + "https://api.openlayer.com/v1/versions/3fa85f64-5717-4562-b3fc-2c963f66afa6/rows?label=validation" + ) + .rowsBody( + TestListResultsResponse.Item.RowsBody.builder() + .addColumnFilter( + TestListResultsResponse.Item.RowsBody.ColumnFilter.SetColumnFilter + .builder() + .measurement("openlayer_token_set") + .operator( + TestListResultsResponse.Item.RowsBody.ColumnFilter + .SetColumnFilter + .Operator + .CONTAINS_NONE + ) + .addValue("cat") + .build() + ) + .addExcludeRowIdList(0L) + .addNotSearchQueryAnd("string") + .addNotSearchQueryOr("string") + .addRowIdList(0L) + .addSearchQueryAnd("string") + .addSearchQueryOr("string") + .build() + ) + .build() + ) + assertThat(testListResultsResponse.lastUnskippedResult()) + .contains( + TestListResultsResponse.LastUnskippedResult.builder() + .id("3fa85f64-5717-4562-b3fc-2c963f66afa6") + .dateCreated(OffsetDateTime.parse("2024-03-22T11:31:01.185Z")) + .dateDataEnds(OffsetDateTime.parse("2024-03-22T11:31:01.185Z")) + .dateDataStarts(OffsetDateTime.parse("2024-03-22T11:31:01.185Z")) + .dateUpdated(OffsetDateTime.parse("2024-03-22T11:31:01.185Z")) + .inferencePipelineId("3fa85f64-5717-4562-b3fc-2c963f66afa6") + .projectVersionId("3fa85f64-5717-4562-b3fc-2c963f66afa6") + .status(TestListResultsResponse.LastUnskippedResult.Status.PASSING) + .statusMessage("Test successfully processed.") + .addExpectedValue( + TestListResultsResponse.LastUnskippedResult.ExpectedValue.builder() + .lowerThreshold(0.0f) + .measurement("measurement") + .upperThreshold(0.0f) + .build() + ) + .goal( + TestListResultsResponse.LastUnskippedResult.Goal.builder() + .id("3fa85f64-5717-4562-b3fc-2c963f66afa6") + .commentCount(0L) + .creatorId("589ece63-49a2-41b4-98e1-10547761d4b0") + .dateArchived(OffsetDateTime.parse("2024-03-22T11:31:01.185Z")) + .dateCreated(OffsetDateTime.parse("2024-03-22T11:31:01.185Z")) + .dateUpdated(OffsetDateTime.parse("2024-03-22T11:31:01.185Z")) + .description( + JsonValue.from( + "This test checks for duplicate rows in the dataset." + ) + ) + .name("No duplicate rows") + .number(1L) + .originProjectVersionId("3fa85f64-5717-4562-b3fc-2c963f66afa6") + .subtype( + TestListResultsResponse.LastUnskippedResult.Goal.Subtype + .DUPLICATE_ROW_COUNT + ) + .suggested(false) + .addThreshold( + TestListResultsResponse.LastUnskippedResult.Goal.Threshold.builder() + .insightName( + TestListResultsResponse.LastUnskippedResult.Goal.Threshold + .InsightName + .DUPLICATE_ROW_COUNT + ) + .addInsightParameter( + TestListResultsResponse.LastUnskippedResult.Goal.Threshold + .InsightParameter + .builder() + .name("column_name") + .value(JsonValue.from("Age")) + .build() + ) + .measurement("duplicateRowCount") + .operator( + TestListResultsResponse.LastUnskippedResult.Goal.Threshold + .Operator + .LESS_OR_EQUALS + ) + .thresholdMode( + TestListResultsResponse.LastUnskippedResult.Goal.Threshold + .ThresholdMode + .AUTOMATIC + ) + .value(0.0) + .build() + ) + .type(TestListResultsResponse.LastUnskippedResult.Goal.Type.INTEGRITY) + .archived(false) + .delayWindow(0.0) + .evaluationWindow(3600.0) + .usesMlModel(false) + .usesProductionData(false) + .usesReferenceDataset(false) + .usesTrainingDataset(false) + .usesValidationDataset(true) + .build() + ) + .goalId("3fa85f64-5717-4562-b3fc-2c963f66afa6") + .rows( + "https://api.openlayer.com/v1/versions/3fa85f64-5717-4562-b3fc-2c963f66afa6/rows?label=validation" + ) + .rowsBody( + TestListResultsResponse.LastUnskippedResult.RowsBody.builder() + .addColumnFilter( + TestListResultsResponse.LastUnskippedResult.RowsBody.ColumnFilter + .SetColumnFilter + .builder() + .measurement("openlayer_token_set") + .operator( + TestListResultsResponse.LastUnskippedResult.RowsBody + .ColumnFilter + .SetColumnFilter + .Operator + .CONTAINS_NONE + ) + .addValue("cat") + .build() + ) + .addExcludeRowIdList(0L) + .addNotSearchQueryAnd("string") + .addNotSearchQueryOr("string") + .addRowIdList(0L) + .addSearchQueryAnd("string") + .addSearchQueryOr("string") + .build() + ) + .build() + ) + } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val testListResultsResponse = + TestListResultsResponse.builder() + .addItem( + TestListResultsResponse.Item.builder() + .id("3fa85f64-5717-4562-b3fc-2c963f66afa6") + .dateCreated(OffsetDateTime.parse("2024-03-22T11:31:01.185Z")) + .dateDataEnds(OffsetDateTime.parse("2024-03-22T11:31:01.185Z")) + .dateDataStarts(OffsetDateTime.parse("2024-03-22T11:31:01.185Z")) + .dateUpdated(OffsetDateTime.parse("2024-03-22T11:31:01.185Z")) + .inferencePipelineId("3fa85f64-5717-4562-b3fc-2c963f66afa6") + .projectVersionId("3fa85f64-5717-4562-b3fc-2c963f66afa6") + .status(TestListResultsResponse.Item.Status.PASSING) + .statusMessage("Test successfully processed.") + .addExpectedValue( + TestListResultsResponse.Item.ExpectedValue.builder() + .lowerThreshold(0.0f) + .measurement("measurement") + .upperThreshold(0.0f) + .build() + ) + .goal( + TestListResultsResponse.Item.Goal.builder() + .id("3fa85f64-5717-4562-b3fc-2c963f66afa6") + .commentCount(0L) + .creatorId("589ece63-49a2-41b4-98e1-10547761d4b0") + .dateArchived(OffsetDateTime.parse("2024-03-22T11:31:01.185Z")) + .dateCreated(OffsetDateTime.parse("2024-03-22T11:31:01.185Z")) + .dateUpdated(OffsetDateTime.parse("2024-03-22T11:31:01.185Z")) + .description( + JsonValue.from( + "This test checks for duplicate rows in the dataset." + ) + ) + .name("No duplicate rows") + .number(1L) + .originProjectVersionId("3fa85f64-5717-4562-b3fc-2c963f66afa6") + .subtype( + TestListResultsResponse.Item.Goal.Subtype.DUPLICATE_ROW_COUNT + ) + .suggested(false) + .addThreshold( + TestListResultsResponse.Item.Goal.Threshold.builder() + .insightName( + TestListResultsResponse.Item.Goal.Threshold.InsightName + .DUPLICATE_ROW_COUNT + ) + .addInsightParameter( + TestListResultsResponse.Item.Goal.Threshold + .InsightParameter + .builder() + .name("column_name") + .value(JsonValue.from("Age")) + .build() + ) + .measurement("duplicateRowCount") + .operator( + TestListResultsResponse.Item.Goal.Threshold.Operator + .LESS_OR_EQUALS + ) + .thresholdMode( + TestListResultsResponse.Item.Goal.Threshold + .ThresholdMode + .AUTOMATIC + ) + .value(0.0) + .build() + ) + .type(TestListResultsResponse.Item.Goal.Type.INTEGRITY) + .archived(false) + .delayWindow(0.0) + .evaluationWindow(3600.0) + .usesMlModel(false) + .usesProductionData(false) + .usesReferenceDataset(false) + .usesTrainingDataset(false) + .usesValidationDataset(true) + .build() + ) + .goalId("3fa85f64-5717-4562-b3fc-2c963f66afa6") + .rows( + "https://api.openlayer.com/v1/versions/3fa85f64-5717-4562-b3fc-2c963f66afa6/rows?label=validation" + ) + .rowsBody( + TestListResultsResponse.Item.RowsBody.builder() + .addColumnFilter( + TestListResultsResponse.Item.RowsBody.ColumnFilter + .SetColumnFilter + .builder() + .measurement("openlayer_token_set") + .operator( + TestListResultsResponse.Item.RowsBody.ColumnFilter + .SetColumnFilter + .Operator + .CONTAINS_NONE + ) + .addValue("cat") + .build() + ) + .addExcludeRowIdList(0L) + .addNotSearchQueryAnd("string") + .addNotSearchQueryOr("string") + .addRowIdList(0L) + .addSearchQueryAnd("string") + .addSearchQueryOr("string") + .build() + ) + .build() + ) + .lastUnskippedResult( + TestListResultsResponse.LastUnskippedResult.builder() + .id("3fa85f64-5717-4562-b3fc-2c963f66afa6") + .dateCreated(OffsetDateTime.parse("2024-03-22T11:31:01.185Z")) + .dateDataEnds(OffsetDateTime.parse("2024-03-22T11:31:01.185Z")) + .dateDataStarts(OffsetDateTime.parse("2024-03-22T11:31:01.185Z")) + .dateUpdated(OffsetDateTime.parse("2024-03-22T11:31:01.185Z")) + .inferencePipelineId("3fa85f64-5717-4562-b3fc-2c963f66afa6") + .projectVersionId("3fa85f64-5717-4562-b3fc-2c963f66afa6") + .status(TestListResultsResponse.LastUnskippedResult.Status.PASSING) + .statusMessage("Test successfully processed.") + .addExpectedValue( + TestListResultsResponse.LastUnskippedResult.ExpectedValue.builder() + .lowerThreshold(0.0f) + .measurement("measurement") + .upperThreshold(0.0f) + .build() + ) + .goal( + TestListResultsResponse.LastUnskippedResult.Goal.builder() + .id("3fa85f64-5717-4562-b3fc-2c963f66afa6") + .commentCount(0L) + .creatorId("589ece63-49a2-41b4-98e1-10547761d4b0") + .dateArchived(OffsetDateTime.parse("2024-03-22T11:31:01.185Z")) + .dateCreated(OffsetDateTime.parse("2024-03-22T11:31:01.185Z")) + .dateUpdated(OffsetDateTime.parse("2024-03-22T11:31:01.185Z")) + .description( + JsonValue.from( + "This test checks for duplicate rows in the dataset." + ) + ) + .name("No duplicate rows") + .number(1L) + .originProjectVersionId("3fa85f64-5717-4562-b3fc-2c963f66afa6") + .subtype( + TestListResultsResponse.LastUnskippedResult.Goal.Subtype + .DUPLICATE_ROW_COUNT + ) + .suggested(false) + .addThreshold( + TestListResultsResponse.LastUnskippedResult.Goal.Threshold + .builder() + .insightName( + TestListResultsResponse.LastUnskippedResult.Goal + .Threshold + .InsightName + .DUPLICATE_ROW_COUNT + ) + .addInsightParameter( + TestListResultsResponse.LastUnskippedResult.Goal + .Threshold + .InsightParameter + .builder() + .name("column_name") + .value(JsonValue.from("Age")) + .build() + ) + .measurement("duplicateRowCount") + .operator( + TestListResultsResponse.LastUnskippedResult.Goal + .Threshold + .Operator + .LESS_OR_EQUALS + ) + .thresholdMode( + TestListResultsResponse.LastUnskippedResult.Goal + .Threshold + .ThresholdMode + .AUTOMATIC + ) + .value(0.0) + .build() + ) + .type( + TestListResultsResponse.LastUnskippedResult.Goal.Type.INTEGRITY + ) + .archived(false) + .delayWindow(0.0) + .evaluationWindow(3600.0) + .usesMlModel(false) + .usesProductionData(false) + .usesReferenceDataset(false) + .usesTrainingDataset(false) + .usesValidationDataset(true) + .build() + ) + .goalId("3fa85f64-5717-4562-b3fc-2c963f66afa6") + .rows( + "https://api.openlayer.com/v1/versions/3fa85f64-5717-4562-b3fc-2c963f66afa6/rows?label=validation" + ) + .rowsBody( + TestListResultsResponse.LastUnskippedResult.RowsBody.builder() + .addColumnFilter( + TestListResultsResponse.LastUnskippedResult.RowsBody + .ColumnFilter + .SetColumnFilter + .builder() + .measurement("openlayer_token_set") + .operator( + TestListResultsResponse.LastUnskippedResult.RowsBody + .ColumnFilter + .SetColumnFilter + .Operator + .CONTAINS_NONE + ) + .addValue("cat") + .build() + ) + .addExcludeRowIdList(0L) + .addNotSearchQueryAnd("string") + .addNotSearchQueryOr("string") + .addRowIdList(0L) + .addSearchQueryAnd("string") + .addSearchQueryOr("string") + .build() + ) + .build() + ) + .build() + + val roundtrippedTestListResultsResponse = + jsonMapper.readValue( + jsonMapper.writeValueAsString(testListResultsResponse), + jacksonTypeRef(), + ) + + assertThat(roundtrippedTestListResultsResponse).isEqualTo(testListResultsResponse) + } +} diff --git a/openlayer-java-core/src/test/kotlin/com/openlayer/api/services/async/TestServiceAsyncTest.kt b/openlayer-java-core/src/test/kotlin/com/openlayer/api/services/async/TestServiceAsyncTest.kt index c356db44..2c97a8ab 100644 --- a/openlayer-java-core/src/test/kotlin/com/openlayer/api/services/async/TestServiceAsyncTest.kt +++ b/openlayer-java-core/src/test/kotlin/com/openlayer/api/services/async/TestServiceAsyncTest.kt @@ -5,6 +5,7 @@ package com.openlayer.api.services.async import com.openlayer.api.TestServerExtension import com.openlayer.api.client.okhttp.OpenlayerOkHttpClientAsync import com.openlayer.api.models.tests.TestEvaluateParams +import com.openlayer.api.models.tests.TestListResultsParams import org.junit.jupiter.api.Test import org.junit.jupiter.api.extension.ExtendWith @@ -34,4 +35,32 @@ internal class TestServiceAsyncTest { val response = responseFuture.get() response.validate() } + + @Test + fun listResults() { + val client = + OpenlayerOkHttpClientAsync.builder() + .baseUrl(TestServerExtension.BASE_URL) + .apiKey("My API Key") + .build() + val testServiceAsync = client.tests() + + val responseFuture = + testServiceAsync.listResults( + TestListResultsParams.builder() + .testId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .endTimestamp(0.0) + .includeInsights(true) + .inferencePipelineId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .page(1L) + .perPage(1L) + .projectVersionId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .startTimestamp(0.0) + .addStatus("string") + .build() + ) + + val response = responseFuture.get() + response.validate() + } } diff --git a/openlayer-java-core/src/test/kotlin/com/openlayer/api/services/blocking/TestServiceTest.kt b/openlayer-java-core/src/test/kotlin/com/openlayer/api/services/blocking/TestServiceTest.kt index 548f8927..64880d19 100644 --- a/openlayer-java-core/src/test/kotlin/com/openlayer/api/services/blocking/TestServiceTest.kt +++ b/openlayer-java-core/src/test/kotlin/com/openlayer/api/services/blocking/TestServiceTest.kt @@ -5,6 +5,7 @@ package com.openlayer.api.services.blocking import com.openlayer.api.TestServerExtension import com.openlayer.api.client.okhttp.OpenlayerOkHttpClient import com.openlayer.api.models.tests.TestEvaluateParams +import com.openlayer.api.models.tests.TestListResultsParams import org.junit.jupiter.api.Test import org.junit.jupiter.api.extension.ExtendWith @@ -33,4 +34,31 @@ internal class TestServiceTest { response.validate() } + + @Test + fun listResults() { + val client = + OpenlayerOkHttpClient.builder() + .baseUrl(TestServerExtension.BASE_URL) + .apiKey("My API Key") + .build() + val testService = client.tests() + + val response = + testService.listResults( + TestListResultsParams.builder() + .testId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .endTimestamp(0.0) + .includeInsights(true) + .inferencePipelineId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .page(1L) + .perPage(1L) + .projectVersionId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .startTimestamp(0.0) + .addStatus("string") + .build() + ) + + response.validate() + } } From fb20f3b3ffc4b5aec1498e776100202e5623df25 Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Fri, 9 Jan 2026 13:26:27 +0000 Subject: [PATCH 2/2] release: 0.3.0 --- .release-please-manifest.json | 2 +- CHANGELOG.md | 8 ++++++++ README.md | 10 +++++----- build.gradle.kts | 2 +- 4 files changed, 15 insertions(+), 7 deletions(-) diff --git a/.release-please-manifest.json b/.release-please-manifest.json index 10f30916..6b7b74c5 100644 --- a/.release-please-manifest.json +++ b/.release-please-manifest.json @@ -1,3 +1,3 @@ { - ".": "0.2.0" + ".": "0.3.0" } \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md index cce19b3d..ff466380 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,13 @@ # Changelog +## 0.3.0 (2026-01-09) + +Full Changelog: [v0.2.0...v0.3.0](https://github.com/openlayer-ai/openlayer-java/compare/v0.2.0...v0.3.0) + +### Features + +* **closes OPEN-8532:** expose 'tests/{id}/results' endpoint ([8815922](https://github.com/openlayer-ai/openlayer-java/commit/88159223fd10a427d7bfabe640439c1cebea4cc3)) + ## 0.2.0 (2026-01-09) Full Changelog: [v0.1.1...v0.2.0](https://github.com/openlayer-ai/openlayer-java/compare/v0.1.1...v0.2.0) diff --git a/README.md b/README.md index a3129d89..0bc9b920 100644 --- a/README.md +++ b/README.md @@ -2,8 +2,8 @@ -[![Maven Central](https://img.shields.io/maven-central/v/com.openlayer.api/openlayer-java)](https://central.sonatype.com/artifact/com.openlayer.api/openlayer-java/0.2.0) -[![javadoc](https://javadoc.io/badge2/com.openlayer.api/openlayer-java/0.2.0/javadoc.svg)](https://javadoc.io/doc/com.openlayer.api/openlayer-java/0.2.0) +[![Maven Central](https://img.shields.io/maven-central/v/com.openlayer.api/openlayer-java)](https://central.sonatype.com/artifact/com.openlayer.api/openlayer-java/0.3.0) +[![javadoc](https://javadoc.io/badge2/com.openlayer.api/openlayer-java/0.3.0/javadoc.svg)](https://javadoc.io/doc/com.openlayer.api/openlayer-java/0.3.0) @@ -13,7 +13,7 @@ It is generated with [Stainless](https://www.stainless.com/). -The REST API documentation can be found on [openlayer.com](https://openlayer.com/docs/api-reference/rest/overview). Javadocs are available on [javadoc.io](https://javadoc.io/doc/com.openlayer.api/openlayer-java/0.2.0). +The REST API documentation can be found on [openlayer.com](https://openlayer.com/docs/api-reference/rest/overview). Javadocs are available on [javadoc.io](https://javadoc.io/doc/com.openlayer.api/openlayer-java/0.3.0). @@ -24,7 +24,7 @@ The REST API documentation can be found on [openlayer.com](https://openlayer.com ### Gradle ```kotlin -implementation("com.openlayer.api:openlayer-java:0.2.0") +implementation("com.openlayer.api:openlayer-java:0.3.0") ``` ### Maven @@ -33,7 +33,7 @@ implementation("com.openlayer.api:openlayer-java:0.2.0") com.openlayer.api openlayer-java - 0.2.0 + 0.3.0 ``` diff --git a/build.gradle.kts b/build.gradle.kts index d440efd6..d977354f 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -8,7 +8,7 @@ repositories { allprojects { group = "com.openlayer.api" - version = "0.2.0" // x-release-please-version + version = "0.3.0" // x-release-please-version } subprojects {