Skip to content
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
2 changes: 1 addition & 1 deletion .stats.yml
Original file line number Diff line number Diff line change
@@ -1 +1 @@
configured_endpoints: 58
configured_endpoints: 63
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,18 @@ import com.openlayer.api.core.Params
import com.openlayer.api.core.http.Headers
import com.openlayer.api.core.http.QueryParams
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

/** Create a new API key in a workspace. */
/**
* Create a new API key in a workspace. The full secret is returned in `secret`, only in this
* response. Optionally set `expiresAt`. When you authenticate with an API key that expires, the new
* key can't outlive it: omit `expiresAt` to inherit that expiry, and a later expiry (or `null`) is
* rejected with 400.
*/
class ApiKeyCreateParams
private constructor(
private val workspaceId: String?,
Expand All @@ -30,6 +36,16 @@ private constructor(

fun workspaceId(): Optional<String> = Optional.ofNullable(workspaceId)

/**
* When the key stops authenticating. `null` means the key never expires. Set when the key is
* created or rotated, and must be in the future. When the request is authenticated with an API
* key that expires, the result can't be later than that key's expiry.
*
* @throws OpenlayerInvalidDataException if the JSON field has an unexpected type (e.g. if the
* server responded with an unexpected value).
*/
fun expiresAt(): Optional<OffsetDateTime> = body.expiresAt()

/**
* The API key name.
*
Expand All @@ -38,6 +54,13 @@ private constructor(
*/
fun name(): Optional<String> = body.name()

/**
* Returns the raw JSON value of [expiresAt].
*
* Unlike [expiresAt], this method doesn't throw if the JSON field has an unexpected type.
*/
fun _expiresAt(): JsonField<OffsetDateTime> = body._expiresAt()

/**
* Returns the raw JSON value of [name].
*
Expand Down Expand Up @@ -89,10 +112,30 @@ private constructor(
*
* This is generally only useful if you are already constructing the body separately.
* Otherwise, it's more convenient to use the top-level setters instead:
* - [expiresAt]
* - [name]
*/
fun body(body: Body) = apply { this.body = body.toBuilder() }

/**
* When the key stops authenticating. `null` means the key never expires. Set when the key
* is created or rotated, and must be in the future. When the request is authenticated with
* an API key that expires, the result can't be later than that key's expiry.
*/
fun expiresAt(expiresAt: OffsetDateTime?) = apply { body.expiresAt(expiresAt) }

/** Alias for calling [Builder.expiresAt] with `expiresAt.orElse(null)`. */
fun expiresAt(expiresAt: Optional<OffsetDateTime>) = expiresAt(expiresAt.getOrNull())

/**
* Sets [Builder.expiresAt] to an arbitrary JSON value.
*
* You should usually call [Builder.expiresAt] with a well-typed [OffsetDateTime] value
* instead. This method is primarily for setting the field to an undocumented or not yet
* supported value.
*/
fun expiresAt(expiresAt: JsonField<OffsetDateTime>) = apply { body.expiresAt(expiresAt) }

/** The API key name. */
fun name(name: String?) = apply { body.name(name) }

Expand Down Expand Up @@ -253,14 +296,28 @@ private constructor(
class Body
@JsonCreator(mode = JsonCreator.Mode.DISABLED)
private constructor(
private val expiresAt: JsonField<OffsetDateTime>,
private val name: JsonField<String>,
private val additionalProperties: MutableMap<String, JsonValue>,
) {

@JsonCreator
private constructor(
@JsonProperty("name") @ExcludeMissing name: JsonField<String> = JsonMissing.of()
) : this(name, mutableMapOf())
@JsonProperty("expiresAt")
@ExcludeMissing
expiresAt: JsonField<OffsetDateTime> = JsonMissing.of(),
@JsonProperty("name") @ExcludeMissing name: JsonField<String> = JsonMissing.of(),
) : this(expiresAt, name, mutableMapOf())

/**
* When the key stops authenticating. `null` means the key never expires. Set when the key
* is created or rotated, and must be in the future. When the request is authenticated with
* an API key that expires, the result can't be later than that key's expiry.
*
* @throws OpenlayerInvalidDataException if the JSON field has an unexpected type (e.g. if
* the server responded with an unexpected value).
*/
fun expiresAt(): Optional<OffsetDateTime> = expiresAt.getOptional("expiresAt")

/**
* The API key name.
Expand All @@ -270,6 +327,15 @@ private constructor(
*/
fun name(): Optional<String> = name.getOptional("name")

/**
* Returns the raw JSON value of [expiresAt].
*
* Unlike [expiresAt], this method doesn't throw if the JSON field has an unexpected type.
*/
@JsonProperty("expiresAt")
@ExcludeMissing
fun _expiresAt(): JsonField<OffsetDateTime> = expiresAt

/**
* Returns the raw JSON value of [name].
*
Expand Down Expand Up @@ -298,15 +364,39 @@ private constructor(
/** A builder for [Body]. */
class Builder internal constructor() {

private var expiresAt: JsonField<OffsetDateTime> = JsonMissing.of()
private var name: JsonField<String> = JsonMissing.of()
private var additionalProperties: MutableMap<String, JsonValue> = mutableMapOf()

@JvmSynthetic
internal fun from(body: Body) = apply {
expiresAt = body.expiresAt
name = body.name
additionalProperties = body.additionalProperties.toMutableMap()
}

/**
* When the key stops authenticating. `null` means the key never expires. Set when the
* key is created or rotated, and must be in the future. When the request is
* authenticated with an API key that expires, the result can't be later than that key's
* expiry.
*/
fun expiresAt(expiresAt: OffsetDateTime?) = expiresAt(JsonField.ofNullable(expiresAt))

/** Alias for calling [Builder.expiresAt] with `expiresAt.orElse(null)`. */
fun expiresAt(expiresAt: Optional<OffsetDateTime>) = expiresAt(expiresAt.getOrNull())

/**
* Sets [Builder.expiresAt] to an arbitrary JSON value.
*
* You should usually call [Builder.expiresAt] with a well-typed [OffsetDateTime] value
* instead. This method is primarily for setting the field to an undocumented or not yet
* supported value.
*/
fun expiresAt(expiresAt: JsonField<OffsetDateTime>) = apply {
this.expiresAt = expiresAt
}

/** The API key name. */
fun name(name: String?) = name(JsonField.ofNullable(name))

Expand Down Expand Up @@ -346,7 +436,7 @@ private constructor(
*
* Further updates to this [Builder] will not mutate the returned instance.
*/
fun build(): Body = Body(name, additionalProperties.toMutableMap())
fun build(): Body = Body(expiresAt, name, additionalProperties.toMutableMap())
}

private var validated: Boolean = false
Expand All @@ -365,6 +455,7 @@ private constructor(
return@apply
}

expiresAt()
name()
validated = true
}
Expand All @@ -383,23 +474,27 @@ private constructor(
*
* Used for best match union deserialization.
*/
@JvmSynthetic internal fun validity(): Int = (if (name.asKnown().isPresent) 1 else 0)
@JvmSynthetic
internal fun validity(): Int =
(if (expiresAt.asKnown().isPresent) 1 else 0) + (if (name.asKnown().isPresent) 1 else 0)

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

return other is Body &&
expiresAt == other.expiresAt &&
name == other.name &&
additionalProperties == other.additionalProperties
}

private val hashCode: Int by lazy { Objects.hash(name, additionalProperties) }
private val hashCode: Int by lazy { Objects.hash(expiresAt, name, additionalProperties) }

override fun hashCode(): Int = hashCode

override fun toString() = "Body{name=$name, additionalProperties=$additionalProperties}"
override fun toString() =
"Body{expiresAt=$expiresAt, name=$name, additionalProperties=$additionalProperties}"
}

override fun equals(other: Any?): Boolean {
Expand Down
Loading
Loading