Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(api): api update #68

Merged
merged 1 commit into from
Dec 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,42 @@

package com.openlayer.api.models

import com.fasterxml.jackson.annotation.JsonCreator
import com.openlayer.api.core.Enum
import com.openlayer.api.core.JsonField
import com.openlayer.api.core.NoAutoDetect
import com.openlayer.api.core.http.Headers
import com.openlayer.api.core.http.QueryParams
import com.openlayer.api.core.toImmutable
import com.openlayer.api.errors.OpenlayerInvalidDataException
import java.util.Objects
import java.util.Optional

class InferencePipelineRetrieveParams
constructor(
private val inferencePipelineId: String,
private val expand: List<Expand>?,
private val additionalHeaders: Headers,
private val additionalQueryParams: QueryParams,
) {

fun inferencePipelineId(): String = inferencePipelineId

fun expand(): Optional<List<Expand>> = Optional.ofNullable(expand)

fun _additionalHeaders(): Headers = additionalHeaders

fun _additionalQueryParams(): QueryParams = additionalQueryParams

@JvmSynthetic internal fun getHeaders(): Headers = additionalHeaders

@JvmSynthetic internal fun getQueryParams(): QueryParams = additionalQueryParams
@JvmSynthetic
internal fun getQueryParams(): QueryParams {
val queryParams = QueryParams.builder()
this.expand?.let { queryParams.put("expand", listOf(it.joinToString(separator = ","))) }
queryParams.putAll(additionalQueryParams)
return queryParams.build()
}

fun getPathParam(index: Int): String {
return when (index) {
Expand All @@ -42,13 +57,15 @@ constructor(
class Builder {

private var inferencePipelineId: String? = null
private var expand: MutableList<Expand> = mutableListOf()
private var additionalHeaders: Headers.Builder = Headers.builder()
private var additionalQueryParams: QueryParams.Builder = QueryParams.builder()

@JvmSynthetic
internal fun from(inferencePipelineRetrieveParams: InferencePipelineRetrieveParams) =
apply {
inferencePipelineId = inferencePipelineRetrieveParams.inferencePipelineId
expand = inferencePipelineRetrieveParams.expand?.toMutableList() ?: mutableListOf()
additionalHeaders = inferencePipelineRetrieveParams.additionalHeaders.toBuilder()
additionalQueryParams =
inferencePipelineRetrieveParams.additionalQueryParams.toBuilder()
Expand All @@ -58,6 +75,15 @@ constructor(
this.inferencePipelineId = inferencePipelineId
}

/** Expand specific nested objects. */
fun expand(expand: List<Expand>) = apply {
this.expand.clear()
this.expand.addAll(expand)
}

/** Expand specific nested objects. */
fun addExpand(expand: Expand) = apply { this.expand.add(expand) }

fun additionalHeaders(additionalHeaders: Headers) = apply {
this.additionalHeaders.clear()
putAllAdditionalHeaders(additionalHeaders)
Expand Down Expand Up @@ -161,21 +187,79 @@ constructor(
checkNotNull(inferencePipelineId) {
"`inferencePipelineId` is required but was not set"
},
expand.toImmutable().ifEmpty { null },
additionalHeaders.build(),
additionalQueryParams.build(),
)
}

class Expand
@JsonCreator
private constructor(
private val value: JsonField<String>,
) : Enum {

@com.fasterxml.jackson.annotation.JsonValue fun _value(): JsonField<String> = value

companion object {

@JvmField val PROJECT = of("project")

@JvmField val WORKSPACE = of("workspace")

@JvmStatic fun of(value: String) = Expand(JsonField.of(value))
}

enum class Known {
PROJECT,
WORKSPACE,
}

enum class Value {
PROJECT,
WORKSPACE,
_UNKNOWN,
}

fun value(): Value =
when (this) {
PROJECT -> Value.PROJECT
WORKSPACE -> Value.WORKSPACE
else -> Value._UNKNOWN
}

fun known(): Known =
when (this) {
PROJECT -> Known.PROJECT
WORKSPACE -> Known.WORKSPACE
else -> throw OpenlayerInvalidDataException("Unknown Expand: $value")
}

fun asString(): String = _value().asStringOrThrow()

override fun equals(other: Any?): Boolean {
if (this === other) {
return true
}

return /* spotless:off */ other is Expand && value == other.value /* spotless:on */
}

override fun hashCode() = value.hashCode()

override fun toString() = value.toString()
}

override fun equals(other: Any?): Boolean {
if (this === other) {
return true
}

return /* spotless:off */ other is InferencePipelineRetrieveParams && inferencePipelineId == other.inferencePipelineId && additionalHeaders == other.additionalHeaders && additionalQueryParams == other.additionalQueryParams /* spotless:on */
return /* spotless:off */ other is InferencePipelineRetrieveParams && inferencePipelineId == other.inferencePipelineId && expand == other.expand && additionalHeaders == other.additionalHeaders && additionalQueryParams == other.additionalQueryParams /* spotless:on */
}

override fun hashCode(): Int = /* spotless:off */ Objects.hash(inferencePipelineId, additionalHeaders, additionalQueryParams) /* spotless:on */
override fun hashCode(): Int = /* spotless:off */ Objects.hash(inferencePipelineId, expand, additionalHeaders, additionalQueryParams) /* spotless:on */

override fun toString() =
"InferencePipelineRetrieveParams{inferencePipelineId=$inferencePipelineId, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}"
"InferencePipelineRetrieveParams{inferencePipelineId=$inferencePipelineId, expand=$expand, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}"
}
Loading