value is only ever present in the create response (confirmed live — apiKeys.list never includes it), so the model and call sites treat it as a one-time reveal, not persisted state. expiresAt omitted (not null) for a non-expiring key, matches synthesized Encodable's default encodeIfPresent behavior.
22 lines
919 B
Swift
22 lines
919 B
Swift
import Foundation
|
|
|
|
/// `apiKeys.create`. `expiresAt: nil` (the key omitted entirely, not sent as
|
|
/// literal `null`) confirmed live to mean no expiration — Swift's
|
|
/// synthesized `Encodable` already omits `nil` optionals via
|
|
/// `encodeIfPresent`, so no custom `encode(to:)` is needed here the way
|
|
/// `UpdateUserAvatarRequest` needed one for the opposite case.
|
|
public struct CreateApiKeyRequest: Encodable, Sendable {
|
|
public let name: String
|
|
public let expiresAt: Date?
|
|
/// `nil`/omitted grants full access — confirmed live (every key created
|
|
/// without a scope came back with unrestricted access). A specific
|
|
/// scope is a list of allowed API paths, e.g. `["/api/documents.info"]`.
|
|
public let scope: [String]?
|
|
|
|
public init(name: String, expiresAt: Date? = nil, scope: [String]? = nil) {
|
|
self.name = name
|
|
self.expiresAt = expiresAt
|
|
self.scope = scope
|
|
}
|
|
}
|