Files
VerseVDI-Protocol/gen/swift/Protocol.swift
T

3666 lines
238 KiB
Swift

// Code generated by tools/generate.py; DO NOT EDIT.
import Foundation
public typealias JSONObject = [String: String]
public let schemaSHA256 = "8c1ed430127cf5774a919f14ff4770b2509d322c8518bf30c412e1e89eeffced"
public let currentWireVersion = "2"
public let nMinus1WireVersion = "1"
public let nMinus2WireVersion = "0"
public struct ContractValidationError: Error, Equatable { public let field: String; public let code: String }
private struct AnyCodingKey: CodingKey { let stringValue: String; let intValue: Int?; init?(stringValue: String) { self.stringValue = stringValue; self.intValue = nil }; init?(intValue: Int) { self.stringValue = String(intValue); self.intValue = intValue } }
private func rejectDuplicateJSONKeys(_ data: Data) throws {
guard data.count <= 1_048_576 else { throw ContractValidationError(field: "json", code: "payload_too_large") }
var index = 0
func skipWhitespace() { while index < data.count && [9, 10, 13, 32].contains(data[index]) { index += 1 } }
func parseString() throws -> String {
guard index < data.count, data[index] == 34 else { throw ContractValidationError(field: "json", code: "invalid_json") }
let start = index
index += 1
while index < data.count {
if data[index] == 92 { index += 2; continue }
if data[index] == 34 { index += 1; return try JSONDecoder().decode(String.self, from: data[start..<index]) }
index += 1
}
throw ContractValidationError(field: "json", code: "invalid_json")
}
func parseValue(_ depth: Int) throws {
guard depth <= 64 else { throw ContractValidationError(field: "json", code: "nesting_too_deep") }
skipWhitespace()
guard index < data.count else { throw ContractValidationError(field: "json", code: "invalid_json") }
if data[index] == 123 {
index += 1
var keys = Set<String>()
skipWhitespace()
if index < data.count, data[index] == 125 { index += 1; return }
while true {
skipWhitespace()
let key = try parseString()
guard keys.insert(key).inserted else { throw ContractValidationError(field: key, code: "duplicate_field") }
skipWhitespace()
guard index < data.count, data[index] == 58 else { throw ContractValidationError(field: "json", code: "invalid_json") }
index += 1
try parseValue(depth + 1)
skipWhitespace()
guard index < data.count else { throw ContractValidationError(field: "json", code: "invalid_json") }
if data[index] == 125 { index += 1; return }
guard data[index] == 44 else { throw ContractValidationError(field: "json", code: "invalid_json") }
index += 1
}
}
if data[index] == 91 {
index += 1
skipWhitespace()
if index < data.count, data[index] == 93 { index += 1; return }
while true {
try parseValue(depth + 1)
skipWhitespace()
guard index < data.count else { throw ContractValidationError(field: "json", code: "invalid_json") }
if data[index] == 93 { index += 1; return }
guard data[index] == 44 else { throw ContractValidationError(field: "json", code: "invalid_json") }
index += 1
}
}
if data[index] == 34 { _ = try parseString(); return }
let start = index
while index < data.count && ![9, 10, 13, 32, 44, 93, 125].contains(data[index]) { index += 1 }
guard index > start else { throw ContractValidationError(field: "json", code: "invalid_json") }
}
try parseValue(0)
skipWhitespace()
guard index == data.count else { throw ContractValidationError(field: "json", code: "trailing_json") }
}
private func validBase64URL(_ value: String) -> Bool {
guard !value.isEmpty, value.utf8.allSatisfy({ byte in
(byte >= 65 && byte <= 90) || (byte >= 97 && byte <= 122) || (byte >= 48 && byte <= 57) || byte == 45 || byte == 95
}) else { return false }
let padding = String(repeating: "=", count: (4 - value.utf8.count % 4) % 4)
let standard = value.replacingOccurrences(of: "-", with: "+").replacingOccurrences(of: "_", with: "/") + padding
guard let decoded = Data(base64Encoded: standard) else { return false }
return decoded.base64EncodedString().replacingOccurrences(of: "+", with: "-").replacingOccurrences(of: "/", with: "_").replacingOccurrences(of: "=", with: "") == value
}
private func validRFC3339UTC(_ value: String) -> Bool {
let bytes = Array(value.utf8)
guard (20...30).contains(bytes.count), bytes[4] == 45, bytes[7] == 45, bytes[10] == 84, bytes[13] == 58, bytes[16] == 58, bytes.last == 90 else { return false }
func digits(_ range: Range<Int>) -> Int? {
var result = 0
for index in range { guard bytes[index] >= 48 && bytes[index] <= 57 else { return nil }; result = result * 10 + Int(bytes[index] - 48) }
return result
}
guard let year = digits(0..<4), let month = digits(5..<7), let day = digits(8..<10), let hour = digits(11..<13), let minute = digits(14..<16), let second = digits(17..<19), hour <= 23, minute <= 59, second <= 59 else { return false }
let leap = year % 4 == 0 && (year % 100 != 0 || year % 400 == 0)
let days: Int
switch month { case 1, 3, 5, 7, 8, 10, 12: days = 31; case 4, 6, 9, 11: days = 30; case 2: days = leap ? 29 : 28; default: return false }
guard day > 0 && day <= days else { return false }
if bytes.count == 20 { return true }
let fraction = bytes[20..<(bytes.count - 1)]
return bytes[19] == 46 && !fraction.isEmpty && fraction.count <= 9 && fraction.allSatisfy { $0 >= 48 && $0 <= 57 } && fraction.last != 48
}
private func validCanonicalUUID(_ value: String) -> Bool {
let bytes = Array(value.utf8)
guard bytes.count == 36, bytes[8] == 45, bytes[13] == 45, bytes[18] == 45, bytes[23] == 45, value != "00000000-0000-0000-0000-000000000000" else { return false }
return bytes.enumerated().allSatisfy { index, byte in [8, 13, 18, 23].contains(index) || (byte >= 48 && byte <= 57) || (byte >= 97 && byte <= 102) }
}
public struct AllocationPolicy: Codable, Equatable {
public let minimumKbps: Int64
public let targetKbps: Int64
public let maximumKbps: Int64
public let tier: String
public let audience: String
public let protocolValue: String
public let protocolVersion: Int64
public let grantTtlSeconds: Int64
public let reservationLeaseSeconds: Int64
enum CodingKeys: String, CodingKey {
case minimumKbps = "minimum_kbps"
case targetKbps = "target_kbps"
case maximumKbps = "maximum_kbps"
case tier = "tier"
case audience = "audience"
case protocolValue = "protocol"
case protocolVersion = "protocol_version"
case grantTtlSeconds = "grant_ttl_seconds"
case reservationLeaseSeconds = "reservation_lease_seconds"
}
public init(minimumKbps: Int64, targetKbps: Int64, maximumKbps: Int64, tier: String, audience: String, protocolValue: String, protocolVersion: Int64, grantTtlSeconds: Int64, reservationLeaseSeconds: Int64) throws {
self.minimumKbps = minimumKbps
self.targetKbps = targetKbps
self.maximumKbps = maximumKbps
self.tier = tier
self.audience = audience
self.protocolValue = protocolValue
self.protocolVersion = protocolVersion
self.grantTtlSeconds = grantTtlSeconds
self.reservationLeaseSeconds = reservationLeaseSeconds
try validate()
}
public init(from decoder: Decoder) throws {
let all = try decoder.container(keyedBy: AnyCodingKey.self)
for key in all.allKeys where CodingKeys(stringValue: key.stringValue) == nil { throw ContractValidationError(field: key.stringValue, code: "unknown_field") }
let c = try decoder.container(keyedBy: CodingKeys.self)
try self.init(minimumKbps: try c.decode(Int64.self, forKey: .minimumKbps), targetKbps: try c.decode(Int64.self, forKey: .targetKbps), maximumKbps: try c.decode(Int64.self, forKey: .maximumKbps), tier: try c.decode(String.self, forKey: .tier), audience: try c.decode(String.self, forKey: .audience), protocolValue: try c.decode(String.self, forKey: .protocolValue), protocolVersion: try c.decode(Int64.self, forKey: .protocolVersion), grantTtlSeconds: try c.decode(Int64.self, forKey: .grantTtlSeconds), reservationLeaseSeconds: try c.decode(Int64.self, forKey: .reservationLeaseSeconds))
}
public func validate() throws {
if self.minimumKbps < 1 { throw ContractValidationError(field: "minimum_kbps", code: "minimum") }
if self.minimumKbps > 100000000 { throw ContractValidationError(field: "minimum_kbps", code: "maximum") }
if self.targetKbps < 1 { throw ContractValidationError(field: "target_kbps", code: "minimum") }
if self.targetKbps > 100000000 { throw ContractValidationError(field: "target_kbps", code: "maximum") }
if self.maximumKbps < 1 { throw ContractValidationError(field: "maximum_kbps", code: "minimum") }
if self.maximumKbps > 100000000 { throw ContractValidationError(field: "maximum_kbps", code: "maximum") }
if !["standard", "priority", "premium"].contains(self.tier) { throw ContractValidationError(field: "tier", code: "invalid_value") }
if self.audience.isEmpty { throw ContractValidationError(field: "audience", code: "required") }
if !self.audience.isEmpty && self.audience.utf8.count < 1 { throw ContractValidationError(field: "audience", code: "min_length") }
if self.audience.utf8.count > 256 { throw ContractValidationError(field: "audience", code: "max_length") }
if self.protocolValue.isEmpty { throw ContractValidationError(field: "protocol", code: "required") }
if !self.protocolValue.isEmpty && self.protocolValue.utf8.count < 1 { throw ContractValidationError(field: "protocol", code: "min_length") }
if self.protocolValue.utf8.count > 64 { throw ContractValidationError(field: "protocol", code: "max_length") }
if self.protocolVersion < 1 { throw ContractValidationError(field: "protocol_version", code: "minimum") }
if self.protocolVersion > 100 { throw ContractValidationError(field: "protocol_version", code: "maximum") }
if self.grantTtlSeconds < 5 { throw ContractValidationError(field: "grant_ttl_seconds", code: "minimum") }
if self.grantTtlSeconds > 300 { throw ContractValidationError(field: "grant_ttl_seconds", code: "maximum") }
if self.reservationLeaseSeconds < 5 { throw ContractValidationError(field: "reservation_lease_seconds", code: "minimum") }
if self.reservationLeaseSeconds > 3600 { throw ContractValidationError(field: "reservation_lease_seconds", code: "maximum") }
if minimumKbps > targetKbps || targetKbps > maximumKbps { throw ContractValidationError(field: "bounds", code: "invalid_order") }
}
public static func decodeJSON(_ data: Data) throws -> Self { try rejectDuplicateJSONKeys(data); return try JSONDecoder().decode(Self.self, from: data) }
public func encodeJSON() throws -> Data { try validate(); return try JSONEncoder().encode(self) }
}
public struct AssignedDesktop: Codable, Equatable {
public let assignmentId: String
public let poolId: String
public let name: String
public let availability: String
public let qualityLimits: SessionQualityLimits
enum CodingKeys: String, CodingKey {
case assignmentId = "assignment_id"
case poolId = "pool_id"
case name = "name"
case availability = "availability"
case qualityLimits = "quality_limits"
}
public init(assignmentId: String, poolId: String, name: String, availability: String, qualityLimits: SessionQualityLimits) throws {
self.assignmentId = assignmentId
self.poolId = poolId
self.name = name
self.availability = availability
self.qualityLimits = qualityLimits
try validate()
}
public init(from decoder: Decoder) throws {
let all = try decoder.container(keyedBy: AnyCodingKey.self)
for key in all.allKeys where CodingKeys(stringValue: key.stringValue) == nil { throw ContractValidationError(field: key.stringValue, code: "unknown_field") }
let c = try decoder.container(keyedBy: CodingKeys.self)
try self.init(assignmentId: try c.decode(String.self, forKey: .assignmentId), poolId: try c.decode(String.self, forKey: .poolId), name: try c.decode(String.self, forKey: .name), availability: try c.decode(String.self, forKey: .availability), qualityLimits: try c.decode(SessionQualityLimits.self, forKey: .qualityLimits))
}
public func validate() throws {
if self.assignmentId.isEmpty { throw ContractValidationError(field: "assignment_id", code: "required") }
if !self.assignmentId.isEmpty && self.assignmentId.utf8.count < 1 { throw ContractValidationError(field: "assignment_id", code: "min_length") }
if self.assignmentId.utf8.count > 128 { throw ContractValidationError(field: "assignment_id", code: "max_length") }
if self.poolId.isEmpty { throw ContractValidationError(field: "pool_id", code: "required") }
if !self.poolId.isEmpty && self.poolId.utf8.count < 1 { throw ContractValidationError(field: "pool_id", code: "min_length") }
if self.poolId.utf8.count > 128 { throw ContractValidationError(field: "pool_id", code: "max_length") }
if self.name.isEmpty { throw ContractValidationError(field: "name", code: "required") }
if !self.name.isEmpty && self.name.utf8.count < 1 { throw ContractValidationError(field: "name", code: "min_length") }
if self.name.utf8.count > 256 { throw ContractValidationError(field: "name", code: "max_length") }
if self.availability.isEmpty { throw ContractValidationError(field: "availability", code: "required") }
if !self.availability.isEmpty && self.availability.utf8.count < 1 { throw ContractValidationError(field: "availability", code: "min_length") }
if self.availability.utf8.count > 64 { throw ContractValidationError(field: "availability", code: "max_length") }
try self.qualityLimits.validate()
}
public static func decodeJSON(_ data: Data) throws -> Self { try rejectDuplicateJSONKeys(data); return try JSONDecoder().decode(Self.self, from: data) }
public func encodeJSON() throws -> Data { try validate(); return try JSONEncoder().encode(self) }
}
public struct AudioProfile: Codable, Equatable {
public let codec: String
public let sampleRateHz: Int64
public let channels: Int64
public let channelLayout: String
public let packetDurationMs: Int64
enum CodingKeys: String, CodingKey {
case codec = "codec"
case sampleRateHz = "sample_rate_hz"
case channels = "channels"
case channelLayout = "channel_layout"
case packetDurationMs = "packet_duration_ms"
}
public init(codec: String, sampleRateHz: Int64, channels: Int64, channelLayout: String, packetDurationMs: Int64) throws {
self.codec = codec
self.sampleRateHz = sampleRateHz
self.channels = channels
self.channelLayout = channelLayout
self.packetDurationMs = packetDurationMs
try validate()
}
public init(from decoder: Decoder) throws {
let all = try decoder.container(keyedBy: AnyCodingKey.self)
for key in all.allKeys where CodingKeys(stringValue: key.stringValue) == nil { throw ContractValidationError(field: key.stringValue, code: "unknown_field") }
let c = try decoder.container(keyedBy: CodingKeys.self)
try self.init(codec: try c.decode(String.self, forKey: .codec), sampleRateHz: try c.decode(Int64.self, forKey: .sampleRateHz), channels: try c.decode(Int64.self, forKey: .channels), channelLayout: try c.decode(String.self, forKey: .channelLayout), packetDurationMs: try c.decode(Int64.self, forKey: .packetDurationMs))
}
public func validate() throws {
if self.codec != "opus" { throw ContractValidationError(field: "codec", code: "invalid_value") }
if self.sampleRateHz < 48000 { throw ContractValidationError(field: "sample_rate_hz", code: "minimum") }
if self.sampleRateHz > 48000 { throw ContractValidationError(field: "sample_rate_hz", code: "maximum") }
if self.channels < 2 { throw ContractValidationError(field: "channels", code: "minimum") }
if self.channels > 2 { throw ContractValidationError(field: "channels", code: "maximum") }
if self.channelLayout != "stereo" { throw ContractValidationError(field: "channel_layout", code: "invalid_value") }
if self.packetDurationMs < 5 { throw ContractValidationError(field: "packet_duration_ms", code: "minimum") }
if self.packetDurationMs > 5 { throw ContractValidationError(field: "packet_duration_ms", code: "maximum") }
}
public static func decodeJSON(_ data: Data) throws -> Self { try rejectDuplicateJSONKeys(data); return try JSONDecoder().decode(Self.self, from: data) }
public func encodeJSON() throws -> Data { try validate(); return try JSONEncoder().encode(self) }
}
public struct BitratePreference: Codable, Equatable {
public let mode: String
public let targetKbps: Int64?
enum CodingKeys: String, CodingKey {
case mode = "mode"
case targetKbps = "target_kbps"
}
public init(mode: String, targetKbps: Int64?) throws {
self.mode = mode
self.targetKbps = targetKbps
try validate()
}
public init(from decoder: Decoder) throws {
let all = try decoder.container(keyedBy: AnyCodingKey.self)
for key in all.allKeys where CodingKeys(stringValue: key.stringValue) == nil { throw ContractValidationError(field: key.stringValue, code: "unknown_field") }
let c = try decoder.container(keyedBy: CodingKeys.self)
try self.init(mode: try c.decode(String.self, forKey: .mode), targetKbps: try c.decodeIfPresent(Int64.self, forKey: .targetKbps))
}
public func validate() throws {
if !["auto", "explicit"].contains(self.mode) { throw ContractValidationError(field: "mode", code: "invalid_value") }
if let value = self.targetKbps {
if value < 100 { throw ContractValidationError(field: "target_kbps", code: "minimum") }
if value > 1000000 { throw ContractValidationError(field: "target_kbps", code: "maximum") }
}
if mode == "auto" && targetKbps != nil || mode == "explicit" && targetKbps == nil { throw ContractValidationError(field: "target_kbps", code: "invalid_tagged_value") }
}
public static func decodeJSON(_ data: Data) throws -> Self { try rejectDuplicateJSONKeys(data); return try JSONDecoder().decode(Self.self, from: data) }
public func encodeJSON() throws -> Data { try validate(); return try JSONEncoder().encode(self) }
}
public struct BrokerSession: Codable, Equatable {
public let id: String
public let principalId: String
public let poolId: String
public let assignmentId: String?
public let state: String
public let policySnapshot: AllocationPolicy
public let reconnectDeadline: String?
public let outcome: String?
public let failureCode: String?
public let cleanupState: String
public let idempotencyKey: String
public let correlationId: String
public let requestedAt: String
public let endedAt: String?
public let version: Int64
public let requestedDisplayMode: DisplayMode?
public let effectiveDisplayMode: DisplayMode?
public let requestedVideoProfiles: [VideoProfile]
public let requestedBitratePreference: BitratePreference
public let selectedDescriptor: SelectedSessionDescriptor?
enum CodingKeys: String, CodingKey {
case id = "id"
case principalId = "principal_id"
case poolId = "pool_id"
case assignmentId = "assignment_id"
case state = "state"
case policySnapshot = "policy_snapshot"
case reconnectDeadline = "reconnect_deadline"
case outcome = "outcome"
case failureCode = "failure_code"
case cleanupState = "cleanup_state"
case idempotencyKey = "idempotency_key"
case correlationId = "correlation_id"
case requestedAt = "requested_at"
case endedAt = "ended_at"
case version = "version"
case requestedDisplayMode = "requested_display_mode"
case effectiveDisplayMode = "effective_display_mode"
case requestedVideoProfiles = "requested_video_profiles"
case requestedBitratePreference = "requested_bitrate_preference"
case selectedDescriptor = "selected_descriptor"
}
public init(id: String, principalId: String, poolId: String, assignmentId: String?, state: String, policySnapshot: AllocationPolicy, reconnectDeadline: String?, outcome: String?, failureCode: String?, cleanupState: String, idempotencyKey: String, correlationId: String, requestedAt: String, endedAt: String?, version: Int64, requestedDisplayMode: DisplayMode?, effectiveDisplayMode: DisplayMode?, requestedVideoProfiles: [VideoProfile], requestedBitratePreference: BitratePreference, selectedDescriptor: SelectedSessionDescriptor?) throws {
self.id = id
self.principalId = principalId
self.poolId = poolId
self.assignmentId = assignmentId
self.state = state
self.policySnapshot = policySnapshot
self.reconnectDeadline = reconnectDeadline
self.outcome = outcome
self.failureCode = failureCode
self.cleanupState = cleanupState
self.idempotencyKey = idempotencyKey
self.correlationId = correlationId
self.requestedAt = requestedAt
self.endedAt = endedAt
self.version = version
self.requestedDisplayMode = requestedDisplayMode
self.effectiveDisplayMode = effectiveDisplayMode
self.requestedVideoProfiles = requestedVideoProfiles
self.requestedBitratePreference = requestedBitratePreference
self.selectedDescriptor = selectedDescriptor
try validate()
}
public init(from decoder: Decoder) throws {
let all = try decoder.container(keyedBy: AnyCodingKey.self)
for key in all.allKeys where CodingKeys(stringValue: key.stringValue) == nil { throw ContractValidationError(field: key.stringValue, code: "unknown_field") }
let c = try decoder.container(keyedBy: CodingKeys.self)
try self.init(id: try c.decode(String.self, forKey: .id), principalId: try c.decode(String.self, forKey: .principalId), poolId: try c.decode(String.self, forKey: .poolId), assignmentId: try c.decodeIfPresent(String.self, forKey: .assignmentId), state: try c.decode(String.self, forKey: .state), policySnapshot: try c.decode(AllocationPolicy.self, forKey: .policySnapshot), reconnectDeadline: try c.decodeIfPresent(String.self, forKey: .reconnectDeadline), outcome: try c.decodeIfPresent(String.self, forKey: .outcome), failureCode: try c.decodeIfPresent(String.self, forKey: .failureCode), cleanupState: try c.decode(String.self, forKey: .cleanupState), idempotencyKey: try c.decode(String.self, forKey: .idempotencyKey), correlationId: try c.decode(String.self, forKey: .correlationId), requestedAt: try c.decode(String.self, forKey: .requestedAt), endedAt: try c.decodeIfPresent(String.self, forKey: .endedAt), version: try c.decode(Int64.self, forKey: .version), requestedDisplayMode: try c.contains(.requestedDisplayMode) ? c.decode(DisplayMode.self, forKey: .requestedDisplayMode) : nil, effectiveDisplayMode: try c.contains(.effectiveDisplayMode) ? c.decode(DisplayMode.self, forKey: .effectiveDisplayMode) : nil, requestedVideoProfiles: try c.decode([VideoProfile].self, forKey: .requestedVideoProfiles), requestedBitratePreference: try c.decode(BitratePreference.self, forKey: .requestedBitratePreference), selectedDescriptor: try c.contains(.selectedDescriptor) ? c.decode(SelectedSessionDescriptor.self, forKey: .selectedDescriptor) : nil)
}
public func validate() throws {
if self.id.isEmpty { throw ContractValidationError(field: "id", code: "required") }
if !self.id.isEmpty && self.id.utf8.count < 1 { throw ContractValidationError(field: "id", code: "min_length") }
if self.id.utf8.count > 128 { throw ContractValidationError(field: "id", code: "max_length") }
if self.principalId.isEmpty { throw ContractValidationError(field: "principal_id", code: "required") }
if !self.principalId.isEmpty && self.principalId.utf8.count < 1 { throw ContractValidationError(field: "principal_id", code: "min_length") }
if self.principalId.utf8.count > 128 { throw ContractValidationError(field: "principal_id", code: "max_length") }
if self.poolId.isEmpty { throw ContractValidationError(field: "pool_id", code: "required") }
if !self.poolId.isEmpty && self.poolId.utf8.count < 1 { throw ContractValidationError(field: "pool_id", code: "min_length") }
if self.poolId.utf8.count > 128 { throw ContractValidationError(field: "pool_id", code: "max_length") }
if let value = self.assignmentId {
if value.utf8.count > 128 { throw ContractValidationError(field: "assignment_id", code: "max_length") }
}
if self.state.isEmpty { throw ContractValidationError(field: "state", code: "required") }
if !self.state.isEmpty && self.state.utf8.count < 1 { throw ContractValidationError(field: "state", code: "min_length") }
if self.state.utf8.count > 64 { throw ContractValidationError(field: "state", code: "max_length") }
try self.policySnapshot.validate()
if let value = self.reconnectDeadline {
if value.utf8.count > 64 { throw ContractValidationError(field: "reconnect_deadline", code: "max_length") }
if !validRFC3339UTC(value) { throw ContractValidationError(field: "reconnect_deadline", code: "invalid_time") }
}
if let value = self.outcome {
if value.utf8.count > 64 { throw ContractValidationError(field: "outcome", code: "max_length") }
}
if let value = self.failureCode {
if value.utf8.count > 128 { throw ContractValidationError(field: "failure_code", code: "max_length") }
}
if self.cleanupState.isEmpty { throw ContractValidationError(field: "cleanup_state", code: "required") }
if !self.cleanupState.isEmpty && self.cleanupState.utf8.count < 1 { throw ContractValidationError(field: "cleanup_state", code: "min_length") }
if self.cleanupState.utf8.count > 64 { throw ContractValidationError(field: "cleanup_state", code: "max_length") }
if self.idempotencyKey.isEmpty { throw ContractValidationError(field: "idempotency_key", code: "required") }
if !self.idempotencyKey.isEmpty && self.idempotencyKey.utf8.count < 1 { throw ContractValidationError(field: "idempotency_key", code: "min_length") }
if self.idempotencyKey.utf8.count > 256 { throw ContractValidationError(field: "idempotency_key", code: "max_length") }
if self.correlationId.isEmpty { throw ContractValidationError(field: "correlation_id", code: "required") }
if !self.correlationId.isEmpty && self.correlationId.utf8.count < 1 { throw ContractValidationError(field: "correlation_id", code: "min_length") }
if self.correlationId.utf8.count > 128 { throw ContractValidationError(field: "correlation_id", code: "max_length") }
if self.requestedAt.utf8.count > 64 { throw ContractValidationError(field: "requested_at", code: "max_length") }
if !validRFC3339UTC(self.requestedAt) { throw ContractValidationError(field: "requested_at", code: "invalid_time") }
if let value = self.endedAt {
if value.utf8.count > 64 { throw ContractValidationError(field: "ended_at", code: "max_length") }
if !validRFC3339UTC(value) { throw ContractValidationError(field: "ended_at", code: "invalid_time") }
}
if self.version < 1 { throw ContractValidationError(field: "version", code: "minimum") }
if let value = self.requestedDisplayMode {
try value.validate()
}
if let value = self.effectiveDisplayMode {
try value.validate()
}
if self.requestedVideoProfiles.count < 1 { throw ContractValidationError(field: "requested_video_profiles", code: "min_items") }
if self.requestedVideoProfiles.count > 12 { throw ContractValidationError(field: "requested_video_profiles", code: "max_items") }
for (index, item) in self.requestedVideoProfiles.enumerated() where self.requestedVideoProfiles[..<index].contains(item) { throw ContractValidationError(field: "requested_video_profiles", code: "duplicate_item") }
for item in self.requestedVideoProfiles { try item.validate() }
try self.requestedBitratePreference.validate()
if let value = self.selectedDescriptor {
try value.validate()
}
}
public static func decodeJSON(_ data: Data) throws -> Self { try rejectDuplicateJSONKeys(data); return try JSONDecoder().decode(Self.self, from: data) }
public func encodeJSON() throws -> Data { try validate(); return try JSONEncoder().encode(self) }
}
public struct BrowserAuthenticatedSession: Codable, Equatable {
public let username: String
public let provider: String
public let roles: [String]
public let role: String
enum CodingKeys: String, CodingKey {
case username = "username"
case provider = "provider"
case roles = "roles"
case role = "role"
}
public init(username: String, provider: String, roles: [String], role: String) throws {
self.username = username
self.provider = provider
self.roles = roles
self.role = role
try validate()
}
public init(from decoder: Decoder) throws {
let all = try decoder.container(keyedBy: AnyCodingKey.self)
for key in all.allKeys where CodingKeys(stringValue: key.stringValue) == nil { throw ContractValidationError(field: key.stringValue, code: "unknown_field") }
let c = try decoder.container(keyedBy: CodingKeys.self)
try self.init(username: try c.decode(String.self, forKey: .username), provider: try c.decode(String.self, forKey: .provider), roles: try c.decode([String].self, forKey: .roles), role: try c.decode(String.self, forKey: .role))
}
public func validate() throws {
if self.username.isEmpty { throw ContractValidationError(field: "username", code: "required") }
if !self.username.isEmpty && self.username.utf8.count < 1 { throw ContractValidationError(field: "username", code: "min_length") }
if self.username.utf8.count > 256 { throw ContractValidationError(field: "username", code: "max_length") }
if self.provider.isEmpty { throw ContractValidationError(field: "provider", code: "required") }
if !self.provider.isEmpty && self.provider.utf8.count < 1 { throw ContractValidationError(field: "provider", code: "min_length") }
if self.provider.utf8.count > 64 { throw ContractValidationError(field: "provider", code: "max_length") }
if self.roles.count > 16 { throw ContractValidationError(field: "roles", code: "max_items") }
for item in self.roles where item.utf8.count < 1 { throw ContractValidationError(field: "roles", code: "min_item_length") }
for item in self.roles where item.utf8.count > 64 { throw ContractValidationError(field: "roles", code: "max_item_length") }
for item in self.roles where item.utf8.count > 64 { throw ContractValidationError(field: "roles", code: "max_item_bytes") }
if !["user", "admin"].contains(self.role) { throw ContractValidationError(field: "role", code: "invalid_value") }
}
public static func decodeJSON(_ data: Data) throws -> Self { try rejectDuplicateJSONKeys(data); return try JSONDecoder().decode(Self.self, from: data) }
public func encodeJSON() throws -> Data { try validate(); return try JSONEncoder().encode(self) }
}
public struct CapabilityProfile: Codable, Equatable {
public let transport: String
public let framing: String
public let media: String
public let sourceRateControl: String
public let videoProfiles: [VideoProfile]
public let audioProfiles: [AudioProfile]
enum CodingKeys: String, CodingKey {
case transport = "transport"
case framing = "framing"
case media = "media"
case sourceRateControl = "source_rate_control"
case videoProfiles = "video_profiles"
case audioProfiles = "audio_profiles"
}
public init(transport: String, framing: String, media: String, sourceRateControl: String, videoProfiles: [VideoProfile], audioProfiles: [AudioProfile]) throws {
self.transport = transport
self.framing = framing
self.media = media
self.sourceRateControl = sourceRateControl
self.videoProfiles = videoProfiles
self.audioProfiles = audioProfiles
try validate()
}
public init(from decoder: Decoder) throws {
let all = try decoder.container(keyedBy: AnyCodingKey.self)
for key in all.allKeys where CodingKeys(stringValue: key.stringValue) == nil { throw ContractValidationError(field: key.stringValue, code: "unknown_field") }
let c = try decoder.container(keyedBy: CodingKeys.self)
try self.init(transport: try c.decode(String.self, forKey: .transport), framing: try c.decode(String.self, forKey: .framing), media: try c.decode(String.self, forKey: .media), sourceRateControl: try c.decode(String.self, forKey: .sourceRateControl), videoProfiles: try c.decode([VideoProfile].self, forKey: .videoProfiles), audioProfiles: try c.decode([AudioProfile].self, forKey: .audioProfiles))
}
public func validate() throws {
if self.transport.isEmpty { throw ContractValidationError(field: "transport", code: "required") }
if !self.transport.isEmpty && self.transport.utf8.count < 1 { throw ContractValidationError(field: "transport", code: "min_length") }
if self.transport.utf8.count > 64 { throw ContractValidationError(field: "transport", code: "max_length") }
if !["datagram-v1", "datagram-v2"].contains(self.framing) { throw ContractValidationError(field: "framing", code: "invalid_value") }
if self.media.isEmpty { throw ContractValidationError(field: "media", code: "required") }
if !self.media.isEmpty && self.media.utf8.count < 1 { throw ContractValidationError(field: "media", code: "min_length") }
if self.media.utf8.count > 64 { throw ContractValidationError(field: "media", code: "max_length") }
if self.sourceRateControl.isEmpty { throw ContractValidationError(field: "source_rate_control", code: "required") }
if !self.sourceRateControl.isEmpty && self.sourceRateControl.utf8.count < 1 { throw ContractValidationError(field: "source_rate_control", code: "min_length") }
if self.sourceRateControl.utf8.count > 64 { throw ContractValidationError(field: "source_rate_control", code: "max_length") }
if self.videoProfiles.count < 1 { throw ContractValidationError(field: "video_profiles", code: "min_items") }
if self.videoProfiles.count > 12 { throw ContractValidationError(field: "video_profiles", code: "max_items") }
for (index, item) in self.videoProfiles.enumerated() where self.videoProfiles[..<index].contains(item) { throw ContractValidationError(field: "video_profiles", code: "duplicate_item") }
for item in self.videoProfiles { try item.validate() }
if self.audioProfiles.count < 1 { throw ContractValidationError(field: "audio_profiles", code: "min_items") }
if self.audioProfiles.count > 1 { throw ContractValidationError(field: "audio_profiles", code: "max_items") }
for (index, item) in self.audioProfiles.enumerated() where self.audioProfiles[..<index].contains(item) { throw ContractValidationError(field: "audio_profiles", code: "duplicate_item") }
for item in self.audioProfiles { try item.validate() }
}
public static func decodeJSON(_ data: Data) throws -> Self { try rejectDuplicateJSONKeys(data); return try JSONDecoder().decode(Self.self, from: data) }
public func encodeJSON() throws -> Data { try validate(); return try JSONEncoder().encode(self) }
}
public struct ChannelFrame: Codable, Equatable {
public let version: String
public let flowId: String
public let sequence: Int64
public let flags: Int64
public let fragmentIndex: Int64
public let fragmentCount: Int64
public let timestampMs: Int64
public let payload: String
enum CodingKeys: String, CodingKey {
case version = "version"
case flowId = "flow_id"
case sequence = "sequence"
case flags = "flags"
case fragmentIndex = "fragment_index"
case fragmentCount = "fragment_count"
case timestampMs = "timestamp_ms"
case payload = "payload"
}
public init(version: String, flowId: String, sequence: Int64, flags: Int64, fragmentIndex: Int64, fragmentCount: Int64, timestampMs: Int64, payload: String) throws {
self.version = version
self.flowId = flowId
self.sequence = sequence
self.flags = flags
self.fragmentIndex = fragmentIndex
self.fragmentCount = fragmentCount
self.timestampMs = timestampMs
self.payload = payload
try validate()
}
public init(from decoder: Decoder) throws {
let all = try decoder.container(keyedBy: AnyCodingKey.self)
for key in all.allKeys where CodingKeys(stringValue: key.stringValue) == nil { throw ContractValidationError(field: key.stringValue, code: "unknown_field") }
let c = try decoder.container(keyedBy: CodingKeys.self)
try self.init(version: try c.decode(String.self, forKey: .version), flowId: try c.decode(String.self, forKey: .flowId), sequence: try c.decode(Int64.self, forKey: .sequence), flags: try c.decode(Int64.self, forKey: .flags), fragmentIndex: try c.decode(Int64.self, forKey: .fragmentIndex), fragmentCount: try c.decode(Int64.self, forKey: .fragmentCount), timestampMs: try c.decode(Int64.self, forKey: .timestampMs), payload: try c.decode(String.self, forKey: .payload))
}
public func validate() throws {
if self.version != "1" { throw ContractValidationError(field: "version", code: "invalid_value") }
if self.flowId.isEmpty { throw ContractValidationError(field: "flow_id", code: "required") }
if !self.flowId.isEmpty && self.flowId.utf8.count < 1 { throw ContractValidationError(field: "flow_id", code: "min_length") }
if self.flowId.utf8.count > 64 { throw ContractValidationError(field: "flow_id", code: "max_length") }
if self.sequence < 0 { throw ContractValidationError(field: "sequence", code: "minimum") }
if self.flags < 0 { throw ContractValidationError(field: "flags", code: "minimum") }
if self.flags > 255 { throw ContractValidationError(field: "flags", code: "maximum") }
if self.fragmentIndex < 0 { throw ContractValidationError(field: "fragment_index", code: "minimum") }
if self.fragmentIndex > 15 { throw ContractValidationError(field: "fragment_index", code: "maximum") }
if self.fragmentCount < 1 { throw ContractValidationError(field: "fragment_count", code: "minimum") }
if self.fragmentCount > 16 { throw ContractValidationError(field: "fragment_count", code: "maximum") }
if self.timestampMs < 0 { throw ContractValidationError(field: "timestamp_ms", code: "minimum") }
if self.payload.utf8.count > 87384 { throw ContractValidationError(field: "payload", code: "max_length") }
if self.payload.utf8.count > 65536 { throw ContractValidationError(field: "payload", code: "max_bytes") }
if fragmentIndex >= fragmentCount { throw ContractValidationError(field: "fragment_index", code: "invalid_order") }
}
public static func decodeJSON(_ data: Data) throws -> Self { try rejectDuplicateJSONKeys(data); return try JSONDecoder().decode(Self.self, from: data) }
public func encodeJSON() throws -> Data { try validate(); return try JSONEncoder().encode(self) }
}
public struct ClientSessionAuthority: Codable, Equatable {
public let version: String
public let sessionId: String
public let gatewayId: String
public let audience: String
public let reconnectSequence: Int64
public let expiresAt: String
public let capabilities: CapabilityProfile
public let selectedDescriptor: SelectedSessionDescriptor
enum CodingKeys: String, CodingKey {
case version = "version"
case sessionId = "session_id"
case gatewayId = "gateway_id"
case audience = "audience"
case reconnectSequence = "reconnect_sequence"
case expiresAt = "expires_at"
case capabilities = "capabilities"
case selectedDescriptor = "selected_descriptor"
}
public init(version: String, sessionId: String, gatewayId: String, audience: String, reconnectSequence: Int64, expiresAt: String, capabilities: CapabilityProfile, selectedDescriptor: SelectedSessionDescriptor) throws {
self.version = version
self.sessionId = sessionId
self.gatewayId = gatewayId
self.audience = audience
self.reconnectSequence = reconnectSequence
self.expiresAt = expiresAt
self.capabilities = capabilities
self.selectedDescriptor = selectedDescriptor
try validate()
}
public init(from decoder: Decoder) throws {
let all = try decoder.container(keyedBy: AnyCodingKey.self)
for key in all.allKeys where CodingKeys(stringValue: key.stringValue) == nil { throw ContractValidationError(field: key.stringValue, code: "unknown_field") }
let c = try decoder.container(keyedBy: CodingKeys.self)
try self.init(version: try c.decode(String.self, forKey: .version), sessionId: try c.decode(String.self, forKey: .sessionId), gatewayId: try c.decode(String.self, forKey: .gatewayId), audience: try c.decode(String.self, forKey: .audience), reconnectSequence: try c.decode(Int64.self, forKey: .reconnectSequence), expiresAt: try c.decode(String.self, forKey: .expiresAt), capabilities: try c.decode(CapabilityProfile.self, forKey: .capabilities), selectedDescriptor: try c.decode(SelectedSessionDescriptor.self, forKey: .selectedDescriptor))
}
public func validate() throws {
if self.version != "1" { throw ContractValidationError(field: "version", code: "invalid_value") }
if self.sessionId.isEmpty { throw ContractValidationError(field: "session_id", code: "required") }
if !self.sessionId.isEmpty && self.sessionId.utf8.count < 1 { throw ContractValidationError(field: "session_id", code: "min_length") }
if self.sessionId.utf8.count > 128 { throw ContractValidationError(field: "session_id", code: "max_length") }
if self.gatewayId.isEmpty { throw ContractValidationError(field: "gateway_id", code: "required") }
if !self.gatewayId.isEmpty && self.gatewayId.utf8.count < 1 { throw ContractValidationError(field: "gateway_id", code: "min_length") }
if self.gatewayId.utf8.count > 128 { throw ContractValidationError(field: "gateway_id", code: "max_length") }
if self.audience.isEmpty { throw ContractValidationError(field: "audience", code: "required") }
if !self.audience.isEmpty && self.audience.utf8.count < 1 { throw ContractValidationError(field: "audience", code: "min_length") }
if self.audience.utf8.count > 256 { throw ContractValidationError(field: "audience", code: "max_length") }
if self.reconnectSequence < 0 { throw ContractValidationError(field: "reconnect_sequence", code: "minimum") }
if self.expiresAt.utf8.count > 64 { throw ContractValidationError(field: "expires_at", code: "max_length") }
if !validRFC3339UTC(self.expiresAt) { throw ContractValidationError(field: "expires_at", code: "invalid_time") }
try self.capabilities.validate()
try self.selectedDescriptor.validate()
}
public static func decodeJSON(_ data: Data) throws -> Self { try rejectDuplicateJSONKeys(data); return try JSONDecoder().decode(Self.self, from: data) }
public func encodeJSON() throws -> Data { try validate(); return try JSONEncoder().encode(self) }
}
public struct ClipboardPolicy: Codable, Equatable {
public let clientToProviderEnabled: Bool
public let providerToClientEnabled: Bool
public let maxTextBytes: Int64
public let maxUpdatesPerMinute: Int64
enum CodingKeys: String, CodingKey {
case clientToProviderEnabled = "client_to_provider_enabled"
case providerToClientEnabled = "provider_to_client_enabled"
case maxTextBytes = "max_text_bytes"
case maxUpdatesPerMinute = "max_updates_per_minute"
}
public init(clientToProviderEnabled: Bool, providerToClientEnabled: Bool, maxTextBytes: Int64, maxUpdatesPerMinute: Int64) throws {
self.clientToProviderEnabled = clientToProviderEnabled
self.providerToClientEnabled = providerToClientEnabled
self.maxTextBytes = maxTextBytes
self.maxUpdatesPerMinute = maxUpdatesPerMinute
try validate()
}
public init(from decoder: Decoder) throws {
let all = try decoder.container(keyedBy: AnyCodingKey.self)
for key in all.allKeys where CodingKeys(stringValue: key.stringValue) == nil { throw ContractValidationError(field: key.stringValue, code: "unknown_field") }
let c = try decoder.container(keyedBy: CodingKeys.self)
try self.init(clientToProviderEnabled: try c.decode(Bool.self, forKey: .clientToProviderEnabled), providerToClientEnabled: try c.decode(Bool.self, forKey: .providerToClientEnabled), maxTextBytes: try c.decode(Int64.self, forKey: .maxTextBytes), maxUpdatesPerMinute: try c.decode(Int64.self, forKey: .maxUpdatesPerMinute))
}
public func validate() throws {
if self.maxTextBytes < 1 { throw ContractValidationError(field: "max_text_bytes", code: "minimum") }
if self.maxTextBytes > 65536 { throw ContractValidationError(field: "max_text_bytes", code: "maximum") }
if self.maxUpdatesPerMinute < 1 { throw ContractValidationError(field: "max_updates_per_minute", code: "minimum") }
if self.maxUpdatesPerMinute > 120 { throw ContractValidationError(field: "max_updates_per_minute", code: "maximum") }
}
public static func decodeJSON(_ data: Data) throws -> Self { try rejectDuplicateJSONKeys(data); return try JSONDecoder().decode(Self.self, from: data) }
public func encodeJSON() throws -> Data { try validate(); return try JSONEncoder().encode(self) }
}
public struct ClipboardText: Codable, Equatable {
public let text: String
public let encoding: String
enum CodingKeys: String, CodingKey {
case text = "text"
case encoding = "encoding"
}
public init(text: String, encoding: String) throws {
self.text = text
self.encoding = encoding
try validate()
}
public init(from decoder: Decoder) throws {
let all = try decoder.container(keyedBy: AnyCodingKey.self)
for key in all.allKeys where CodingKeys(stringValue: key.stringValue) == nil { throw ContractValidationError(field: key.stringValue, code: "unknown_field") }
let c = try decoder.container(keyedBy: CodingKeys.self)
try self.init(text: try c.decode(String.self, forKey: .text), encoding: try c.decode(String.self, forKey: .encoding))
}
public func validate() throws {
if self.text.utf8.count > 65536 { throw ContractValidationError(field: "text", code: "max_length") }
if self.encoding != "utf-8" { throw ContractValidationError(field: "encoding", code: "invalid_value") }
}
public static func decodeJSON(_ data: Data) throws -> Self { try rejectDuplicateJSONKeys(data); return try JSONDecoder().decode(Self.self, from: data) }
public func encodeJSON() throws -> Data { try validate(); return try JSONEncoder().encode(self) }
}
public struct ConnectionManifest: Codable, Equatable {
public let version: String
public let purpose: String
public let sessionId: String
public let reconnectSequence: Int64
public let gateway: ManifestGateway
public let tunnel: ManifestTunnel
public let profile: ManifestProfile
public let grant: GrantReference
public let correlationId: String
public let selectedDescriptor: SelectedSessionDescriptor
enum CodingKeys: String, CodingKey {
case version = "version"
case purpose = "purpose"
case sessionId = "session_id"
case reconnectSequence = "reconnect_sequence"
case gateway = "gateway"
case tunnel = "tunnel"
case profile = "profile"
case grant = "grant"
case correlationId = "correlation_id"
case selectedDescriptor = "selected_descriptor"
}
public init(version: String, purpose: String, sessionId: String, reconnectSequence: Int64, gateway: ManifestGateway, tunnel: ManifestTunnel, profile: ManifestProfile, grant: GrantReference, correlationId: String, selectedDescriptor: SelectedSessionDescriptor) throws {
self.version = version
self.purpose = purpose
self.sessionId = sessionId
self.reconnectSequence = reconnectSequence
self.gateway = gateway
self.tunnel = tunnel
self.profile = profile
self.grant = grant
self.correlationId = correlationId
self.selectedDescriptor = selectedDescriptor
try validate()
}
public init(from decoder: Decoder) throws {
let all = try decoder.container(keyedBy: AnyCodingKey.self)
for key in all.allKeys where CodingKeys(stringValue: key.stringValue) == nil { throw ContractValidationError(field: key.stringValue, code: "unknown_field") }
let c = try decoder.container(keyedBy: CodingKeys.self)
try self.init(version: try c.decode(String.self, forKey: .version), purpose: try c.decode(String.self, forKey: .purpose), sessionId: try c.decode(String.self, forKey: .sessionId), reconnectSequence: try c.decode(Int64.self, forKey: .reconnectSequence), gateway: try c.decode(ManifestGateway.self, forKey: .gateway), tunnel: try c.decode(ManifestTunnel.self, forKey: .tunnel), profile: try c.decode(ManifestProfile.self, forKey: .profile), grant: try c.decode(GrantReference.self, forKey: .grant), correlationId: try c.decode(String.self, forKey: .correlationId), selectedDescriptor: try c.decode(SelectedSessionDescriptor.self, forKey: .selectedDescriptor))
}
public func validate() throws {
if self.version != "1" { throw ContractValidationError(field: "version", code: "invalid_value") }
if !["launch", "reconnect"].contains(self.purpose) { throw ContractValidationError(field: "purpose", code: "invalid_value") }
if self.sessionId.isEmpty { throw ContractValidationError(field: "session_id", code: "required") }
if !self.sessionId.isEmpty && self.sessionId.utf8.count < 1 { throw ContractValidationError(field: "session_id", code: "min_length") }
if self.sessionId.utf8.count > 128 { throw ContractValidationError(field: "session_id", code: "max_length") }
if self.reconnectSequence < 0 { throw ContractValidationError(field: "reconnect_sequence", code: "minimum") }
try self.gateway.validate()
try self.tunnel.validate()
try self.profile.validate()
try self.grant.validate()
if self.correlationId.isEmpty { throw ContractValidationError(field: "correlation_id", code: "required") }
if !self.correlationId.isEmpty && self.correlationId.utf8.count < 1 { throw ContractValidationError(field: "correlation_id", code: "min_length") }
if self.correlationId.utf8.count > 128 { throw ContractValidationError(field: "correlation_id", code: "max_length") }
try self.selectedDescriptor.validate()
}
public static func decodeJSON(_ data: Data) throws -> Self { try rejectDuplicateJSONKeys(data); return try JSONDecoder().decode(Self.self, from: data) }
public func encodeJSON() throws -> Data { try validate(); return try JSONEncoder().encode(self) }
}
public struct DeviceChallenge: Codable, Equatable {
public let deviceId: String
public let serverId: String
public let principalId: String
public let challenge: String
public let expiresAt: String
public let algorithm: String
public let signatureFormat: String
enum CodingKeys: String, CodingKey {
case deviceId = "device_id"
case serverId = "server_id"
case principalId = "principal_id"
case challenge = "challenge"
case expiresAt = "expires_at"
case algorithm = "algorithm"
case signatureFormat = "signature_format"
}
public init(deviceId: String, serverId: String, principalId: String, challenge: String, expiresAt: String, algorithm: String, signatureFormat: String) throws {
self.deviceId = deviceId
self.serverId = serverId
self.principalId = principalId
self.challenge = challenge
self.expiresAt = expiresAt
self.algorithm = algorithm
self.signatureFormat = signatureFormat
try validate()
}
public init(from decoder: Decoder) throws {
let all = try decoder.container(keyedBy: AnyCodingKey.self)
for key in all.allKeys where CodingKeys(stringValue: key.stringValue) == nil { throw ContractValidationError(field: key.stringValue, code: "unknown_field") }
let c = try decoder.container(keyedBy: CodingKeys.self)
try self.init(deviceId: try c.decode(String.self, forKey: .deviceId), serverId: try c.decode(String.self, forKey: .serverId), principalId: try c.decode(String.self, forKey: .principalId), challenge: try c.decode(String.self, forKey: .challenge), expiresAt: try c.decode(String.self, forKey: .expiresAt), algorithm: try c.decode(String.self, forKey: .algorithm), signatureFormat: try c.decode(String.self, forKey: .signatureFormat))
}
public func validate() throws {
if self.deviceId.isEmpty { throw ContractValidationError(field: "device_id", code: "required") }
if !self.deviceId.isEmpty && self.deviceId.utf8.count < 1 { throw ContractValidationError(field: "device_id", code: "min_length") }
if self.deviceId.utf8.count > 128 { throw ContractValidationError(field: "device_id", code: "max_length") }
if self.serverId.isEmpty { throw ContractValidationError(field: "server_id", code: "required") }
if !self.serverId.isEmpty && self.serverId.utf8.count < 1 { throw ContractValidationError(field: "server_id", code: "min_length") }
if self.serverId.utf8.count > 128 { throw ContractValidationError(field: "server_id", code: "max_length") }
if self.principalId.isEmpty { throw ContractValidationError(field: "principal_id", code: "required") }
if !self.principalId.isEmpty && self.principalId.utf8.count < 1 { throw ContractValidationError(field: "principal_id", code: "min_length") }
if self.principalId.utf8.count > 128 { throw ContractValidationError(field: "principal_id", code: "max_length") }
if self.challenge.isEmpty { throw ContractValidationError(field: "challenge", code: "required") }
if !self.challenge.isEmpty && self.challenge.utf8.count < 1 { throw ContractValidationError(field: "challenge", code: "min_length") }
if self.challenge.utf8.count > 256 { throw ContractValidationError(field: "challenge", code: "max_length") }
if self.expiresAt.utf8.count > 64 { throw ContractValidationError(field: "expires_at", code: "max_length") }
if !validRFC3339UTC(self.expiresAt) { throw ContractValidationError(field: "expires_at", code: "invalid_time") }
if self.algorithm != "ed25519" { throw ContractValidationError(field: "algorithm", code: "invalid_value") }
if self.signatureFormat != "ed25519-domain-separated-v1" { throw ContractValidationError(field: "signature_format", code: "invalid_value") }
}
public static func decodeJSON(_ data: Data) throws -> Self { try rejectDuplicateJSONKeys(data); return try JSONDecoder().decode(Self.self, from: data) }
public func encodeJSON() throws -> Data { try validate(); return try JSONEncoder().encode(self) }
}
public struct DeviceProofRequest: Codable, Equatable {
public let challenge: String
public let signature: String
enum CodingKeys: String, CodingKey {
case challenge = "challenge"
case signature = "signature"
}
public init(challenge: String, signature: String) throws {
self.challenge = challenge
self.signature = signature
try validate()
}
public init(from decoder: Decoder) throws {
let all = try decoder.container(keyedBy: AnyCodingKey.self)
for key in all.allKeys where CodingKeys(stringValue: key.stringValue) == nil { throw ContractValidationError(field: key.stringValue, code: "unknown_field") }
let c = try decoder.container(keyedBy: CodingKeys.self)
try self.init(challenge: try c.decode(String.self, forKey: .challenge), signature: try c.decode(String.self, forKey: .signature))
}
public func validate() throws {
if self.challenge.isEmpty { throw ContractValidationError(field: "challenge", code: "required") }
if !self.challenge.isEmpty && self.challenge.utf8.count < 1 { throw ContractValidationError(field: "challenge", code: "min_length") }
if self.challenge.utf8.count > 256 { throw ContractValidationError(field: "challenge", code: "max_length") }
if self.signature.isEmpty { throw ContractValidationError(field: "signature", code: "required") }
if !self.signature.isEmpty && self.signature.utf8.count < 1 { throw ContractValidationError(field: "signature", code: "min_length") }
if self.signature.utf8.count > 256 { throw ContractValidationError(field: "signature", code: "max_length") }
}
public static func decodeJSON(_ data: Data) throws -> Self { try rejectDuplicateJSONKeys(data); return try JSONDecoder().decode(Self.self, from: data) }
public func encodeJSON() throws -> Data { try validate(); return try JSONEncoder().encode(self) }
}
public struct DeviceRegistrationRequest: Codable, Equatable {
public let name: String
public let platform: String
public let deviceSubject: String
public let algorithm: String
public let publicKey: String
enum CodingKeys: String, CodingKey {
case name = "name"
case platform = "platform"
case deviceSubject = "device_subject"
case algorithm = "algorithm"
case publicKey = "public_key"
}
public init(name: String, platform: String, deviceSubject: String, algorithm: String, publicKey: String) throws {
self.name = name
self.platform = platform
self.deviceSubject = deviceSubject
self.algorithm = algorithm
self.publicKey = publicKey
try validate()
}
public init(from decoder: Decoder) throws {
let all = try decoder.container(keyedBy: AnyCodingKey.self)
for key in all.allKeys where CodingKeys(stringValue: key.stringValue) == nil { throw ContractValidationError(field: key.stringValue, code: "unknown_field") }
let c = try decoder.container(keyedBy: CodingKeys.self)
try self.init(name: try c.decode(String.self, forKey: .name), platform: try c.decode(String.self, forKey: .platform), deviceSubject: try c.decode(String.self, forKey: .deviceSubject), algorithm: try c.decode(String.self, forKey: .algorithm), publicKey: try c.decode(String.self, forKey: .publicKey))
}
public func validate() throws {
if self.name.isEmpty { throw ContractValidationError(field: "name", code: "required") }
if !self.name.isEmpty && self.name.utf8.count < 1 { throw ContractValidationError(field: "name", code: "min_length") }
if self.name.utf8.count > 128 { throw ContractValidationError(field: "name", code: "max_length") }
if self.platform.isEmpty { throw ContractValidationError(field: "platform", code: "required") }
if !self.platform.isEmpty && self.platform.utf8.count < 1 { throw ContractValidationError(field: "platform", code: "min_length") }
if self.platform.utf8.count > 64 { throw ContractValidationError(field: "platform", code: "max_length") }
if self.deviceSubject.isEmpty { throw ContractValidationError(field: "device_subject", code: "required") }
if !self.deviceSubject.isEmpty && self.deviceSubject.utf8.count < 1 { throw ContractValidationError(field: "device_subject", code: "min_length") }
if self.deviceSubject.utf8.count > 256 { throw ContractValidationError(field: "device_subject", code: "max_length") }
if self.algorithm != "ed25519" { throw ContractValidationError(field: "algorithm", code: "invalid_value") }
if self.publicKey.isEmpty { throw ContractValidationError(field: "public_key", code: "required") }
if !self.publicKey.isEmpty && self.publicKey.utf8.count < 1 { throw ContractValidationError(field: "public_key", code: "min_length") }
if self.publicKey.utf8.count > 256 { throw ContractValidationError(field: "public_key", code: "max_length") }
}
public static func decodeJSON(_ data: Data) throws -> Self { try rejectDuplicateJSONKeys(data); return try JSONDecoder().decode(Self.self, from: data) }
public func encodeJSON() throws -> Data { try validate(); return try JSONEncoder().encode(self) }
}
public struct DisplayLimitOverrideRequest: Codable, Equatable {
public let allowDisplayLimitOverride: Bool
public let expectedVersion: Int64
enum CodingKeys: String, CodingKey {
case allowDisplayLimitOverride = "allow_display_limit_override"
case expectedVersion = "expected_version"
}
public init(allowDisplayLimitOverride: Bool, expectedVersion: Int64) throws {
self.allowDisplayLimitOverride = allowDisplayLimitOverride
self.expectedVersion = expectedVersion
try validate()
}
public init(from decoder: Decoder) throws {
let all = try decoder.container(keyedBy: AnyCodingKey.self)
for key in all.allKeys where CodingKeys(stringValue: key.stringValue) == nil { throw ContractValidationError(field: key.stringValue, code: "unknown_field") }
let c = try decoder.container(keyedBy: CodingKeys.self)
try self.init(allowDisplayLimitOverride: try c.decode(Bool.self, forKey: .allowDisplayLimitOverride), expectedVersion: try c.decode(Int64.self, forKey: .expectedVersion))
}
public func validate() throws {
if self.expectedVersion < 1 { throw ContractValidationError(field: "expected_version", code: "minimum") }
}
public static func decodeJSON(_ data: Data) throws -> Self { try rejectDuplicateJSONKeys(data); return try JSONDecoder().decode(Self.self, from: data) }
public func encodeJSON() throws -> Data { try validate(); return try JSONEncoder().encode(self) }
}
public struct DisplayMode: Codable, Equatable {
public let resolutionWidth: Int64
public let resolutionHeight: Int64
public let fps: Int64
enum CodingKeys: String, CodingKey {
case resolutionWidth = "resolution_width"
case resolutionHeight = "resolution_height"
case fps = "fps"
}
public init(resolutionWidth: Int64, resolutionHeight: Int64, fps: Int64) throws {
self.resolutionWidth = resolutionWidth
self.resolutionHeight = resolutionHeight
self.fps = fps
try validate()
}
public init(from decoder: Decoder) throws {
let all = try decoder.container(keyedBy: AnyCodingKey.self)
for key in all.allKeys where CodingKeys(stringValue: key.stringValue) == nil { throw ContractValidationError(field: key.stringValue, code: "unknown_field") }
let c = try decoder.container(keyedBy: CodingKeys.self)
try self.init(resolutionWidth: try c.decode(Int64.self, forKey: .resolutionWidth), resolutionHeight: try c.decode(Int64.self, forKey: .resolutionHeight), fps: try c.decode(Int64.self, forKey: .fps))
}
public func validate() throws {
if self.resolutionWidth < 320 { throw ContractValidationError(field: "resolution_width", code: "minimum") }
if self.resolutionWidth > 16384 { throw ContractValidationError(field: "resolution_width", code: "maximum") }
if self.resolutionHeight < 200 { throw ContractValidationError(field: "resolution_height", code: "minimum") }
if self.resolutionHeight > 8640 { throw ContractValidationError(field: "resolution_height", code: "maximum") }
if self.fps < 1 { throw ContractValidationError(field: "fps", code: "minimum") }
if self.fps > 240 { throw ContractValidationError(field: "fps", code: "maximum") }
}
public static func decodeJSON(_ data: Data) throws -> Self { try rejectDuplicateJSONKeys(data); return try JSONDecoder().decode(Self.self, from: data) }
public func encodeJSON() throws -> Data { try validate(); return try JSONEncoder().encode(self) }
}
public struct EntitledPool: Codable, Equatable {
public let poolId: String
public let name: String
public let assignmentState: String
public let qualityLimits: SessionQualityLimits
enum CodingKeys: String, CodingKey {
case poolId = "pool_id"
case name = "name"
case assignmentState = "assignment_state"
case qualityLimits = "quality_limits"
}
public init(poolId: String, name: String, assignmentState: String, qualityLimits: SessionQualityLimits) throws {
self.poolId = poolId
self.name = name
self.assignmentState = assignmentState
self.qualityLimits = qualityLimits
try validate()
}
public init(from decoder: Decoder) throws {
let all = try decoder.container(keyedBy: AnyCodingKey.self)
for key in all.allKeys where CodingKeys(stringValue: key.stringValue) == nil { throw ContractValidationError(field: key.stringValue, code: "unknown_field") }
let c = try decoder.container(keyedBy: CodingKeys.self)
try self.init(poolId: try c.decode(String.self, forKey: .poolId), name: try c.decode(String.self, forKey: .name), assignmentState: try c.decode(String.self, forKey: .assignmentState), qualityLimits: try c.decode(SessionQualityLimits.self, forKey: .qualityLimits))
}
public func validate() throws {
if self.poolId.isEmpty { throw ContractValidationError(field: "pool_id", code: "required") }
if !self.poolId.isEmpty && self.poolId.utf8.count < 1 { throw ContractValidationError(field: "pool_id", code: "min_length") }
if self.poolId.utf8.count > 128 { throw ContractValidationError(field: "pool_id", code: "max_length") }
if self.name.isEmpty { throw ContractValidationError(field: "name", code: "required") }
if !self.name.isEmpty && self.name.utf8.count < 1 { throw ContractValidationError(field: "name", code: "min_length") }
if self.name.utf8.count > 256 { throw ContractValidationError(field: "name", code: "max_length") }
if self.assignmentState.isEmpty { throw ContractValidationError(field: "assignment_state", code: "required") }
if !self.assignmentState.isEmpty && self.assignmentState.utf8.count < 1 { throw ContractValidationError(field: "assignment_state", code: "min_length") }
if self.assignmentState.utf8.count > 64 { throw ContractValidationError(field: "assignment_state", code: "max_length") }
try self.qualityLimits.validate()
}
public static func decodeJSON(_ data: Data) throws -> Self { try rejectDuplicateJSONKeys(data); return try JSONDecoder().decode(Self.self, from: data) }
public func encodeJSON() throws -> Data { try validate(); return try JSONEncoder().encode(self) }
}
public struct ErrorEnvelope: Codable, Equatable {
public let status: Bool
public let error: String
public let code: String
public let message: String
public let resolution: String
public let requestId: String
public let violations: [FieldViolation]
enum CodingKeys: String, CodingKey {
case status = "status"
case error = "error"
case code = "code"
case message = "message"
case resolution = "resolution"
case requestId = "request_id"
case violations = "violations"
}
public init(status: Bool, error: String, code: String, message: String, resolution: String, requestId: String, violations: [FieldViolation]) throws {
self.status = status
self.error = error
self.code = code
self.message = message
self.resolution = resolution
self.requestId = requestId
self.violations = violations
try validate()
}
public init(from decoder: Decoder) throws {
let all = try decoder.container(keyedBy: AnyCodingKey.self)
for key in all.allKeys where CodingKeys(stringValue: key.stringValue) == nil { throw ContractValidationError(field: key.stringValue, code: "unknown_field") }
let c = try decoder.container(keyedBy: CodingKeys.self)
try self.init(status: try c.decode(Bool.self, forKey: .status), error: try c.decode(String.self, forKey: .error), code: try c.decode(String.self, forKey: .code), message: try c.decode(String.self, forKey: .message), resolution: try c.decode(String.self, forKey: .resolution), requestId: try c.decode(String.self, forKey: .requestId), violations: try c.decode([FieldViolation].self, forKey: .violations))
}
public func validate() throws {
if self.error.isEmpty { throw ContractValidationError(field: "error", code: "required") }
if !self.error.isEmpty && self.error.utf8.count < 1 { throw ContractValidationError(field: "error", code: "min_length") }
if self.error.utf8.count > 512 { throw ContractValidationError(field: "error", code: "max_length") }
if self.code.isEmpty { throw ContractValidationError(field: "code", code: "required") }
if !self.code.isEmpty && self.code.utf8.count < 1 { throw ContractValidationError(field: "code", code: "min_length") }
if self.code.utf8.count > 128 { throw ContractValidationError(field: "code", code: "max_length") }
if self.message.isEmpty { throw ContractValidationError(field: "message", code: "required") }
if !self.message.isEmpty && self.message.utf8.count < 1 { throw ContractValidationError(field: "message", code: "min_length") }
if self.message.utf8.count > 512 { throw ContractValidationError(field: "message", code: "max_length") }
if self.resolution.isEmpty { throw ContractValidationError(field: "resolution", code: "required") }
if !self.resolution.isEmpty && self.resolution.utf8.count < 1 { throw ContractValidationError(field: "resolution", code: "min_length") }
if self.resolution.utf8.count > 128 { throw ContractValidationError(field: "resolution", code: "max_length") }
if self.requestId.isEmpty { throw ContractValidationError(field: "request_id", code: "required") }
if !self.requestId.isEmpty && self.requestId.utf8.count < 1 { throw ContractValidationError(field: "request_id", code: "min_length") }
if self.requestId.utf8.count > 128 { throw ContractValidationError(field: "request_id", code: "max_length") }
if self.violations.count > 16 { throw ContractValidationError(field: "violations", code: "max_items") }
for item in self.violations { try item.validate() }
}
public static func decodeJSON(_ data: Data) throws -> Self { try rejectDuplicateJSONKeys(data); return try JSONDecoder().decode(Self.self, from: data) }
public func encodeJSON() throws -> Data { try validate(); return try JSONEncoder().encode(self) }
}
public struct EventEnvelope: Codable, Equatable {
public let eventId: String
public let sequence: Int64
public let type: String
public let version: Int64
public let resource: ResourceLink
public let occurredAt: String
public let correlationId: String
public let payload: JSONObject
enum CodingKeys: String, CodingKey {
case eventId = "event_id"
case sequence = "sequence"
case type = "type"
case version = "version"
case resource = "resource"
case occurredAt = "occurred_at"
case correlationId = "correlation_id"
case payload = "payload"
}
public init(eventId: String, sequence: Int64, type: String, version: Int64, resource: ResourceLink, occurredAt: String, correlationId: String, payload: JSONObject) throws {
self.eventId = eventId
self.sequence = sequence
self.type = type
self.version = version
self.resource = resource
self.occurredAt = occurredAt
self.correlationId = correlationId
self.payload = payload
try validate()
}
public init(from decoder: Decoder) throws {
let all = try decoder.container(keyedBy: AnyCodingKey.self)
for key in all.allKeys where CodingKeys(stringValue: key.stringValue) == nil { throw ContractValidationError(field: key.stringValue, code: "unknown_field") }
let c = try decoder.container(keyedBy: CodingKeys.self)
try self.init(eventId: try c.decode(String.self, forKey: .eventId), sequence: try c.decode(Int64.self, forKey: .sequence), type: try c.decode(String.self, forKey: .type), version: try c.decode(Int64.self, forKey: .version), resource: try c.decode(ResourceLink.self, forKey: .resource), occurredAt: try c.decode(String.self, forKey: .occurredAt), correlationId: try c.decode(String.self, forKey: .correlationId), payload: try c.decode(JSONObject.self, forKey: .payload))
}
public func validate() throws {
if self.eventId.isEmpty { throw ContractValidationError(field: "event_id", code: "required") }
if !self.eventId.isEmpty && self.eventId.utf8.count < 1 { throw ContractValidationError(field: "event_id", code: "min_length") }
if self.eventId.utf8.count > 128 { throw ContractValidationError(field: "event_id", code: "max_length") }
if self.sequence < 1 { throw ContractValidationError(field: "sequence", code: "minimum") }
if self.type.isEmpty { throw ContractValidationError(field: "type", code: "required") }
if !self.type.isEmpty && self.type.utf8.count < 1 { throw ContractValidationError(field: "type", code: "min_length") }
if self.type.utf8.count > 128 { throw ContractValidationError(field: "type", code: "max_length") }
if self.version < 1 { throw ContractValidationError(field: "version", code: "minimum") }
try self.resource.validate()
if self.occurredAt.utf8.count > 64 { throw ContractValidationError(field: "occurred_at", code: "max_length") }
if !validRFC3339UTC(self.occurredAt) { throw ContractValidationError(field: "occurred_at", code: "invalid_time") }
if self.correlationId.isEmpty { throw ContractValidationError(field: "correlation_id", code: "required") }
if !self.correlationId.isEmpty && self.correlationId.utf8.count < 1 { throw ContractValidationError(field: "correlation_id", code: "min_length") }
if self.correlationId.utf8.count > 128 { throw ContractValidationError(field: "correlation_id", code: "max_length") }
}
public static func decodeJSON(_ data: Data) throws -> Self { try rejectDuplicateJSONKeys(data); return try JSONDecoder().decode(Self.self, from: data) }
public func encodeJSON() throws -> Data { try validate(); return try JSONEncoder().encode(self) }
}
public struct EventResume: Codable, Equatable {
public let cursor: String
public let lastSequence: Int64
enum CodingKeys: String, CodingKey {
case cursor = "cursor"
case lastSequence = "last_sequence"
}
public init(cursor: String, lastSequence: Int64) throws {
self.cursor = cursor
self.lastSequence = lastSequence
try validate()
}
public init(from decoder: Decoder) throws {
let all = try decoder.container(keyedBy: AnyCodingKey.self)
for key in all.allKeys where CodingKeys(stringValue: key.stringValue) == nil { throw ContractValidationError(field: key.stringValue, code: "unknown_field") }
let c = try decoder.container(keyedBy: CodingKeys.self)
try self.init(cursor: try c.decode(String.self, forKey: .cursor), lastSequence: try c.decode(Int64.self, forKey: .lastSequence))
}
public func validate() throws {
if self.cursor.utf8.count > 512 { throw ContractValidationError(field: "cursor", code: "max_length") }
if self.lastSequence < 0 { throw ContractValidationError(field: "last_sequence", code: "minimum") }
}
public static func decodeJSON(_ data: Data) throws -> Self { try rejectDuplicateJSONKeys(data); return try JSONDecoder().decode(Self.self, from: data) }
public func encodeJSON() throws -> Data { try validate(); return try JSONEncoder().encode(self) }
}
public struct FieldViolation: Codable, Equatable {
public let field: String
public let code: String
enum CodingKeys: String, CodingKey {
case field = "field"
case code = "code"
}
public init(field: String, code: String) throws {
self.field = field
self.code = code
try validate()
}
public init(from decoder: Decoder) throws {
let all = try decoder.container(keyedBy: AnyCodingKey.self)
for key in all.allKeys where CodingKeys(stringValue: key.stringValue) == nil { throw ContractValidationError(field: key.stringValue, code: "unknown_field") }
let c = try decoder.container(keyedBy: CodingKeys.self)
try self.init(field: try c.decode(String.self, forKey: .field), code: try c.decode(String.self, forKey: .code))
}
public func validate() throws {
if self.field.isEmpty { throw ContractValidationError(field: "field", code: "required") }
if !self.field.isEmpty && self.field.utf8.count < 1 { throw ContractValidationError(field: "field", code: "min_length") }
if self.field.utf8.count > 128 { throw ContractValidationError(field: "field", code: "max_length") }
if self.code.isEmpty { throw ContractValidationError(field: "code", code: "required") }
if !self.code.isEmpty && self.code.utf8.count < 1 { throw ContractValidationError(field: "code", code: "min_length") }
if self.code.utf8.count > 64 { throw ContractValidationError(field: "code", code: "max_length") }
}
public static func decodeJSON(_ data: Data) throws -> Self { try rejectDuplicateJSONKeys(data); return try JSONDecoder().decode(Self.self, from: data) }
public func encodeJSON() throws -> Data { try validate(); return try JSONEncoder().encode(self) }
}
public struct GatewayClipboardAudit: Codable, Equatable {
public let version: String
public let sessionId: String
public let direction: String
public let outcome: String
public let textBytes: Int64
public let reason: String
enum CodingKeys: String, CodingKey {
case version = "version"
case sessionId = "session_id"
case direction = "direction"
case outcome = "outcome"
case textBytes = "text_bytes"
case reason = "reason"
}
public init(version: String, sessionId: String, direction: String, outcome: String, textBytes: Int64, reason: String) throws {
self.version = version
self.sessionId = sessionId
self.direction = direction
self.outcome = outcome
self.textBytes = textBytes
self.reason = reason
try validate()
}
public init(from decoder: Decoder) throws {
let all = try decoder.container(keyedBy: AnyCodingKey.self)
for key in all.allKeys where CodingKeys(stringValue: key.stringValue) == nil { throw ContractValidationError(field: key.stringValue, code: "unknown_field") }
let c = try decoder.container(keyedBy: CodingKeys.self)
try self.init(version: try c.decode(String.self, forKey: .version), sessionId: try c.decode(String.self, forKey: .sessionId), direction: try c.decode(String.self, forKey: .direction), outcome: try c.decode(String.self, forKey: .outcome), textBytes: try c.decode(Int64.self, forKey: .textBytes), reason: try c.decode(String.self, forKey: .reason))
}
public func validate() throws {
if self.version != "1" { throw ContractValidationError(field: "version", code: "invalid_value") }
if self.sessionId.isEmpty { throw ContractValidationError(field: "session_id", code: "required") }
if !self.sessionId.isEmpty && self.sessionId.utf8.count < 1 { throw ContractValidationError(field: "session_id", code: "min_length") }
if self.sessionId.utf8.count > 128 { throw ContractValidationError(field: "session_id", code: "max_length") }
if !["client_to_provider", "provider_to_client"].contains(self.direction) { throw ContractValidationError(field: "direction", code: "invalid_value") }
if !["forwarded", "suppressed", "rejected"].contains(self.outcome) { throw ContractValidationError(field: "outcome", code: "invalid_value") }
if self.textBytes < 0 { throw ContractValidationError(field: "text_bytes", code: "minimum") }
if self.textBytes > 65536 { throw ContractValidationError(field: "text_bytes", code: "maximum") }
if !["forwarded", "loop", "policy", "rate", "provider", "malformed"].contains(self.reason) { throw ContractValidationError(field: "reason", code: "invalid_value") }
}
public static func decodeJSON(_ data: Data) throws -> Self { try rejectDuplicateJSONKeys(data); return try JSONDecoder().decode(Self.self, from: data) }
public func encodeJSON() throws -> Data { try validate(); return try JSONEncoder().encode(self) }
}
public struct GatewayClipboardText: Codable, Equatable {
public let direction: String
public let text: String
public let encoding: String
public let loopToken: String
enum CodingKeys: String, CodingKey {
case direction = "direction"
case text = "text"
case encoding = "encoding"
case loopToken = "loop_token"
}
public init(direction: String, text: String, encoding: String, loopToken: String) throws {
self.direction = direction
self.text = text
self.encoding = encoding
self.loopToken = loopToken
try validate()
}
public init(from decoder: Decoder) throws {
let all = try decoder.container(keyedBy: AnyCodingKey.self)
for key in all.allKeys where CodingKeys(stringValue: key.stringValue) == nil { throw ContractValidationError(field: key.stringValue, code: "unknown_field") }
let c = try decoder.container(keyedBy: CodingKeys.self)
try self.init(direction: try c.decode(String.self, forKey: .direction), text: try c.decode(String.self, forKey: .text), encoding: try c.decode(String.self, forKey: .encoding), loopToken: try c.decode(String.self, forKey: .loopToken))
}
public func validate() throws {
if !["client_to_provider", "provider_to_client"].contains(self.direction) { throw ContractValidationError(field: "direction", code: "invalid_value") }
if self.text.utf8.count > 65536 { throw ContractValidationError(field: "text", code: "max_length") }
if self.text.utf8.count > 65536 { throw ContractValidationError(field: "text", code: "max_bytes") }
if self.encoding != "utf-8" { throw ContractValidationError(field: "encoding", code: "invalid_value") }
if self.loopToken.isEmpty { throw ContractValidationError(field: "loop_token", code: "required") }
if !self.loopToken.isEmpty && self.loopToken.utf8.count < 16 { throw ContractValidationError(field: "loop_token", code: "min_length") }
if self.loopToken.utf8.count > 128 { throw ContractValidationError(field: "loop_token", code: "max_length") }
if !validBase64URL(self.loopToken) { throw ContractValidationError(field: "loop_token", code: "invalid_format") }
}
public static func decodeJSON(_ data: Data) throws -> Self { try rejectDuplicateJSONKeys(data); return try JSONDecoder().decode(Self.self, from: data) }
public func encodeJSON() throws -> Data { try validate(); return try JSONEncoder().encode(self) }
}
public struct GatewayDrain: Codable, Equatable {
public let version: String
public let gatewayId: String
public let sequence: Int64
public let reason: String
public let deadline: String
enum CodingKeys: String, CodingKey {
case version = "version"
case gatewayId = "gateway_id"
case sequence = "sequence"
case reason = "reason"
case deadline = "deadline"
}
public init(version: String, gatewayId: String, sequence: Int64, reason: String, deadline: String) throws {
self.version = version
self.gatewayId = gatewayId
self.sequence = sequence
self.reason = reason
self.deadline = deadline
try validate()
}
public init(from decoder: Decoder) throws {
let all = try decoder.container(keyedBy: AnyCodingKey.self)
for key in all.allKeys where CodingKeys(stringValue: key.stringValue) == nil { throw ContractValidationError(field: key.stringValue, code: "unknown_field") }
let c = try decoder.container(keyedBy: CodingKeys.self)
try self.init(version: try c.decode(String.self, forKey: .version), gatewayId: try c.decode(String.self, forKey: .gatewayId), sequence: try c.decode(Int64.self, forKey: .sequence), reason: try c.decode(String.self, forKey: .reason), deadline: try c.decode(String.self, forKey: .deadline))
}
public func validate() throws {
if self.version != "1" { throw ContractValidationError(field: "version", code: "invalid_value") }
if self.gatewayId.isEmpty { throw ContractValidationError(field: "gateway_id", code: "required") }
if !self.gatewayId.isEmpty && self.gatewayId.utf8.count < 1 { throw ContractValidationError(field: "gateway_id", code: "min_length") }
if self.gatewayId.utf8.count > 128 { throw ContractValidationError(field: "gateway_id", code: "max_length") }
if self.sequence < 1 { throw ContractValidationError(field: "sequence", code: "minimum") }
if self.reason.isEmpty { throw ContractValidationError(field: "reason", code: "required") }
if !self.reason.isEmpty && self.reason.utf8.count < 1 { throw ContractValidationError(field: "reason", code: "min_length") }
if self.reason.utf8.count > 256 { throw ContractValidationError(field: "reason", code: "max_length") }
if self.deadline.utf8.count > 64 { throw ContractValidationError(field: "deadline", code: "max_length") }
if !validRFC3339UTC(self.deadline) { throw ContractValidationError(field: "deadline", code: "invalid_time") }
}
public static func decodeJSON(_ data: Data) throws -> Self { try rejectDuplicateJSONKeys(data); return try JSONDecoder().decode(Self.self, from: data) }
public func encodeJSON() throws -> Data { try validate(); return try JSONEncoder().encode(self) }
}
public struct GatewayHeartbeat: Codable, Equatable {
public let version: String
public let gatewayId: String
public let sequence: Int64
public let observedAt: String
public let activeConnections: Int64
public let egressKbps: Int64
public let state: String
public let telemetry: GatewayTelemetry
enum CodingKeys: String, CodingKey {
case version = "version"
case gatewayId = "gateway_id"
case sequence = "sequence"
case observedAt = "observed_at"
case activeConnections = "active_connections"
case egressKbps = "egress_kbps"
case state = "state"
case telemetry = "telemetry"
}
public init(version: String, gatewayId: String, sequence: Int64, observedAt: String, activeConnections: Int64, egressKbps: Int64, state: String, telemetry: GatewayTelemetry) throws {
self.version = version
self.gatewayId = gatewayId
self.sequence = sequence
self.observedAt = observedAt
self.activeConnections = activeConnections
self.egressKbps = egressKbps
self.state = state
self.telemetry = telemetry
try validate()
}
public init(from decoder: Decoder) throws {
let all = try decoder.container(keyedBy: AnyCodingKey.self)
for key in all.allKeys where CodingKeys(stringValue: key.stringValue) == nil { throw ContractValidationError(field: key.stringValue, code: "unknown_field") }
let c = try decoder.container(keyedBy: CodingKeys.self)
try self.init(version: try c.decode(String.self, forKey: .version), gatewayId: try c.decode(String.self, forKey: .gatewayId), sequence: try c.decode(Int64.self, forKey: .sequence), observedAt: try c.decode(String.self, forKey: .observedAt), activeConnections: try c.decode(Int64.self, forKey: .activeConnections), egressKbps: try c.decode(Int64.self, forKey: .egressKbps), state: try c.decode(String.self, forKey: .state), telemetry: try c.decode(GatewayTelemetry.self, forKey: .telemetry))
}
public func validate() throws {
if self.version != "1" { throw ContractValidationError(field: "version", code: "invalid_value") }
if self.gatewayId.isEmpty { throw ContractValidationError(field: "gateway_id", code: "required") }
if !self.gatewayId.isEmpty && self.gatewayId.utf8.count < 1 { throw ContractValidationError(field: "gateway_id", code: "min_length") }
if self.gatewayId.utf8.count > 128 { throw ContractValidationError(field: "gateway_id", code: "max_length") }
if self.sequence < 1 { throw ContractValidationError(field: "sequence", code: "minimum") }
if self.observedAt.utf8.count > 64 { throw ContractValidationError(field: "observed_at", code: "max_length") }
if !validRFC3339UTC(self.observedAt) { throw ContractValidationError(field: "observed_at", code: "invalid_time") }
if self.activeConnections < 0 { throw ContractValidationError(field: "active_connections", code: "minimum") }
if self.activeConnections > 1000000 { throw ContractValidationError(field: "active_connections", code: "maximum") }
if self.egressKbps < 0 { throw ContractValidationError(field: "egress_kbps", code: "minimum") }
if self.egressKbps > 1000000000 { throw ContractValidationError(field: "egress_kbps", code: "maximum") }
if !["ready", "draining", "offline"].contains(self.state) { throw ContractValidationError(field: "state", code: "invalid_value") }
try self.telemetry.validate()
}
public static func decodeJSON(_ data: Data) throws -> Self { try rejectDuplicateJSONKeys(data); return try JSONDecoder().decode(Self.self, from: data) }
public func encodeJSON() throws -> Data { try validate(); return try JSONEncoder().encode(self) }
}
public struct GatewayQualityAck: Codable, Equatable {
public let version: String
public let sessionId: String
public let gatewayId: String
public let reconnectSequence: Int64
public let operationId: String
public let revision: Int64
public let leaseGeneration: Int64
public let outcome: String
public let currentAppliedRevision: Int64?
public let failureCode: String?
enum CodingKeys: String, CodingKey {
case version = "version"
case sessionId = "session_id"
case gatewayId = "gateway_id"
case reconnectSequence = "reconnect_sequence"
case operationId = "operation_id"
case revision = "revision"
case leaseGeneration = "lease_generation"
case outcome = "outcome"
case currentAppliedRevision = "current_applied_revision"
case failureCode = "failure_code"
}
public init(version: String, sessionId: String, gatewayId: String, reconnectSequence: Int64, operationId: String, revision: Int64, leaseGeneration: Int64, outcome: String, currentAppliedRevision: Int64?, failureCode: String?) throws {
self.version = version
self.sessionId = sessionId
self.gatewayId = gatewayId
self.reconnectSequence = reconnectSequence
self.operationId = operationId
self.revision = revision
self.leaseGeneration = leaseGeneration
self.outcome = outcome
self.currentAppliedRevision = currentAppliedRevision
self.failureCode = failureCode
try validate()
}
public init(from decoder: Decoder) throws {
let all = try decoder.container(keyedBy: AnyCodingKey.self)
for key in all.allKeys where CodingKeys(stringValue: key.stringValue) == nil { throw ContractValidationError(field: key.stringValue, code: "unknown_field") }
let c = try decoder.container(keyedBy: CodingKeys.self)
try self.init(version: try c.decode(String.self, forKey: .version), sessionId: try c.decode(String.self, forKey: .sessionId), gatewayId: try c.decode(String.self, forKey: .gatewayId), reconnectSequence: try c.decode(Int64.self, forKey: .reconnectSequence), operationId: try c.decode(String.self, forKey: .operationId), revision: try c.decode(Int64.self, forKey: .revision), leaseGeneration: try c.decode(Int64.self, forKey: .leaseGeneration), outcome: try c.decode(String.self, forKey: .outcome), currentAppliedRevision: try c.decodeIfPresent(Int64.self, forKey: .currentAppliedRevision), failureCode: try c.decodeIfPresent(String.self, forKey: .failureCode))
}
public func validate() throws {
if self.version != "1" { throw ContractValidationError(field: "version", code: "invalid_value") }
if self.sessionId.isEmpty { throw ContractValidationError(field: "session_id", code: "required") }
if !self.sessionId.isEmpty && self.sessionId.utf8.count < 1 { throw ContractValidationError(field: "session_id", code: "min_length") }
if self.sessionId.utf8.count > 128 { throw ContractValidationError(field: "session_id", code: "max_length") }
if self.gatewayId.isEmpty { throw ContractValidationError(field: "gateway_id", code: "required") }
if !self.gatewayId.isEmpty && self.gatewayId.utf8.count < 1 { throw ContractValidationError(field: "gateway_id", code: "min_length") }
if self.gatewayId.utf8.count > 128 { throw ContractValidationError(field: "gateway_id", code: "max_length") }
if self.reconnectSequence < 0 { throw ContractValidationError(field: "reconnect_sequence", code: "minimum") }
if self.operationId.isEmpty { throw ContractValidationError(field: "operation_id", code: "required") }
if !self.operationId.isEmpty && self.operationId.utf8.count < 36 { throw ContractValidationError(field: "operation_id", code: "min_length") }
if self.operationId.utf8.count > 36 { throw ContractValidationError(field: "operation_id", code: "max_length") }
if !validCanonicalUUID(self.operationId) { throw ContractValidationError(field: "operation_id", code: "invalid_uuid") }
if self.revision < 1 { throw ContractValidationError(field: "revision", code: "minimum") }
if self.leaseGeneration < 1 { throw ContractValidationError(field: "lease_generation", code: "minimum") }
if !["applied", "proven_prior", "unknown"].contains(self.outcome) { throw ContractValidationError(field: "outcome", code: "invalid_value") }
if let value = self.currentAppliedRevision {
if value < 0 { throw ContractValidationError(field: "current_applied_revision", code: "minimum") }
}
if let value = self.failureCode {
if !value.isEmpty && value.utf8.count < 1 { throw ContractValidationError(field: "failure_code", code: "min_length") }
if value.utf8.count > 128 { throw ContractValidationError(field: "failure_code", code: "max_length") }
}
if outcome == "applied" && currentAppliedRevision != revision { throw ContractValidationError(field: "current_applied_revision", code: "invalid_tagged_value") }
if outcome == "proven_prior" && (currentAppliedRevision == nil || currentAppliedRevision! >= revision) { throw ContractValidationError(field: "current_applied_revision", code: "invalid_tagged_value") }
if outcome == "unknown" && currentAppliedRevision != nil { throw ContractValidationError(field: "current_applied_revision", code: "invalid_tagged_value") }
}
public static func decodeJSON(_ data: Data) throws -> Self { try rejectDuplicateJSONKeys(data); return try JSONDecoder().decode(Self.self, from: data) }
public func encodeJSON() throws -> Data { try validate(); return try JSONEncoder().encode(self) }
}
public struct GatewayQualityWork: Codable, Equatable {
public let version: String
public let sessionId: String
public let gatewayId: String
public let reconnectSequence: Int64
public let operationId: String
public let revision: Int64
public let leaseGeneration: Int64
public let leaseExpiresAt: String
public let selectedDescriptor: SelectedSessionDescriptor
public let currentAppliedRevision: Int64?
enum CodingKeys: String, CodingKey {
case version = "version"
case sessionId = "session_id"
case gatewayId = "gateway_id"
case reconnectSequence = "reconnect_sequence"
case operationId = "operation_id"
case revision = "revision"
case leaseGeneration = "lease_generation"
case leaseExpiresAt = "lease_expires_at"
case selectedDescriptor = "selected_descriptor"
case currentAppliedRevision = "current_applied_revision"
}
public init(version: String, sessionId: String, gatewayId: String, reconnectSequence: Int64, operationId: String, revision: Int64, leaseGeneration: Int64, leaseExpiresAt: String, selectedDescriptor: SelectedSessionDescriptor, currentAppliedRevision: Int64?) throws {
self.version = version
self.sessionId = sessionId
self.gatewayId = gatewayId
self.reconnectSequence = reconnectSequence
self.operationId = operationId
self.revision = revision
self.leaseGeneration = leaseGeneration
self.leaseExpiresAt = leaseExpiresAt
self.selectedDescriptor = selectedDescriptor
self.currentAppliedRevision = currentAppliedRevision
try validate()
}
public init(from decoder: Decoder) throws {
let all = try decoder.container(keyedBy: AnyCodingKey.self)
for key in all.allKeys where CodingKeys(stringValue: key.stringValue) == nil { throw ContractValidationError(field: key.stringValue, code: "unknown_field") }
let c = try decoder.container(keyedBy: CodingKeys.self)
try self.init(version: try c.decode(String.self, forKey: .version), sessionId: try c.decode(String.self, forKey: .sessionId), gatewayId: try c.decode(String.self, forKey: .gatewayId), reconnectSequence: try c.decode(Int64.self, forKey: .reconnectSequence), operationId: try c.decode(String.self, forKey: .operationId), revision: try c.decode(Int64.self, forKey: .revision), leaseGeneration: try c.decode(Int64.self, forKey: .leaseGeneration), leaseExpiresAt: try c.decode(String.self, forKey: .leaseExpiresAt), selectedDescriptor: try c.decode(SelectedSessionDescriptor.self, forKey: .selectedDescriptor), currentAppliedRevision: try c.decodeIfPresent(Int64.self, forKey: .currentAppliedRevision))
}
public func validate() throws {
if self.version != "1" { throw ContractValidationError(field: "version", code: "invalid_value") }
if self.sessionId.isEmpty { throw ContractValidationError(field: "session_id", code: "required") }
if !self.sessionId.isEmpty && self.sessionId.utf8.count < 1 { throw ContractValidationError(field: "session_id", code: "min_length") }
if self.sessionId.utf8.count > 128 { throw ContractValidationError(field: "session_id", code: "max_length") }
if self.gatewayId.isEmpty { throw ContractValidationError(field: "gateway_id", code: "required") }
if !self.gatewayId.isEmpty && self.gatewayId.utf8.count < 1 { throw ContractValidationError(field: "gateway_id", code: "min_length") }
if self.gatewayId.utf8.count > 128 { throw ContractValidationError(field: "gateway_id", code: "max_length") }
if self.reconnectSequence < 0 { throw ContractValidationError(field: "reconnect_sequence", code: "minimum") }
if self.operationId.isEmpty { throw ContractValidationError(field: "operation_id", code: "required") }
if !self.operationId.isEmpty && self.operationId.utf8.count < 36 { throw ContractValidationError(field: "operation_id", code: "min_length") }
if self.operationId.utf8.count > 36 { throw ContractValidationError(field: "operation_id", code: "max_length") }
if !validCanonicalUUID(self.operationId) { throw ContractValidationError(field: "operation_id", code: "invalid_uuid") }
if self.revision < 1 { throw ContractValidationError(field: "revision", code: "minimum") }
if self.leaseGeneration < 1 { throw ContractValidationError(field: "lease_generation", code: "minimum") }
if self.leaseExpiresAt.utf8.count > 64 { throw ContractValidationError(field: "lease_expires_at", code: "max_length") }
if !validRFC3339UTC(self.leaseExpiresAt) { throw ContractValidationError(field: "lease_expires_at", code: "invalid_time") }
try self.selectedDescriptor.validate()
if let value = self.currentAppliedRevision {
if value < 0 { throw ContractValidationError(field: "current_applied_revision", code: "minimum") }
}
}
public static func decodeJSON(_ data: Data) throws -> Self { try rejectDuplicateJSONKeys(data); return try JSONDecoder().decode(Self.self, from: data) }
public func encodeJSON() throws -> Data { try validate(); return try JSONEncoder().encode(self) }
}
public struct GatewayQualityWorkRequest: Codable, Equatable {
public let version: String
public let sessionId: String
public let gatewayId: String
public let reconnectSequence: Int64
public let acquisition: String
public let operationId: String?
public let revision: Int64?
public let leaseGeneration: Int64?
public let currentAppliedRevision: Int64?
enum CodingKeys: String, CodingKey {
case version = "version"
case sessionId = "session_id"
case gatewayId = "gateway_id"
case reconnectSequence = "reconnect_sequence"
case acquisition = "acquisition"
case operationId = "operation_id"
case revision = "revision"
case leaseGeneration = "lease_generation"
case currentAppliedRevision = "current_applied_revision"
}
public init(version: String, sessionId: String, gatewayId: String, reconnectSequence: Int64, acquisition: String, operationId: String?, revision: Int64?, leaseGeneration: Int64?, currentAppliedRevision: Int64?) throws {
self.version = version
self.sessionId = sessionId
self.gatewayId = gatewayId
self.reconnectSequence = reconnectSequence
self.acquisition = acquisition
self.operationId = operationId
self.revision = revision
self.leaseGeneration = leaseGeneration
self.currentAppliedRevision = currentAppliedRevision
try validate()
}
public init(from decoder: Decoder) throws {
let all = try decoder.container(keyedBy: AnyCodingKey.self)
for key in all.allKeys where CodingKeys(stringValue: key.stringValue) == nil { throw ContractValidationError(field: key.stringValue, code: "unknown_field") }
let c = try decoder.container(keyedBy: CodingKeys.self)
try self.init(version: try c.decode(String.self, forKey: .version), sessionId: try c.decode(String.self, forKey: .sessionId), gatewayId: try c.decode(String.self, forKey: .gatewayId), reconnectSequence: try c.decode(Int64.self, forKey: .reconnectSequence), acquisition: try c.decode(String.self, forKey: .acquisition), operationId: try c.decodeIfPresent(String.self, forKey: .operationId), revision: try c.decodeIfPresent(Int64.self, forKey: .revision), leaseGeneration: try c.decodeIfPresent(Int64.self, forKey: .leaseGeneration), currentAppliedRevision: try c.decodeIfPresent(Int64.self, forKey: .currentAppliedRevision))
}
public func validate() throws {
if self.version != "1" { throw ContractValidationError(field: "version", code: "invalid_value") }
if self.sessionId.isEmpty { throw ContractValidationError(field: "session_id", code: "required") }
if !self.sessionId.isEmpty && self.sessionId.utf8.count < 1 { throw ContractValidationError(field: "session_id", code: "min_length") }
if self.sessionId.utf8.count > 128 { throw ContractValidationError(field: "session_id", code: "max_length") }
if self.gatewayId.isEmpty { throw ContractValidationError(field: "gateway_id", code: "required") }
if !self.gatewayId.isEmpty && self.gatewayId.utf8.count < 1 { throw ContractValidationError(field: "gateway_id", code: "min_length") }
if self.gatewayId.utf8.count > 128 { throw ContractValidationError(field: "gateway_id", code: "max_length") }
if self.reconnectSequence < 0 { throw ContractValidationError(field: "reconnect_sequence", code: "minimum") }
if !["poll", "prompt", "observation"].contains(self.acquisition) { throw ContractValidationError(field: "acquisition", code: "invalid_value") }
if let value = self.operationId {
if !value.isEmpty && value.utf8.count < 36 { throw ContractValidationError(field: "operation_id", code: "min_length") }
if value.utf8.count > 36 { throw ContractValidationError(field: "operation_id", code: "max_length") }
if !validCanonicalUUID(value) { throw ContractValidationError(field: "operation_id", code: "invalid_uuid") }
}
if let value = self.revision {
if value < 1 { throw ContractValidationError(field: "revision", code: "minimum") }
}
if let value = self.leaseGeneration {
if value < 1 { throw ContractValidationError(field: "lease_generation", code: "minimum") }
}
if let value = self.currentAppliedRevision {
if value < 0 { throw ContractValidationError(field: "current_applied_revision", code: "minimum") }
}
if acquisition == "poll" && (operationId != nil || revision != nil || leaseGeneration != nil || currentAppliedRevision != nil) { throw ContractValidationError(field: "acquisition", code: "invalid_tagged_value") }
if acquisition == "prompt" && (operationId == nil || revision == nil || leaseGeneration != nil || currentAppliedRevision != nil) { throw ContractValidationError(field: "acquisition", code: "invalid_tagged_value") }
if acquisition == "observation" && (operationId == nil || revision == nil || leaseGeneration == nil || currentAppliedRevision == nil) { throw ContractValidationError(field: "acquisition", code: "invalid_tagged_value") }
}
public static func decodeJSON(_ data: Data) throws -> Self { try rejectDuplicateJSONKeys(data); return try JSONDecoder().decode(Self.self, from: data) }
public func encodeJSON() throws -> Data { try validate(); return try JSONEncoder().encode(self) }
}
public struct GatewayRegistration: Codable, Equatable {
public let version: String
public let gatewayId: String
public let instanceIdentity: String
public let certificateIdentity: String
public let publicIdentity: String
public let address: String
public let providerIdentity: String
public let protocolMinVersion: Int64
public let protocolMaxVersion: Int64
public let connectionCapacity: Int64
public let bandwidthCapacityKbps: Int64
public let features: [String]
public let capabilities: CapabilityProfile
enum CodingKeys: String, CodingKey {
case version = "version"
case gatewayId = "gateway_id"
case instanceIdentity = "instance_identity"
case certificateIdentity = "certificate_identity"
case publicIdentity = "public_identity"
case address = "address"
case providerIdentity = "provider_identity"
case protocolMinVersion = "protocol_min_version"
case protocolMaxVersion = "protocol_max_version"
case connectionCapacity = "connection_capacity"
case bandwidthCapacityKbps = "bandwidth_capacity_kbps"
case features = "features"
case capabilities = "capabilities"
}
public init(version: String, gatewayId: String, instanceIdentity: String, certificateIdentity: String, publicIdentity: String, address: String, providerIdentity: String, protocolMinVersion: Int64, protocolMaxVersion: Int64, connectionCapacity: Int64, bandwidthCapacityKbps: Int64, features: [String], capabilities: CapabilityProfile) throws {
self.version = version
self.gatewayId = gatewayId
self.instanceIdentity = instanceIdentity
self.certificateIdentity = certificateIdentity
self.publicIdentity = publicIdentity
self.address = address
self.providerIdentity = providerIdentity
self.protocolMinVersion = protocolMinVersion
self.protocolMaxVersion = protocolMaxVersion
self.connectionCapacity = connectionCapacity
self.bandwidthCapacityKbps = bandwidthCapacityKbps
self.features = features
self.capabilities = capabilities
try validate()
}
public init(from decoder: Decoder) throws {
let all = try decoder.container(keyedBy: AnyCodingKey.self)
for key in all.allKeys where CodingKeys(stringValue: key.stringValue) == nil { throw ContractValidationError(field: key.stringValue, code: "unknown_field") }
let c = try decoder.container(keyedBy: CodingKeys.self)
try self.init(version: try c.decode(String.self, forKey: .version), gatewayId: try c.decode(String.self, forKey: .gatewayId), instanceIdentity: try c.decode(String.self, forKey: .instanceIdentity), certificateIdentity: try c.decode(String.self, forKey: .certificateIdentity), publicIdentity: try c.decode(String.self, forKey: .publicIdentity), address: try c.decode(String.self, forKey: .address), providerIdentity: try c.decode(String.self, forKey: .providerIdentity), protocolMinVersion: try c.decode(Int64.self, forKey: .protocolMinVersion), protocolMaxVersion: try c.decode(Int64.self, forKey: .protocolMaxVersion), connectionCapacity: try c.decode(Int64.self, forKey: .connectionCapacity), bandwidthCapacityKbps: try c.decode(Int64.self, forKey: .bandwidthCapacityKbps), features: try c.decode([String].self, forKey: .features), capabilities: try c.decode(CapabilityProfile.self, forKey: .capabilities))
}
public func validate() throws {
if self.version != "1" { throw ContractValidationError(field: "version", code: "invalid_value") }
if self.gatewayId.isEmpty { throw ContractValidationError(field: "gateway_id", code: "required") }
if !self.gatewayId.isEmpty && self.gatewayId.utf8.count < 1 { throw ContractValidationError(field: "gateway_id", code: "min_length") }
if self.gatewayId.utf8.count > 128 { throw ContractValidationError(field: "gateway_id", code: "max_length") }
if self.instanceIdentity.isEmpty { throw ContractValidationError(field: "instance_identity", code: "required") }
if !self.instanceIdentity.isEmpty && self.instanceIdentity.utf8.count < 1 { throw ContractValidationError(field: "instance_identity", code: "min_length") }
if self.instanceIdentity.utf8.count > 512 { throw ContractValidationError(field: "instance_identity", code: "max_length") }
if self.certificateIdentity.isEmpty { throw ContractValidationError(field: "certificate_identity", code: "required") }
if !self.certificateIdentity.isEmpty && self.certificateIdentity.utf8.count < 1 { throw ContractValidationError(field: "certificate_identity", code: "min_length") }
if self.certificateIdentity.utf8.count > 512 { throw ContractValidationError(field: "certificate_identity", code: "max_length") }
if self.publicIdentity.isEmpty { throw ContractValidationError(field: "public_identity", code: "required") }
if !self.publicIdentity.isEmpty && self.publicIdentity.utf8.count < 1 { throw ContractValidationError(field: "public_identity", code: "min_length") }
if self.publicIdentity.utf8.count > 256 { throw ContractValidationError(field: "public_identity", code: "max_length") }
if self.address.isEmpty { throw ContractValidationError(field: "address", code: "required") }
if !self.address.isEmpty && self.address.utf8.count < 1 { throw ContractValidationError(field: "address", code: "min_length") }
if self.address.utf8.count > 256 { throw ContractValidationError(field: "address", code: "max_length") }
if self.providerIdentity.isEmpty { throw ContractValidationError(field: "provider_identity", code: "required") }
if !self.providerIdentity.isEmpty && self.providerIdentity.utf8.count < 1 { throw ContractValidationError(field: "provider_identity", code: "min_length") }
if self.providerIdentity.utf8.count > 256 { throw ContractValidationError(field: "provider_identity", code: "max_length") }
if self.protocolMinVersion < 1 { throw ContractValidationError(field: "protocol_min_version", code: "minimum") }
if self.protocolMinVersion > 100 { throw ContractValidationError(field: "protocol_min_version", code: "maximum") }
if self.protocolMaxVersion < 1 { throw ContractValidationError(field: "protocol_max_version", code: "minimum") }
if self.protocolMaxVersion > 100 { throw ContractValidationError(field: "protocol_max_version", code: "maximum") }
if self.connectionCapacity < 1 { throw ContractValidationError(field: "connection_capacity", code: "minimum") }
if self.connectionCapacity > 1000000 { throw ContractValidationError(field: "connection_capacity", code: "maximum") }
if self.bandwidthCapacityKbps < 1 { throw ContractValidationError(field: "bandwidth_capacity_kbps", code: "minimum") }
if self.bandwidthCapacityKbps > 1000000000 { throw ContractValidationError(field: "bandwidth_capacity_kbps", code: "maximum") }
if self.features.count > 64 { throw ContractValidationError(field: "features", code: "max_items") }
for item in self.features where item.utf8.count < 1 { throw ContractValidationError(field: "features", code: "min_item_length") }
for item in self.features where item.utf8.count > 64 { throw ContractValidationError(field: "features", code: "max_item_length") }
try self.capabilities.validate()
if protocolMinVersion > protocolMaxVersion { throw ContractValidationError(field: "protocol_version", code: "invalid_order") }
}
public static func decodeJSON(_ data: Data) throws -> Self { try rejectDuplicateJSONKeys(data); return try JSONDecoder().decode(Self.self, from: data) }
public func encodeJSON() throws -> Data { try validate(); return try JSONEncoder().encode(self) }
}
public struct GatewayStopAck: Codable, Equatable {
public let version: String
public let sessionId: String
public let gatewayId: String
public let reconnectSequence: Int64
public let operationId: String
public let outcome: String
public let failureCode: String?
enum CodingKeys: String, CodingKey {
case version = "version"
case sessionId = "session_id"
case gatewayId = "gateway_id"
case reconnectSequence = "reconnect_sequence"
case operationId = "operation_id"
case outcome = "outcome"
case failureCode = "failure_code"
}
public init(version: String, sessionId: String, gatewayId: String, reconnectSequence: Int64, operationId: String, outcome: String, failureCode: String?) throws {
self.version = version
self.sessionId = sessionId
self.gatewayId = gatewayId
self.reconnectSequence = reconnectSequence
self.operationId = operationId
self.outcome = outcome
self.failureCode = failureCode
try validate()
}
public init(from decoder: Decoder) throws {
let all = try decoder.container(keyedBy: AnyCodingKey.self)
for key in all.allKeys where CodingKeys(stringValue: key.stringValue) == nil { throw ContractValidationError(field: key.stringValue, code: "unknown_field") }
let c = try decoder.container(keyedBy: CodingKeys.self)
try self.init(version: try c.decode(String.self, forKey: .version), sessionId: try c.decode(String.self, forKey: .sessionId), gatewayId: try c.decode(String.self, forKey: .gatewayId), reconnectSequence: try c.decode(Int64.self, forKey: .reconnectSequence), operationId: try c.decode(String.self, forKey: .operationId), outcome: try c.decode(String.self, forKey: .outcome), failureCode: try c.decodeIfPresent(String.self, forKey: .failureCode))
}
public func validate() throws {
if self.version != "1" { throw ContractValidationError(field: "version", code: "invalid_value") }
if self.sessionId.isEmpty { throw ContractValidationError(field: "session_id", code: "required") }
if !self.sessionId.isEmpty && self.sessionId.utf8.count < 1 { throw ContractValidationError(field: "session_id", code: "min_length") }
if self.sessionId.utf8.count > 128 { throw ContractValidationError(field: "session_id", code: "max_length") }
if self.gatewayId.isEmpty { throw ContractValidationError(field: "gateway_id", code: "required") }
if !self.gatewayId.isEmpty && self.gatewayId.utf8.count < 1 { throw ContractValidationError(field: "gateway_id", code: "min_length") }
if self.gatewayId.utf8.count > 128 { throw ContractValidationError(field: "gateway_id", code: "max_length") }
if self.reconnectSequence < 0 { throw ContractValidationError(field: "reconnect_sequence", code: "minimum") }
if self.operationId.isEmpty { throw ContractValidationError(field: "operation_id", code: "required") }
if !self.operationId.isEmpty && self.operationId.utf8.count < 36 { throw ContractValidationError(field: "operation_id", code: "min_length") }
if self.operationId.utf8.count > 36 { throw ContractValidationError(field: "operation_id", code: "max_length") }
if !validCanonicalUUID(self.operationId) { throw ContractValidationError(field: "operation_id", code: "invalid_uuid") }
if !["applied", "failed", "termination_unconfirmed"].contains(self.outcome) { throw ContractValidationError(field: "outcome", code: "invalid_value") }
if let value = self.failureCode {
if !value.isEmpty && value.utf8.count < 1 { throw ContractValidationError(field: "failure_code", code: "min_length") }
if value.utf8.count > 128 { throw ContractValidationError(field: "failure_code", code: "max_length") }
}
}
public static func decodeJSON(_ data: Data) throws -> Self { try rejectDuplicateJSONKeys(data); return try JSONDecoder().decode(Self.self, from: data) }
public func encodeJSON() throws -> Data { try validate(); return try JSONEncoder().encode(self) }
}
public struct GatewayStopWork: Codable, Equatable {
public let version: String
public let sessionId: String
public let gatewayId: String
public let reconnectSequence: Int64
public let operationId: String
public let attempt: Int64
enum CodingKeys: String, CodingKey {
case version = "version"
case sessionId = "session_id"
case gatewayId = "gateway_id"
case reconnectSequence = "reconnect_sequence"
case operationId = "operation_id"
case attempt = "attempt"
}
public init(version: String, sessionId: String, gatewayId: String, reconnectSequence: Int64, operationId: String, attempt: Int64) throws {
self.version = version
self.sessionId = sessionId
self.gatewayId = gatewayId
self.reconnectSequence = reconnectSequence
self.operationId = operationId
self.attempt = attempt
try validate()
}
public init(from decoder: Decoder) throws {
let all = try decoder.container(keyedBy: AnyCodingKey.self)
for key in all.allKeys where CodingKeys(stringValue: key.stringValue) == nil { throw ContractValidationError(field: key.stringValue, code: "unknown_field") }
let c = try decoder.container(keyedBy: CodingKeys.self)
try self.init(version: try c.decode(String.self, forKey: .version), sessionId: try c.decode(String.self, forKey: .sessionId), gatewayId: try c.decode(String.self, forKey: .gatewayId), reconnectSequence: try c.decode(Int64.self, forKey: .reconnectSequence), operationId: try c.decode(String.self, forKey: .operationId), attempt: try c.decode(Int64.self, forKey: .attempt))
}
public func validate() throws {
if self.version != "1" { throw ContractValidationError(field: "version", code: "invalid_value") }
if self.sessionId.isEmpty { throw ContractValidationError(field: "session_id", code: "required") }
if !self.sessionId.isEmpty && self.sessionId.utf8.count < 1 { throw ContractValidationError(field: "session_id", code: "min_length") }
if self.sessionId.utf8.count > 128 { throw ContractValidationError(field: "session_id", code: "max_length") }
if self.gatewayId.isEmpty { throw ContractValidationError(field: "gateway_id", code: "required") }
if !self.gatewayId.isEmpty && self.gatewayId.utf8.count < 1 { throw ContractValidationError(field: "gateway_id", code: "min_length") }
if self.gatewayId.utf8.count > 128 { throw ContractValidationError(field: "gateway_id", code: "max_length") }
if self.reconnectSequence < 0 { throw ContractValidationError(field: "reconnect_sequence", code: "minimum") }
if self.operationId.isEmpty { throw ContractValidationError(field: "operation_id", code: "required") }
if !self.operationId.isEmpty && self.operationId.utf8.count < 36 { throw ContractValidationError(field: "operation_id", code: "min_length") }
if self.operationId.utf8.count > 36 { throw ContractValidationError(field: "operation_id", code: "max_length") }
if !validCanonicalUUID(self.operationId) { throw ContractValidationError(field: "operation_id", code: "invalid_uuid") }
if self.attempt < 1 { throw ContractValidationError(field: "attempt", code: "minimum") }
if self.attempt > 1 { throw ContractValidationError(field: "attempt", code: "maximum") }
}
public static func decodeJSON(_ data: Data) throws -> Self { try rejectDuplicateJSONKeys(data); return try JSONDecoder().decode(Self.self, from: data) }
public func encodeJSON() throws -> Data { try validate(); return try JSONEncoder().encode(self) }
}
public struct GatewayStopWorkRequest: Codable, Equatable {
public let version: String
public let sessionId: String
public let gatewayId: String
public let reconnectSequence: Int64
public let acquisition: String
public let operationId: String?
enum CodingKeys: String, CodingKey {
case version = "version"
case sessionId = "session_id"
case gatewayId = "gateway_id"
case reconnectSequence = "reconnect_sequence"
case acquisition = "acquisition"
case operationId = "operation_id"
}
public init(version: String, sessionId: String, gatewayId: String, reconnectSequence: Int64, acquisition: String, operationId: String?) throws {
self.version = version
self.sessionId = sessionId
self.gatewayId = gatewayId
self.reconnectSequence = reconnectSequence
self.acquisition = acquisition
self.operationId = operationId
try validate()
}
public init(from decoder: Decoder) throws {
let all = try decoder.container(keyedBy: AnyCodingKey.self)
for key in all.allKeys where CodingKeys(stringValue: key.stringValue) == nil { throw ContractValidationError(field: key.stringValue, code: "unknown_field") }
let c = try decoder.container(keyedBy: CodingKeys.self)
try self.init(version: try c.decode(String.self, forKey: .version), sessionId: try c.decode(String.self, forKey: .sessionId), gatewayId: try c.decode(String.self, forKey: .gatewayId), reconnectSequence: try c.decode(Int64.self, forKey: .reconnectSequence), acquisition: try c.decode(String.self, forKey: .acquisition), operationId: try c.decodeIfPresent(String.self, forKey: .operationId))
}
public func validate() throws {
if self.version != "1" { throw ContractValidationError(field: "version", code: "invalid_value") }
if self.sessionId.isEmpty { throw ContractValidationError(field: "session_id", code: "required") }
if !self.sessionId.isEmpty && self.sessionId.utf8.count < 1 { throw ContractValidationError(field: "session_id", code: "min_length") }
if self.sessionId.utf8.count > 128 { throw ContractValidationError(field: "session_id", code: "max_length") }
if self.gatewayId.isEmpty { throw ContractValidationError(field: "gateway_id", code: "required") }
if !self.gatewayId.isEmpty && self.gatewayId.utf8.count < 1 { throw ContractValidationError(field: "gateway_id", code: "min_length") }
if self.gatewayId.utf8.count > 128 { throw ContractValidationError(field: "gateway_id", code: "max_length") }
if self.reconnectSequence < 0 { throw ContractValidationError(field: "reconnect_sequence", code: "minimum") }
if !["poll", "prompt"].contains(self.acquisition) { throw ContractValidationError(field: "acquisition", code: "invalid_value") }
if let value = self.operationId {
if !value.isEmpty && value.utf8.count < 36 { throw ContractValidationError(field: "operation_id", code: "min_length") }
if value.utf8.count > 36 { throw ContractValidationError(field: "operation_id", code: "max_length") }
if !validCanonicalUUID(value) { throw ContractValidationError(field: "operation_id", code: "invalid_uuid") }
}
if acquisition == "poll" && operationId != nil || acquisition == "prompt" && operationId == nil { throw ContractValidationError(field: "acquisition", code: "invalid_tagged_value") }
}
public static func decodeJSON(_ data: Data) throws -> Self { try rejectDuplicateJSONKeys(data); return try JSONDecoder().decode(Self.self, from: data) }
public func encodeJSON() throws -> Data { try validate(); return try JSONEncoder().encode(self) }
}
public struct GatewayTelemetry: Codable, Equatable {
public let admittedSessions: Int64
public let admissionRejects: Int64
public let reconnects: Int64
public let drainTransitions: Int64
public let mediaDrops: Int64
public let mediaPackets: Int64
public let mediaBytes: Int64
public let queueDelayMicros: Int64
public let processingDelayMicros: Int64
public let processingSamples: Int64
public let pacingDelayMicros: Int64
public let providerErrors: Int64
public let inputRejected: Int64
public let controlRttMicros: Int64
public let controlJitterMicros: Int64
public let controlLossPpm: Int64
public let pendingReliable: Int64
public let providerState: String
enum CodingKeys: String, CodingKey {
case admittedSessions = "admitted_sessions"
case admissionRejects = "admission_rejects"
case reconnects = "reconnects"
case drainTransitions = "drain_transitions"
case mediaDrops = "media_drops"
case mediaPackets = "media_packets"
case mediaBytes = "media_bytes"
case queueDelayMicros = "queue_delay_micros"
case processingDelayMicros = "processing_delay_micros"
case processingSamples = "processing_samples"
case pacingDelayMicros = "pacing_delay_micros"
case providerErrors = "provider_errors"
case inputRejected = "input_rejected"
case controlRttMicros = "control_rtt_micros"
case controlJitterMicros = "control_jitter_micros"
case controlLossPpm = "control_loss_ppm"
case pendingReliable = "pending_reliable"
case providerState = "provider_state"
}
public init(admittedSessions: Int64, admissionRejects: Int64, reconnects: Int64, drainTransitions: Int64, mediaDrops: Int64, mediaPackets: Int64, mediaBytes: Int64, queueDelayMicros: Int64, processingDelayMicros: Int64, processingSamples: Int64, pacingDelayMicros: Int64, providerErrors: Int64, inputRejected: Int64, controlRttMicros: Int64, controlJitterMicros: Int64, controlLossPpm: Int64, pendingReliable: Int64, providerState: String) throws {
self.admittedSessions = admittedSessions
self.admissionRejects = admissionRejects
self.reconnects = reconnects
self.drainTransitions = drainTransitions
self.mediaDrops = mediaDrops
self.mediaPackets = mediaPackets
self.mediaBytes = mediaBytes
self.queueDelayMicros = queueDelayMicros
self.processingDelayMicros = processingDelayMicros
self.processingSamples = processingSamples
self.pacingDelayMicros = pacingDelayMicros
self.providerErrors = providerErrors
self.inputRejected = inputRejected
self.controlRttMicros = controlRttMicros
self.controlJitterMicros = controlJitterMicros
self.controlLossPpm = controlLossPpm
self.pendingReliable = pendingReliable
self.providerState = providerState
try validate()
}
public init(from decoder: Decoder) throws {
let all = try decoder.container(keyedBy: AnyCodingKey.self)
for key in all.allKeys where CodingKeys(stringValue: key.stringValue) == nil { throw ContractValidationError(field: key.stringValue, code: "unknown_field") }
let c = try decoder.container(keyedBy: CodingKeys.self)
try self.init(admittedSessions: try c.decode(Int64.self, forKey: .admittedSessions), admissionRejects: try c.decode(Int64.self, forKey: .admissionRejects), reconnects: try c.decode(Int64.self, forKey: .reconnects), drainTransitions: try c.decode(Int64.self, forKey: .drainTransitions), mediaDrops: try c.decode(Int64.self, forKey: .mediaDrops), mediaPackets: try c.decode(Int64.self, forKey: .mediaPackets), mediaBytes: try c.decode(Int64.self, forKey: .mediaBytes), queueDelayMicros: try c.decode(Int64.self, forKey: .queueDelayMicros), processingDelayMicros: try c.decode(Int64.self, forKey: .processingDelayMicros), processingSamples: try c.decode(Int64.self, forKey: .processingSamples), pacingDelayMicros: try c.decode(Int64.self, forKey: .pacingDelayMicros), providerErrors: try c.decode(Int64.self, forKey: .providerErrors), inputRejected: try c.decode(Int64.self, forKey: .inputRejected), controlRttMicros: try c.decode(Int64.self, forKey: .controlRttMicros), controlJitterMicros: try c.decode(Int64.self, forKey: .controlJitterMicros), controlLossPpm: try c.decode(Int64.self, forKey: .controlLossPpm), pendingReliable: try c.decode(Int64.self, forKey: .pendingReliable), providerState: try c.decode(String.self, forKey: .providerState))
}
public func validate() throws {
if self.admittedSessions < 0 { throw ContractValidationError(field: "admitted_sessions", code: "minimum") }
if self.admittedSessions > 9223372036854775807 { throw ContractValidationError(field: "admitted_sessions", code: "maximum") }
if self.admissionRejects < 0 { throw ContractValidationError(field: "admission_rejects", code: "minimum") }
if self.admissionRejects > 9223372036854775807 { throw ContractValidationError(field: "admission_rejects", code: "maximum") }
if self.reconnects < 0 { throw ContractValidationError(field: "reconnects", code: "minimum") }
if self.reconnects > 9223372036854775807 { throw ContractValidationError(field: "reconnects", code: "maximum") }
if self.drainTransitions < 0 { throw ContractValidationError(field: "drain_transitions", code: "minimum") }
if self.drainTransitions > 9223372036854775807 { throw ContractValidationError(field: "drain_transitions", code: "maximum") }
if self.mediaDrops < 0 { throw ContractValidationError(field: "media_drops", code: "minimum") }
if self.mediaDrops > 9223372036854775807 { throw ContractValidationError(field: "media_drops", code: "maximum") }
if self.mediaPackets < 0 { throw ContractValidationError(field: "media_packets", code: "minimum") }
if self.mediaPackets > 9223372036854775807 { throw ContractValidationError(field: "media_packets", code: "maximum") }
if self.mediaBytes < 0 { throw ContractValidationError(field: "media_bytes", code: "minimum") }
if self.mediaBytes > 9223372036854775807 { throw ContractValidationError(field: "media_bytes", code: "maximum") }
if self.queueDelayMicros < 0 { throw ContractValidationError(field: "queue_delay_micros", code: "minimum") }
if self.queueDelayMicros > 9223372036854775807 { throw ContractValidationError(field: "queue_delay_micros", code: "maximum") }
if self.processingDelayMicros < 0 { throw ContractValidationError(field: "processing_delay_micros", code: "minimum") }
if self.processingDelayMicros > 9223372036854775807 { throw ContractValidationError(field: "processing_delay_micros", code: "maximum") }
if self.processingSamples < 0 { throw ContractValidationError(field: "processing_samples", code: "minimum") }
if self.processingSamples > 9223372036854775807 { throw ContractValidationError(field: "processing_samples", code: "maximum") }
if self.pacingDelayMicros < 0 { throw ContractValidationError(field: "pacing_delay_micros", code: "minimum") }
if self.pacingDelayMicros > 9223372036854775807 { throw ContractValidationError(field: "pacing_delay_micros", code: "maximum") }
if self.providerErrors < 0 { throw ContractValidationError(field: "provider_errors", code: "minimum") }
if self.providerErrors > 9223372036854775807 { throw ContractValidationError(field: "provider_errors", code: "maximum") }
if self.inputRejected < 0 { throw ContractValidationError(field: "input_rejected", code: "minimum") }
if self.inputRejected > 9223372036854775807 { throw ContractValidationError(field: "input_rejected", code: "maximum") }
if self.controlRttMicros < 0 { throw ContractValidationError(field: "control_rtt_micros", code: "minimum") }
if self.controlRttMicros > 9223372036854775807 { throw ContractValidationError(field: "control_rtt_micros", code: "maximum") }
if self.controlJitterMicros < 0 { throw ContractValidationError(field: "control_jitter_micros", code: "minimum") }
if self.controlJitterMicros > 9223372036854775807 { throw ContractValidationError(field: "control_jitter_micros", code: "maximum") }
if self.controlLossPpm < 0 { throw ContractValidationError(field: "control_loss_ppm", code: "minimum") }
if self.controlLossPpm > 1000000 { throw ContractValidationError(field: "control_loss_ppm", code: "maximum") }
if self.pendingReliable < 0 { throw ContractValidationError(field: "pending_reliable", code: "minimum") }
if self.pendingReliable > 9223372036854775807 { throw ContractValidationError(field: "pending_reliable", code: "maximum") }
if !["unknown", "starting", "ready", "disconnected", "terminating", "terminated", "cleanup_pending", "failed"].contains(self.providerState) { throw ContractValidationError(field: "provider_state", code: "invalid_value") }
}
public static func decodeJSON(_ data: Data) throws -> Self { try rejectDuplicateJSONKeys(data); return try JSONDecoder().decode(Self.self, from: data) }
public func encodeJSON() throws -> Data { try validate(); return try JSONEncoder().encode(self) }
}
public struct GrantReference: Codable, Equatable {
public let opaqueValue: String
public let expiresAt: String
public let audience: String
enum CodingKeys: String, CodingKey {
case opaqueValue = "opaque_value"
case expiresAt = "expires_at"
case audience = "audience"
}
public init(opaqueValue: String, expiresAt: String, audience: String) throws {
self.opaqueValue = opaqueValue
self.expiresAt = expiresAt
self.audience = audience
try validate()
}
public init(from decoder: Decoder) throws {
let all = try decoder.container(keyedBy: AnyCodingKey.self)
for key in all.allKeys where CodingKeys(stringValue: key.stringValue) == nil { throw ContractValidationError(field: key.stringValue, code: "unknown_field") }
let c = try decoder.container(keyedBy: CodingKeys.self)
try self.init(opaqueValue: try c.decode(String.self, forKey: .opaqueValue), expiresAt: try c.decode(String.self, forKey: .expiresAt), audience: try c.decode(String.self, forKey: .audience))
}
public func validate() throws {
if self.opaqueValue.isEmpty { throw ContractValidationError(field: "opaque_value", code: "required") }
if !self.opaqueValue.isEmpty && self.opaqueValue.utf8.count < 43 { throw ContractValidationError(field: "opaque_value", code: "min_length") }
if self.opaqueValue.utf8.count > 256 { throw ContractValidationError(field: "opaque_value", code: "max_length") }
if self.expiresAt.utf8.count > 64 { throw ContractValidationError(field: "expires_at", code: "max_length") }
if !validRFC3339UTC(self.expiresAt) { throw ContractValidationError(field: "expires_at", code: "invalid_time") }
if self.audience.isEmpty { throw ContractValidationError(field: "audience", code: "required") }
if !self.audience.isEmpty && self.audience.utf8.count < 1 { throw ContractValidationError(field: "audience", code: "min_length") }
if self.audience.utf8.count > 128 { throw ContractValidationError(field: "audience", code: "max_length") }
}
public static func decodeJSON(_ data: Data) throws -> Self { try rejectDuplicateJSONKeys(data); return try JSONDecoder().decode(Self.self, from: data) }
public func encodeJSON() throws -> Data { try validate(); return try JSONEncoder().encode(self) }
}
public struct LoginRequest: Codable, Equatable {
public let provider: String?
public let username: String
public let password: String
enum CodingKeys: String, CodingKey {
case provider = "provider"
case username = "username"
case password = "password"
}
public init(provider: String?, username: String, password: String) throws {
self.provider = provider
self.username = username
self.password = password
try validate()
}
public init(from decoder: Decoder) throws {
let all = try decoder.container(keyedBy: AnyCodingKey.self)
for key in all.allKeys where CodingKeys(stringValue: key.stringValue) == nil { throw ContractValidationError(field: key.stringValue, code: "unknown_field") }
let c = try decoder.container(keyedBy: CodingKeys.self)
try self.init(provider: try c.decodeIfPresent(String.self, forKey: .provider), username: try c.decode(String.self, forKey: .username), password: try c.decode(String.self, forKey: .password))
}
public func validate() throws {
if let value = self.provider {
if !["ldap", "local"].contains(value) { throw ContractValidationError(field: "provider", code: "invalid_value") }
}
if self.username.isEmpty { throw ContractValidationError(field: "username", code: "required") }
if !self.username.isEmpty && self.username.utf8.count < 1 { throw ContractValidationError(field: "username", code: "min_length") }
if self.username.utf8.count > 256 { throw ContractValidationError(field: "username", code: "max_length") }
if self.password.isEmpty { throw ContractValidationError(field: "password", code: "required") }
if !self.password.isEmpty && self.password.utf8.count < 1 { throw ContractValidationError(field: "password", code: "min_length") }
if self.password.utf8.count > 1024 { throw ContractValidationError(field: "password", code: "max_length") }
}
public static func decodeJSON(_ data: Data) throws -> Self { try rejectDuplicateJSONKeys(data); return try JSONDecoder().decode(Self.self, from: data) }
public func encodeJSON() throws -> Data { try validate(); return try JSONEncoder().encode(self) }
}
public struct ManifestBounds: Codable, Equatable {
public let minimumKbps: Int64
public let targetKbps: Int64
public let maximumKbps: Int64
enum CodingKeys: String, CodingKey {
case minimumKbps = "minimum_kbps"
case targetKbps = "target_kbps"
case maximumKbps = "maximum_kbps"
}
public init(minimumKbps: Int64, targetKbps: Int64, maximumKbps: Int64) throws {
self.minimumKbps = minimumKbps
self.targetKbps = targetKbps
self.maximumKbps = maximumKbps
try validate()
}
public init(from decoder: Decoder) throws {
let all = try decoder.container(keyedBy: AnyCodingKey.self)
for key in all.allKeys where CodingKeys(stringValue: key.stringValue) == nil { throw ContractValidationError(field: key.stringValue, code: "unknown_field") }
let c = try decoder.container(keyedBy: CodingKeys.self)
try self.init(minimumKbps: try c.decode(Int64.self, forKey: .minimumKbps), targetKbps: try c.decode(Int64.self, forKey: .targetKbps), maximumKbps: try c.decode(Int64.self, forKey: .maximumKbps))
}
public func validate() throws {
if self.minimumKbps < 1 { throw ContractValidationError(field: "minimum_kbps", code: "minimum") }
if self.minimumKbps > 100000000 { throw ContractValidationError(field: "minimum_kbps", code: "maximum") }
if self.targetKbps < 1 { throw ContractValidationError(field: "target_kbps", code: "minimum") }
if self.targetKbps > 100000000 { throw ContractValidationError(field: "target_kbps", code: "maximum") }
if self.maximumKbps < 1 { throw ContractValidationError(field: "maximum_kbps", code: "minimum") }
if self.maximumKbps > 100000000 { throw ContractValidationError(field: "maximum_kbps", code: "maximum") }
if minimumKbps > targetKbps || targetKbps > maximumKbps { throw ContractValidationError(field: "bounds", code: "invalid_order") }
}
public static func decodeJSON(_ data: Data) throws -> Self { try rejectDuplicateJSONKeys(data); return try JSONDecoder().decode(Self.self, from: data) }
public func encodeJSON() throws -> Data { try validate(); return try JSONEncoder().encode(self) }
}
public struct ManifestGateway: Codable, Equatable {
public let id: String
public let addresses: [String]
public let publicIdentity: String
enum CodingKeys: String, CodingKey {
case id = "id"
case addresses = "addresses"
case publicIdentity = "public_identity"
}
public init(id: String, addresses: [String], publicIdentity: String) throws {
self.id = id
self.addresses = addresses
self.publicIdentity = publicIdentity
try validate()
}
public init(from decoder: Decoder) throws {
let all = try decoder.container(keyedBy: AnyCodingKey.self)
for key in all.allKeys where CodingKeys(stringValue: key.stringValue) == nil { throw ContractValidationError(field: key.stringValue, code: "unknown_field") }
let c = try decoder.container(keyedBy: CodingKeys.self)
try self.init(id: try c.decode(String.self, forKey: .id), addresses: try c.decode([String].self, forKey: .addresses), publicIdentity: try c.decode(String.self, forKey: .publicIdentity))
}
public func validate() throws {
if self.id.isEmpty { throw ContractValidationError(field: "id", code: "required") }
if !self.id.isEmpty && self.id.utf8.count < 1 { throw ContractValidationError(field: "id", code: "min_length") }
if self.id.utf8.count > 128 { throw ContractValidationError(field: "id", code: "max_length") }
if self.addresses.count < 1 { throw ContractValidationError(field: "addresses", code: "min_items") }
if self.addresses.count > 4 { throw ContractValidationError(field: "addresses", code: "max_items") }
for item in self.addresses where item.utf8.count < 1 { throw ContractValidationError(field: "addresses", code: "min_item_length") }
for item in self.addresses where item.utf8.count > 256 { throw ContractValidationError(field: "addresses", code: "max_item_length") }
if self.publicIdentity.isEmpty { throw ContractValidationError(field: "public_identity", code: "required") }
if !self.publicIdentity.isEmpty && self.publicIdentity.utf8.count < 1 { throw ContractValidationError(field: "public_identity", code: "min_length") }
if self.publicIdentity.utf8.count > 256 { throw ContractValidationError(field: "public_identity", code: "max_length") }
}
public static func decodeJSON(_ data: Data) throws -> Self { try rejectDuplicateJSONKeys(data); return try JSONDecoder().decode(Self.self, from: data) }
public func encodeJSON() throws -> Data { try validate(); return try JSONEncoder().encode(self) }
}
public struct ManifestProfile: Codable, Equatable {
public let id: String
public let bounds: ManifestBounds
public let displayMode: DisplayMode?
enum CodingKeys: String, CodingKey {
case id = "id"
case bounds = "bounds"
case displayMode = "display_mode"
}
public init(id: String, bounds: ManifestBounds, displayMode: DisplayMode?) throws {
self.id = id
self.bounds = bounds
self.displayMode = displayMode
try validate()
}
public init(from decoder: Decoder) throws {
let all = try decoder.container(keyedBy: AnyCodingKey.self)
for key in all.allKeys where CodingKeys(stringValue: key.stringValue) == nil { throw ContractValidationError(field: key.stringValue, code: "unknown_field") }
let c = try decoder.container(keyedBy: CodingKeys.self)
try self.init(id: try c.decode(String.self, forKey: .id), bounds: try c.decode(ManifestBounds.self, forKey: .bounds), displayMode: try c.contains(.displayMode) ? c.decode(DisplayMode.self, forKey: .displayMode) : nil)
}
public func validate() throws {
if self.id.isEmpty { throw ContractValidationError(field: "id", code: "required") }
if !self.id.isEmpty && self.id.utf8.count < 1 { throw ContractValidationError(field: "id", code: "min_length") }
if self.id.utf8.count > 128 { throw ContractValidationError(field: "id", code: "max_length") }
try self.bounds.validate()
if let value = self.displayMode {
try value.validate()
}
}
public static func decodeJSON(_ data: Data) throws -> Self { try rejectDuplicateJSONKeys(data); return try JSONDecoder().decode(Self.self, from: data) }
public func encodeJSON() throws -> Data { try validate(); return try JSONEncoder().encode(self) }
}
public struct ManifestTunnel: Codable, Equatable {
public let versions: [String]
public let features: [String]
enum CodingKeys: String, CodingKey {
case versions = "versions"
case features = "features"
}
public init(versions: [String], features: [String]) throws {
self.versions = versions
self.features = features
try validate()
}
public init(from decoder: Decoder) throws {
let all = try decoder.container(keyedBy: AnyCodingKey.self)
for key in all.allKeys where CodingKeys(stringValue: key.stringValue) == nil { throw ContractValidationError(field: key.stringValue, code: "unknown_field") }
let c = try decoder.container(keyedBy: CodingKeys.self)
try self.init(versions: try c.decode([String].self, forKey: .versions), features: try c.decode([String].self, forKey: .features))
}
public func validate() throws {
if self.versions.count < 1 { throw ContractValidationError(field: "versions", code: "min_items") }
if self.versions.count > 4 { throw ContractValidationError(field: "versions", code: "max_items") }
for item in self.versions where item.utf8.count < 1 { throw ContractValidationError(field: "versions", code: "min_item_length") }
for item in self.versions where item.utf8.count > 64 { throw ContractValidationError(field: "versions", code: "max_item_length") }
if self.features.count > 32 { throw ContractValidationError(field: "features", code: "max_items") }
for item in self.features where item.utf8.count < 1 { throw ContractValidationError(field: "features", code: "min_item_length") }
for item in self.features where item.utf8.count > 64 { throw ContractValidationError(field: "features", code: "max_item_length") }
}
public static func decodeJSON(_ data: Data) throws -> Self { try rejectDuplicateJSONKeys(data); return try JSONDecoder().decode(Self.self, from: data) }
public func encodeJSON() throws -> Data { try validate(); return try JSONEncoder().encode(self) }
}
public struct NativeAuthenticatedSession: Codable, Equatable {
public let username: String
public let provider: String
public let roles: [String]
public let role: String
public let nativeIdentity: NativeSessionIdentity
enum CodingKeys: String, CodingKey {
case username = "username"
case provider = "provider"
case roles = "roles"
case role = "role"
case nativeIdentity = "native_identity"
}
public init(username: String, provider: String, roles: [String], role: String, nativeIdentity: NativeSessionIdentity) throws {
self.username = username
self.provider = provider
self.roles = roles
self.role = role
self.nativeIdentity = nativeIdentity
try validate()
}
public init(from decoder: Decoder) throws {
let all = try decoder.container(keyedBy: AnyCodingKey.self)
for key in all.allKeys where CodingKeys(stringValue: key.stringValue) == nil { throw ContractValidationError(field: key.stringValue, code: "unknown_field") }
let c = try decoder.container(keyedBy: CodingKeys.self)
try self.init(username: try c.decode(String.self, forKey: .username), provider: try c.decode(String.self, forKey: .provider), roles: try c.decode([String].self, forKey: .roles), role: try c.decode(String.self, forKey: .role), nativeIdentity: try c.decode(NativeSessionIdentity.self, forKey: .nativeIdentity))
}
public func validate() throws {
if self.username.isEmpty { throw ContractValidationError(field: "username", code: "required") }
if !self.username.isEmpty && self.username.utf8.count < 1 { throw ContractValidationError(field: "username", code: "min_length") }
if self.username.utf8.count > 256 { throw ContractValidationError(field: "username", code: "max_length") }
if self.provider.isEmpty { throw ContractValidationError(field: "provider", code: "required") }
if !self.provider.isEmpty && self.provider.utf8.count < 1 { throw ContractValidationError(field: "provider", code: "min_length") }
if self.provider.utf8.count > 64 { throw ContractValidationError(field: "provider", code: "max_length") }
if self.roles.count > 16 { throw ContractValidationError(field: "roles", code: "max_items") }
for item in self.roles where item.utf8.count < 1 { throw ContractValidationError(field: "roles", code: "min_item_length") }
for item in self.roles where item.utf8.count > 64 { throw ContractValidationError(field: "roles", code: "max_item_length") }
for item in self.roles where item.utf8.count > 64 { throw ContractValidationError(field: "roles", code: "max_item_bytes") }
if !["user", "admin"].contains(self.role) { throw ContractValidationError(field: "role", code: "invalid_value") }
try self.nativeIdentity.validate()
}
public static func decodeJSON(_ data: Data) throws -> Self { try rejectDuplicateJSONKeys(data); return try JSONDecoder().decode(Self.self, from: data) }
public func encodeJSON() throws -> Data { try validate(); return try JSONEncoder().encode(self) }
}
public struct NativeCredential: Codable, Equatable {
public let deviceId: String?
public let familyId: String
public let accessToken: String
public let refreshToken: String
public let expiresAt: String
public let refreshExpiresAt: String?
enum CodingKeys: String, CodingKey {
case deviceId = "device_id"
case familyId = "family_id"
case accessToken = "access_token"
case refreshToken = "refresh_token"
case expiresAt = "expires_at"
case refreshExpiresAt = "refresh_expires_at"
}
public init(deviceId: String?, familyId: String, accessToken: String, refreshToken: String, expiresAt: String, refreshExpiresAt: String?) throws {
self.deviceId = deviceId
self.familyId = familyId
self.accessToken = accessToken
self.refreshToken = refreshToken
self.expiresAt = expiresAt
self.refreshExpiresAt = refreshExpiresAt
try validate()
}
public init(from decoder: Decoder) throws {
let all = try decoder.container(keyedBy: AnyCodingKey.self)
for key in all.allKeys where CodingKeys(stringValue: key.stringValue) == nil { throw ContractValidationError(field: key.stringValue, code: "unknown_field") }
let c = try decoder.container(keyedBy: CodingKeys.self)
try self.init(deviceId: try c.decodeIfPresent(String.self, forKey: .deviceId), familyId: try c.decode(String.self, forKey: .familyId), accessToken: try c.decode(String.self, forKey: .accessToken), refreshToken: try c.decode(String.self, forKey: .refreshToken), expiresAt: try c.decode(String.self, forKey: .expiresAt), refreshExpiresAt: try c.decodeIfPresent(String.self, forKey: .refreshExpiresAt))
}
public func validate() throws {
if let value = self.deviceId {
if value.utf8.count > 128 { throw ContractValidationError(field: "device_id", code: "max_length") }
}
if self.familyId.isEmpty { throw ContractValidationError(field: "family_id", code: "required") }
if !self.familyId.isEmpty && self.familyId.utf8.count < 1 { throw ContractValidationError(field: "family_id", code: "min_length") }
if self.familyId.utf8.count > 128 { throw ContractValidationError(field: "family_id", code: "max_length") }
if self.accessToken.isEmpty { throw ContractValidationError(field: "access_token", code: "required") }
if !self.accessToken.isEmpty && self.accessToken.utf8.count < 1 { throw ContractValidationError(field: "access_token", code: "min_length") }
if self.accessToken.utf8.count > 256 { throw ContractValidationError(field: "access_token", code: "max_length") }
if self.refreshToken.isEmpty { throw ContractValidationError(field: "refresh_token", code: "required") }
if !self.refreshToken.isEmpty && self.refreshToken.utf8.count < 1 { throw ContractValidationError(field: "refresh_token", code: "min_length") }
if self.refreshToken.utf8.count > 256 { throw ContractValidationError(field: "refresh_token", code: "max_length") }
if self.expiresAt.utf8.count > 64 { throw ContractValidationError(field: "expires_at", code: "max_length") }
if !validRFC3339UTC(self.expiresAt) { throw ContractValidationError(field: "expires_at", code: "invalid_time") }
if let value = self.refreshExpiresAt {
if value.utf8.count > 64 { throw ContractValidationError(field: "refresh_expires_at", code: "max_length") }
if !validRFC3339UTC(value) { throw ContractValidationError(field: "refresh_expires_at", code: "invalid_time") }
}
}
public static func decodeJSON(_ data: Data) throws -> Self { try rejectDuplicateJSONKeys(data); return try JSONDecoder().decode(Self.self, from: data) }
public func encodeJSON() throws -> Data { try validate(); return try JSONEncoder().encode(self) }
}
public struct NativeSessionIdentity: Codable, Equatable {
public let clientDeviceId: String
public let deviceKeyId: String
enum CodingKeys: String, CodingKey {
case clientDeviceId = "client_device_id"
case deviceKeyId = "device_key_id"
}
public init(clientDeviceId: String, deviceKeyId: String) throws {
self.clientDeviceId = clientDeviceId
self.deviceKeyId = deviceKeyId
try validate()
}
public init(from decoder: Decoder) throws {
let all = try decoder.container(keyedBy: AnyCodingKey.self)
for key in all.allKeys where CodingKeys(stringValue: key.stringValue) == nil { throw ContractValidationError(field: key.stringValue, code: "unknown_field") }
let c = try decoder.container(keyedBy: CodingKeys.self)
try self.init(clientDeviceId: try c.decode(String.self, forKey: .clientDeviceId), deviceKeyId: try c.decode(String.self, forKey: .deviceKeyId))
}
public func validate() throws {
if self.clientDeviceId.isEmpty { throw ContractValidationError(field: "client_device_id", code: "required") }
if !self.clientDeviceId.isEmpty && self.clientDeviceId.utf8.count < 1 { throw ContractValidationError(field: "client_device_id", code: "min_length") }
if self.clientDeviceId.utf8.count > 128 { throw ContractValidationError(field: "client_device_id", code: "max_length") }
if self.deviceKeyId.isEmpty { throw ContractValidationError(field: "device_key_id", code: "required") }
if !self.deviceKeyId.isEmpty && self.deviceKeyId.utf8.count < 1 { throw ContractValidationError(field: "device_key_id", code: "min_length") }
if self.deviceKeyId.utf8.count > 128 { throw ContractValidationError(field: "device_key_id", code: "max_length") }
}
public static func decodeJSON(_ data: Data) throws -> Self { try rejectDuplicateJSONKeys(data); return try JSONDecoder().decode(Self.self, from: data) }
public func encodeJSON() throws -> Data { try validate(); return try JSONEncoder().encode(self) }
}
public struct NativeTunnelCredential: Codable, Equatable {
public let clientDeviceId: String
public let deviceKeyId: String
public let certificateChainPem: String
public let trustBundlePem: String
public let expiresAt: String
enum CodingKeys: String, CodingKey {
case clientDeviceId = "client_device_id"
case deviceKeyId = "device_key_id"
case certificateChainPem = "certificate_chain_pem"
case trustBundlePem = "trust_bundle_pem"
case expiresAt = "expires_at"
}
public init(clientDeviceId: String, deviceKeyId: String, certificateChainPem: String, trustBundlePem: String, expiresAt: String) throws {
self.clientDeviceId = clientDeviceId
self.deviceKeyId = deviceKeyId
self.certificateChainPem = certificateChainPem
self.trustBundlePem = trustBundlePem
self.expiresAt = expiresAt
try validate()
}
public init(from decoder: Decoder) throws {
let all = try decoder.container(keyedBy: AnyCodingKey.self)
for key in all.allKeys where CodingKeys(stringValue: key.stringValue) == nil { throw ContractValidationError(field: key.stringValue, code: "unknown_field") }
let c = try decoder.container(keyedBy: CodingKeys.self)
try self.init(clientDeviceId: try c.decode(String.self, forKey: .clientDeviceId), deviceKeyId: try c.decode(String.self, forKey: .deviceKeyId), certificateChainPem: try c.decode(String.self, forKey: .certificateChainPem), trustBundlePem: try c.decode(String.self, forKey: .trustBundlePem), expiresAt: try c.decode(String.self, forKey: .expiresAt))
}
public func validate() throws {
if self.clientDeviceId.isEmpty { throw ContractValidationError(field: "client_device_id", code: "required") }
if !self.clientDeviceId.isEmpty && self.clientDeviceId.utf8.count < 1 { throw ContractValidationError(field: "client_device_id", code: "min_length") }
if self.clientDeviceId.utf8.count > 128 { throw ContractValidationError(field: "client_device_id", code: "max_length") }
if self.deviceKeyId.isEmpty { throw ContractValidationError(field: "device_key_id", code: "required") }
if !self.deviceKeyId.isEmpty && self.deviceKeyId.utf8.count < 1 { throw ContractValidationError(field: "device_key_id", code: "min_length") }
if self.deviceKeyId.utf8.count > 128 { throw ContractValidationError(field: "device_key_id", code: "max_length") }
if self.certificateChainPem.isEmpty { throw ContractValidationError(field: "certificate_chain_pem", code: "required") }
if !self.certificateChainPem.isEmpty && self.certificateChainPem.utf8.count < 1 { throw ContractValidationError(field: "certificate_chain_pem", code: "min_length") }
if self.certificateChainPem.utf8.count > 65536 { throw ContractValidationError(field: "certificate_chain_pem", code: "max_length") }
if self.trustBundlePem.isEmpty { throw ContractValidationError(field: "trust_bundle_pem", code: "required") }
if !self.trustBundlePem.isEmpty && self.trustBundlePem.utf8.count < 1 { throw ContractValidationError(field: "trust_bundle_pem", code: "min_length") }
if self.trustBundlePem.utf8.count > 65536 { throw ContractValidationError(field: "trust_bundle_pem", code: "max_length") }
if self.expiresAt.utf8.count > 64 { throw ContractValidationError(field: "expires_at", code: "max_length") }
if !validRFC3339UTC(self.expiresAt) { throw ContractValidationError(field: "expires_at", code: "invalid_time") }
}
public static func decodeJSON(_ data: Data) throws -> Self { try rejectDuplicateJSONKeys(data); return try JSONDecoder().decode(Self.self, from: data) }
public func encodeJSON() throws -> Data { try validate(); return try JSONEncoder().encode(self) }
}
public struct PageInfo: Codable, Equatable {
public let limit: Int64
public let nextCursor: String
enum CodingKeys: String, CodingKey {
case limit = "limit"
case nextCursor = "next_cursor"
}
public init(limit: Int64, nextCursor: String) throws {
self.limit = limit
self.nextCursor = nextCursor
try validate()
}
public init(from decoder: Decoder) throws {
let all = try decoder.container(keyedBy: AnyCodingKey.self)
for key in all.allKeys where CodingKeys(stringValue: key.stringValue) == nil { throw ContractValidationError(field: key.stringValue, code: "unknown_field") }
let c = try decoder.container(keyedBy: CodingKeys.self)
try self.init(limit: try c.decode(Int64.self, forKey: .limit), nextCursor: try c.decode(String.self, forKey: .nextCursor))
}
public func validate() throws {
if self.limit < 1 { throw ContractValidationError(field: "limit", code: "minimum") }
if self.limit > 100 { throw ContractValidationError(field: "limit", code: "maximum") }
if self.nextCursor.utf8.count > 512 { throw ContractValidationError(field: "next_cursor", code: "max_length") }
}
public static func decodeJSON(_ data: Data) throws -> Self { try rejectDuplicateJSONKeys(data); return try JSONDecoder().decode(Self.self, from: data) }
public func encodeJSON() throws -> Data { try validate(); return try JSONEncoder().encode(self) }
}
public struct ProviderSessionWork: Codable, Equatable {
public let version: String
public let sessionId: String
public let gatewayId: String
public let reconnectSequence: Int64
public let expiresAt: String
public let providerProfile: String
public let providerIdentity: String
public let policyVersionId: String
public let streamPolicy: ProviderStreamPolicy
public let applicationId: String
public let clientId: String
public let managementHost: String
public let managementPort: Int64
public let streamHost: String
public let streamPort: Int64
public let clientCertificatePem: String
public let clientPrivateKeyPem: String
public let serverCertificatePem: String
public let clipboardPolicy: ClipboardPolicy
public let providerApplicationTerminationAllowed: Bool
enum CodingKeys: String, CodingKey {
case version = "version"
case sessionId = "session_id"
case gatewayId = "gateway_id"
case reconnectSequence = "reconnect_sequence"
case expiresAt = "expires_at"
case providerProfile = "provider_profile"
case providerIdentity = "provider_identity"
case policyVersionId = "policy_version_id"
case streamPolicy = "stream_policy"
case applicationId = "application_id"
case clientId = "client_id"
case managementHost = "management_host"
case managementPort = "management_port"
case streamHost = "stream_host"
case streamPort = "stream_port"
case clientCertificatePem = "client_certificate_pem"
case clientPrivateKeyPem = "client_private_key_pem"
case serverCertificatePem = "server_certificate_pem"
case clipboardPolicy = "clipboard_policy"
case providerApplicationTerminationAllowed = "provider_application_termination_allowed"
}
public init(version: String, sessionId: String, gatewayId: String, reconnectSequence: Int64, expiresAt: String, providerProfile: String, providerIdentity: String, policyVersionId: String, streamPolicy: ProviderStreamPolicy, applicationId: String, clientId: String, managementHost: String, managementPort: Int64, streamHost: String, streamPort: Int64, clientCertificatePem: String, clientPrivateKeyPem: String, serverCertificatePem: String, clipboardPolicy: ClipboardPolicy, providerApplicationTerminationAllowed: Bool) throws {
self.version = version
self.sessionId = sessionId
self.gatewayId = gatewayId
self.reconnectSequence = reconnectSequence
self.expiresAt = expiresAt
self.providerProfile = providerProfile
self.providerIdentity = providerIdentity
self.policyVersionId = policyVersionId
self.streamPolicy = streamPolicy
self.applicationId = applicationId
self.clientId = clientId
self.managementHost = managementHost
self.managementPort = managementPort
self.streamHost = streamHost
self.streamPort = streamPort
self.clientCertificatePem = clientCertificatePem
self.clientPrivateKeyPem = clientPrivateKeyPem
self.serverCertificatePem = serverCertificatePem
self.clipboardPolicy = clipboardPolicy
self.providerApplicationTerminationAllowed = providerApplicationTerminationAllowed
try validate()
}
public init(from decoder: Decoder) throws {
let all = try decoder.container(keyedBy: AnyCodingKey.self)
for key in all.allKeys where CodingKeys(stringValue: key.stringValue) == nil { throw ContractValidationError(field: key.stringValue, code: "unknown_field") }
let c = try decoder.container(keyedBy: CodingKeys.self)
try self.init(version: try c.decode(String.self, forKey: .version), sessionId: try c.decode(String.self, forKey: .sessionId), gatewayId: try c.decode(String.self, forKey: .gatewayId), reconnectSequence: try c.decode(Int64.self, forKey: .reconnectSequence), expiresAt: try c.decode(String.self, forKey: .expiresAt), providerProfile: try c.decode(String.self, forKey: .providerProfile), providerIdentity: try c.decode(String.self, forKey: .providerIdentity), policyVersionId: try c.decode(String.self, forKey: .policyVersionId), streamPolicy: try c.decode(ProviderStreamPolicy.self, forKey: .streamPolicy), applicationId: try c.decode(String.self, forKey: .applicationId), clientId: try c.decode(String.self, forKey: .clientId), managementHost: try c.decode(String.self, forKey: .managementHost), managementPort: try c.decode(Int64.self, forKey: .managementPort), streamHost: try c.decode(String.self, forKey: .streamHost), streamPort: try c.decode(Int64.self, forKey: .streamPort), clientCertificatePem: try c.decode(String.self, forKey: .clientCertificatePem), clientPrivateKeyPem: try c.decode(String.self, forKey: .clientPrivateKeyPem), serverCertificatePem: try c.decode(String.self, forKey: .serverCertificatePem), clipboardPolicy: try c.decode(ClipboardPolicy.self, forKey: .clipboardPolicy), providerApplicationTerminationAllowed: try c.decode(Bool.self, forKey: .providerApplicationTerminationAllowed))
}
public func validate() throws {
if self.version != "1" { throw ContractValidationError(field: "version", code: "invalid_value") }
if self.sessionId.isEmpty { throw ContractValidationError(field: "session_id", code: "required") }
if !self.sessionId.isEmpty && self.sessionId.utf8.count < 1 { throw ContractValidationError(field: "session_id", code: "min_length") }
if self.sessionId.utf8.count > 128 { throw ContractValidationError(field: "session_id", code: "max_length") }
if self.gatewayId.isEmpty { throw ContractValidationError(field: "gateway_id", code: "required") }
if !self.gatewayId.isEmpty && self.gatewayId.utf8.count < 1 { throw ContractValidationError(field: "gateway_id", code: "min_length") }
if self.gatewayId.utf8.count > 128 { throw ContractValidationError(field: "gateway_id", code: "max_length") }
if self.reconnectSequence < 0 { throw ContractValidationError(field: "reconnect_sequence", code: "minimum") }
if self.expiresAt.utf8.count > 64 { throw ContractValidationError(field: "expires_at", code: "max_length") }
if !validRFC3339UTC(self.expiresAt) { throw ContractValidationError(field: "expires_at", code: "invalid_time") }
if self.providerProfile != "apollo" { throw ContractValidationError(field: "provider_profile", code: "invalid_value") }
if self.providerIdentity.isEmpty { throw ContractValidationError(field: "provider_identity", code: "required") }
if !self.providerIdentity.isEmpty && self.providerIdentity.utf8.count < 1 { throw ContractValidationError(field: "provider_identity", code: "min_length") }
if self.providerIdentity.utf8.count > 256 { throw ContractValidationError(field: "provider_identity", code: "max_length") }
if self.policyVersionId.isEmpty { throw ContractValidationError(field: "policy_version_id", code: "required") }
if !self.policyVersionId.isEmpty && self.policyVersionId.utf8.count < 1 { throw ContractValidationError(field: "policy_version_id", code: "min_length") }
if self.policyVersionId.utf8.count > 128 { throw ContractValidationError(field: "policy_version_id", code: "max_length") }
try self.streamPolicy.validate()
if self.applicationId.isEmpty { throw ContractValidationError(field: "application_id", code: "required") }
if !self.applicationId.isEmpty && self.applicationId.utf8.count < 1 { throw ContractValidationError(field: "application_id", code: "min_length") }
if self.applicationId.utf8.count > 128 { throw ContractValidationError(field: "application_id", code: "max_length") }
if self.clientId.isEmpty { throw ContractValidationError(field: "client_id", code: "required") }
if !self.clientId.isEmpty && self.clientId.utf8.count < 1 { throw ContractValidationError(field: "client_id", code: "min_length") }
if self.clientId.utf8.count > 128 { throw ContractValidationError(field: "client_id", code: "max_length") }
if self.managementHost.isEmpty { throw ContractValidationError(field: "management_host", code: "required") }
if !self.managementHost.isEmpty && self.managementHost.utf8.count < 1 { throw ContractValidationError(field: "management_host", code: "min_length") }
if self.managementHost.utf8.count > 256 { throw ContractValidationError(field: "management_host", code: "max_length") }
if self.managementPort < 1 { throw ContractValidationError(field: "management_port", code: "minimum") }
if self.managementPort > 65535 { throw ContractValidationError(field: "management_port", code: "maximum") }
if self.streamHost.isEmpty { throw ContractValidationError(field: "stream_host", code: "required") }
if !self.streamHost.isEmpty && self.streamHost.utf8.count < 1 { throw ContractValidationError(field: "stream_host", code: "min_length") }
if self.streamHost.utf8.count > 256 { throw ContractValidationError(field: "stream_host", code: "max_length") }
if self.streamPort < 1 { throw ContractValidationError(field: "stream_port", code: "minimum") }
if self.streamPort > 65535 { throw ContractValidationError(field: "stream_port", code: "maximum") }
if self.clientCertificatePem.isEmpty { throw ContractValidationError(field: "client_certificate_pem", code: "required") }
if !self.clientCertificatePem.isEmpty && self.clientCertificatePem.utf8.count < 1 { throw ContractValidationError(field: "client_certificate_pem", code: "min_length") }
if self.clientCertificatePem.utf8.count > 32768 { throw ContractValidationError(field: "client_certificate_pem", code: "max_length") }
if self.clientPrivateKeyPem.isEmpty { throw ContractValidationError(field: "client_private_key_pem", code: "required") }
if !self.clientPrivateKeyPem.isEmpty && self.clientPrivateKeyPem.utf8.count < 1 { throw ContractValidationError(field: "client_private_key_pem", code: "min_length") }
if self.clientPrivateKeyPem.utf8.count > 32768 { throw ContractValidationError(field: "client_private_key_pem", code: "max_length") }
if self.serverCertificatePem.isEmpty { throw ContractValidationError(field: "server_certificate_pem", code: "required") }
if !self.serverCertificatePem.isEmpty && self.serverCertificatePem.utf8.count < 1 { throw ContractValidationError(field: "server_certificate_pem", code: "min_length") }
if self.serverCertificatePem.utf8.count > 32768 { throw ContractValidationError(field: "server_certificate_pem", code: "max_length") }
try self.clipboardPolicy.validate()
}
public static func decodeJSON(_ data: Data) throws -> Self { try rejectDuplicateJSONKeys(data); return try JSONDecoder().decode(Self.self, from: data) }
public func encodeJSON() throws -> Data { try validate(); return try JSONEncoder().encode(self) }
}
public struct ProviderState: Codable, Equatable {
public let version: String
public let sessionId: String
public let state: String
public let cleanupPending: Bool
public let channels: [String]
enum CodingKeys: String, CodingKey {
case version = "version"
case sessionId = "session_id"
case state = "state"
case cleanupPending = "cleanup_pending"
case channels = "channels"
}
public init(version: String, sessionId: String, state: String, cleanupPending: Bool, channels: [String]) throws {
self.version = version
self.sessionId = sessionId
self.state = state
self.cleanupPending = cleanupPending
self.channels = channels
try validate()
}
public init(from decoder: Decoder) throws {
let all = try decoder.container(keyedBy: AnyCodingKey.self)
for key in all.allKeys where CodingKeys(stringValue: key.stringValue) == nil { throw ContractValidationError(field: key.stringValue, code: "unknown_field") }
let c = try decoder.container(keyedBy: CodingKeys.self)
try self.init(version: try c.decode(String.self, forKey: .version), sessionId: try c.decode(String.self, forKey: .sessionId), state: try c.decode(String.self, forKey: .state), cleanupPending: try c.decode(Bool.self, forKey: .cleanupPending), channels: try c.decode([String].self, forKey: .channels))
}
public func validate() throws {
if self.version != "1" { throw ContractValidationError(field: "version", code: "invalid_value") }
if self.sessionId.isEmpty { throw ContractValidationError(field: "session_id", code: "required") }
if !self.sessionId.isEmpty && self.sessionId.utf8.count < 1 { throw ContractValidationError(field: "session_id", code: "min_length") }
if self.sessionId.utf8.count > 128 { throw ContractValidationError(field: "session_id", code: "max_length") }
if !["starting", "ready", "disconnected", "terminating", "terminated", "cleanup_pending", "failed"].contains(self.state) { throw ContractValidationError(field: "state", code: "invalid_value") }
if self.channels.count > 8 { throw ContractValidationError(field: "channels", code: "max_items") }
for item in self.channels where item.utf8.count < 1 { throw ContractValidationError(field: "channels", code: "min_item_length") }
for item in self.channels where item.utf8.count > 64 { throw ContractValidationError(field: "channels", code: "max_item_length") }
}
public static func decodeJSON(_ data: Data) throws -> Self { try rejectDuplicateJSONKeys(data); return try JSONDecoder().decode(Self.self, from: data) }
public func encodeJSON() throws -> Data { try validate(); return try JSONEncoder().encode(self) }
}
public struct ProviderStreamPolicy: Codable, Equatable {
public let videoProfile: VideoProfile
public let audioProfile: AudioProfile
public let displayMode: DisplayMode
public let bitrateTargetKbps: Int64
public let bitrateMaximumKbps: Int64
enum CodingKeys: String, CodingKey {
case videoProfile = "video_profile"
case audioProfile = "audio_profile"
case displayMode = "display_mode"
case bitrateTargetKbps = "bitrate_target_kbps"
case bitrateMaximumKbps = "bitrate_maximum_kbps"
}
public init(videoProfile: VideoProfile, audioProfile: AudioProfile, displayMode: DisplayMode, bitrateTargetKbps: Int64, bitrateMaximumKbps: Int64) throws {
self.videoProfile = videoProfile
self.audioProfile = audioProfile
self.displayMode = displayMode
self.bitrateTargetKbps = bitrateTargetKbps
self.bitrateMaximumKbps = bitrateMaximumKbps
try validate()
}
public init(from decoder: Decoder) throws {
let all = try decoder.container(keyedBy: AnyCodingKey.self)
for key in all.allKeys where CodingKeys(stringValue: key.stringValue) == nil { throw ContractValidationError(field: key.stringValue, code: "unknown_field") }
let c = try decoder.container(keyedBy: CodingKeys.self)
try self.init(videoProfile: try c.decode(VideoProfile.self, forKey: .videoProfile), audioProfile: try c.decode(AudioProfile.self, forKey: .audioProfile), displayMode: try c.decode(DisplayMode.self, forKey: .displayMode), bitrateTargetKbps: try c.decode(Int64.self, forKey: .bitrateTargetKbps), bitrateMaximumKbps: try c.decode(Int64.self, forKey: .bitrateMaximumKbps))
}
public func validate() throws {
try self.videoProfile.validate()
try self.audioProfile.validate()
try self.displayMode.validate()
if self.bitrateTargetKbps < 100 { throw ContractValidationError(field: "bitrate_target_kbps", code: "minimum") }
if self.bitrateTargetKbps > 1000000 { throw ContractValidationError(field: "bitrate_target_kbps", code: "maximum") }
if self.bitrateMaximumKbps < 100 { throw ContractValidationError(field: "bitrate_maximum_kbps", code: "minimum") }
if self.bitrateMaximumKbps > 1000000 { throw ContractValidationError(field: "bitrate_maximum_kbps", code: "maximum") }
if bitrateTargetKbps > bitrateMaximumKbps { throw ContractValidationError(field: "bitrate_bounds", code: "invalid_order") }
}
public static func decodeJSON(_ data: Data) throws -> Self { try rejectDuplicateJSONKeys(data); return try JSONDecoder().decode(Self.self, from: data) }
public func encodeJSON() throws -> Data { try validate(); return try JSONEncoder().encode(self) }
}
public struct QualityChangeOperation: Codable, Equatable {
public let operationId: String
public let sessionId: String
public let revision: Int64
public let state: String
public let requestedBitratePreference: BitratePreference
public let effectiveBitrateKbps: Int64
public let governingPolicyVersion: String
public let sessionVersion: Int64
public let createdAt: String
public let deadlineAt: String
public let updatedAt: String
public let failureCode: String?
enum CodingKeys: String, CodingKey {
case operationId = "operation_id"
case sessionId = "session_id"
case revision = "revision"
case state = "state"
case requestedBitratePreference = "requested_bitrate_preference"
case effectiveBitrateKbps = "effective_bitrate_kbps"
case governingPolicyVersion = "governing_policy_version"
case sessionVersion = "session_version"
case createdAt = "created_at"
case deadlineAt = "deadline_at"
case updatedAt = "updated_at"
case failureCode = "failure_code"
}
public init(operationId: String, sessionId: String, revision: Int64, state: String, requestedBitratePreference: BitratePreference, effectiveBitrateKbps: Int64, governingPolicyVersion: String, sessionVersion: Int64, createdAt: String, deadlineAt: String, updatedAt: String, failureCode: String?) throws {
self.operationId = operationId
self.sessionId = sessionId
self.revision = revision
self.state = state
self.requestedBitratePreference = requestedBitratePreference
self.effectiveBitrateKbps = effectiveBitrateKbps
self.governingPolicyVersion = governingPolicyVersion
self.sessionVersion = sessionVersion
self.createdAt = createdAt
self.deadlineAt = deadlineAt
self.updatedAt = updatedAt
self.failureCode = failureCode
try validate()
}
public init(from decoder: Decoder) throws {
let all = try decoder.container(keyedBy: AnyCodingKey.self)
for key in all.allKeys where CodingKeys(stringValue: key.stringValue) == nil { throw ContractValidationError(field: key.stringValue, code: "unknown_field") }
let c = try decoder.container(keyedBy: CodingKeys.self)
try self.init(operationId: try c.decode(String.self, forKey: .operationId), sessionId: try c.decode(String.self, forKey: .sessionId), revision: try c.decode(Int64.self, forKey: .revision), state: try c.decode(String.self, forKey: .state), requestedBitratePreference: try c.decode(BitratePreference.self, forKey: .requestedBitratePreference), effectiveBitrateKbps: try c.decode(Int64.self, forKey: .effectiveBitrateKbps), governingPolicyVersion: try c.decode(String.self, forKey: .governingPolicyVersion), sessionVersion: try c.decode(Int64.self, forKey: .sessionVersion), createdAt: try c.decode(String.self, forKey: .createdAt), deadlineAt: try c.decode(String.self, forKey: .deadlineAt), updatedAt: try c.decode(String.self, forKey: .updatedAt), failureCode: try c.decodeIfPresent(String.self, forKey: .failureCode))
}
public func validate() throws {
if self.operationId.isEmpty { throw ContractValidationError(field: "operation_id", code: "required") }
if !self.operationId.isEmpty && self.operationId.utf8.count < 36 { throw ContractValidationError(field: "operation_id", code: "min_length") }
if self.operationId.utf8.count > 36 { throw ContractValidationError(field: "operation_id", code: "max_length") }
if !validCanonicalUUID(self.operationId) { throw ContractValidationError(field: "operation_id", code: "invalid_uuid") }
if self.sessionId.isEmpty { throw ContractValidationError(field: "session_id", code: "required") }
if !self.sessionId.isEmpty && self.sessionId.utf8.count < 1 { throw ContractValidationError(field: "session_id", code: "min_length") }
if self.sessionId.utf8.count > 128 { throw ContractValidationError(field: "session_id", code: "max_length") }
if self.revision < 1 { throw ContractValidationError(field: "revision", code: "minimum") }
if !["pending", "applying", "applied", "failed", "timed_out"].contains(self.state) { throw ContractValidationError(field: "state", code: "invalid_value") }
try self.requestedBitratePreference.validate()
if self.effectiveBitrateKbps < 100 { throw ContractValidationError(field: "effective_bitrate_kbps", code: "minimum") }
if self.effectiveBitrateKbps > 1000000 { throw ContractValidationError(field: "effective_bitrate_kbps", code: "maximum") }
if self.governingPolicyVersion.isEmpty { throw ContractValidationError(field: "governing_policy_version", code: "required") }
if !self.governingPolicyVersion.isEmpty && self.governingPolicyVersion.utf8.count < 1 { throw ContractValidationError(field: "governing_policy_version", code: "min_length") }
if self.governingPolicyVersion.utf8.count > 128 { throw ContractValidationError(field: "governing_policy_version", code: "max_length") }
if self.sessionVersion < 1 { throw ContractValidationError(field: "session_version", code: "minimum") }
if self.createdAt.utf8.count > 64 { throw ContractValidationError(field: "created_at", code: "max_length") }
if !validRFC3339UTC(self.createdAt) { throw ContractValidationError(field: "created_at", code: "invalid_time") }
if self.deadlineAt.utf8.count > 64 { throw ContractValidationError(field: "deadline_at", code: "max_length") }
if !validRFC3339UTC(self.deadlineAt) { throw ContractValidationError(field: "deadline_at", code: "invalid_time") }
if self.updatedAt.utf8.count > 64 { throw ContractValidationError(field: "updated_at", code: "max_length") }
if !validRFC3339UTC(self.updatedAt) { throw ContractValidationError(field: "updated_at", code: "invalid_time") }
if let value = self.failureCode {
if !value.isEmpty && value.utf8.count < 1 { throw ContractValidationError(field: "failure_code", code: "min_length") }
if value.utf8.count > 128 { throw ContractValidationError(field: "failure_code", code: "max_length") }
}
}
public static func decodeJSON(_ data: Data) throws -> Self { try rejectDuplicateJSONKeys(data); return try JSONDecoder().decode(Self.self, from: data) }
public func encodeJSON() throws -> Data { try validate(); return try JSONEncoder().encode(self) }
}
public struct QualityChangeRequest: Codable, Equatable {
public let bitratePreference: BitratePreference
public let expectedSessionVersion: Int64
public let expectedPolicyVersion: String
enum CodingKeys: String, CodingKey {
case bitratePreference = "bitrate_preference"
case expectedSessionVersion = "expected_session_version"
case expectedPolicyVersion = "expected_policy_version"
}
public init(bitratePreference: BitratePreference, expectedSessionVersion: Int64, expectedPolicyVersion: String) throws {
self.bitratePreference = bitratePreference
self.expectedSessionVersion = expectedSessionVersion
self.expectedPolicyVersion = expectedPolicyVersion
try validate()
}
public init(from decoder: Decoder) throws {
let all = try decoder.container(keyedBy: AnyCodingKey.self)
for key in all.allKeys where CodingKeys(stringValue: key.stringValue) == nil { throw ContractValidationError(field: key.stringValue, code: "unknown_field") }
let c = try decoder.container(keyedBy: CodingKeys.self)
try self.init(bitratePreference: try c.decode(BitratePreference.self, forKey: .bitratePreference), expectedSessionVersion: try c.decode(Int64.self, forKey: .expectedSessionVersion), expectedPolicyVersion: try c.decode(String.self, forKey: .expectedPolicyVersion))
}
public func validate() throws {
try self.bitratePreference.validate()
if self.expectedSessionVersion < 1 { throw ContractValidationError(field: "expected_session_version", code: "minimum") }
if self.expectedPolicyVersion.isEmpty { throw ContractValidationError(field: "expected_policy_version", code: "required") }
if !self.expectedPolicyVersion.isEmpty && self.expectedPolicyVersion.utf8.count < 1 { throw ContractValidationError(field: "expected_policy_version", code: "min_length") }
if self.expectedPolicyVersion.utf8.count > 128 { throw ContractValidationError(field: "expected_policy_version", code: "max_length") }
}
public static func decodeJSON(_ data: Data) throws -> Self { try rejectDuplicateJSONKeys(data); return try JSONDecoder().decode(Self.self, from: data) }
public func encodeJSON() throws -> Data { try validate(); return try JSONEncoder().encode(self) }
}
public struct ReauthGrant: Codable, Equatable {
public let token: String
public let purpose: String
public let expiresAt: String
enum CodingKeys: String, CodingKey {
case token = "token"
case purpose = "purpose"
case expiresAt = "expires_at"
}
public init(token: String, purpose: String, expiresAt: String) throws {
self.token = token
self.purpose = purpose
self.expiresAt = expiresAt
try validate()
}
public init(from decoder: Decoder) throws {
let all = try decoder.container(keyedBy: AnyCodingKey.self)
for key in all.allKeys where CodingKeys(stringValue: key.stringValue) == nil { throw ContractValidationError(field: key.stringValue, code: "unknown_field") }
let c = try decoder.container(keyedBy: CodingKeys.self)
try self.init(token: try c.decode(String.self, forKey: .token), purpose: try c.decode(String.self, forKey: .purpose), expiresAt: try c.decode(String.self, forKey: .expiresAt))
}
public func validate() throws {
if self.token.isEmpty { throw ContractValidationError(field: "token", code: "required") }
if !self.token.isEmpty && self.token.utf8.count < 1 { throw ContractValidationError(field: "token", code: "min_length") }
if self.token.utf8.count > 256 { throw ContractValidationError(field: "token", code: "max_length") }
if self.purpose.isEmpty { throw ContractValidationError(field: "purpose", code: "required") }
if !self.purpose.isEmpty && self.purpose.utf8.count < 1 { throw ContractValidationError(field: "purpose", code: "min_length") }
if self.purpose.utf8.count > 64 { throw ContractValidationError(field: "purpose", code: "max_length") }
if self.expiresAt.utf8.count > 64 { throw ContractValidationError(field: "expires_at", code: "max_length") }
if !validRFC3339UTC(self.expiresAt) { throw ContractValidationError(field: "expires_at", code: "invalid_time") }
}
public static func decodeJSON(_ data: Data) throws -> Self { try rejectDuplicateJSONKeys(data); return try JSONDecoder().decode(Self.self, from: data) }
public func encodeJSON() throws -> Data { try validate(); return try JSONEncoder().encode(self) }
}
public struct ReauthRequest: Codable, Equatable {
public let password: String
public let purpose: String
enum CodingKeys: String, CodingKey {
case password = "password"
case purpose = "purpose"
}
public init(password: String, purpose: String) throws {
self.password = password
self.purpose = purpose
try validate()
}
public init(from decoder: Decoder) throws {
let all = try decoder.container(keyedBy: AnyCodingKey.self)
for key in all.allKeys where CodingKeys(stringValue: key.stringValue) == nil { throw ContractValidationError(field: key.stringValue, code: "unknown_field") }
let c = try decoder.container(keyedBy: CodingKeys.self)
try self.init(password: try c.decode(String.self, forKey: .password), purpose: try c.decode(String.self, forKey: .purpose))
}
public func validate() throws {
if self.password.isEmpty { throw ContractValidationError(field: "password", code: "required") }
if !self.password.isEmpty && self.password.utf8.count < 1 { throw ContractValidationError(field: "password", code: "min_length") }
if self.password.utf8.count > 1024 { throw ContractValidationError(field: "password", code: "max_length") }
if !["identity_change", "key_change", "backup_enable", "external_database_tls_disabled", "assignment_change"].contains(self.purpose) { throw ContractValidationError(field: "purpose", code: "invalid_value") }
}
public static func decodeJSON(_ data: Data) throws -> Self { try rejectDuplicateJSONKeys(data); return try JSONDecoder().decode(Self.self, from: data) }
public func encodeJSON() throws -> Data { try validate(); return try JSONEncoder().encode(self) }
}
public struct ReconnectRequest: Codable, Equatable {
public let clientDeviceId: String
public let deviceKeyId: String
public let expectedVersion: Int64
public let displayRelaunchConfirmed: Bool
enum CodingKeys: String, CodingKey {
case clientDeviceId = "client_device_id"
case deviceKeyId = "device_key_id"
case expectedVersion = "expected_version"
case displayRelaunchConfirmed = "display_relaunch_confirmed"
}
public init(clientDeviceId: String, deviceKeyId: String, expectedVersion: Int64, displayRelaunchConfirmed: Bool) throws {
self.clientDeviceId = clientDeviceId
self.deviceKeyId = deviceKeyId
self.expectedVersion = expectedVersion
self.displayRelaunchConfirmed = displayRelaunchConfirmed
try validate()
}
public init(from decoder: Decoder) throws {
let all = try decoder.container(keyedBy: AnyCodingKey.self)
for key in all.allKeys where CodingKeys(stringValue: key.stringValue) == nil { throw ContractValidationError(field: key.stringValue, code: "unknown_field") }
let c = try decoder.container(keyedBy: CodingKeys.self)
try self.init(clientDeviceId: try c.decode(String.self, forKey: .clientDeviceId), deviceKeyId: try c.decode(String.self, forKey: .deviceKeyId), expectedVersion: try c.decode(Int64.self, forKey: .expectedVersion), displayRelaunchConfirmed: try c.decode(Bool.self, forKey: .displayRelaunchConfirmed))
}
public func validate() throws {
if self.clientDeviceId.isEmpty { throw ContractValidationError(field: "client_device_id", code: "required") }
if !self.clientDeviceId.isEmpty && self.clientDeviceId.utf8.count < 1 { throw ContractValidationError(field: "client_device_id", code: "min_length") }
if self.clientDeviceId.utf8.count > 128 { throw ContractValidationError(field: "client_device_id", code: "max_length") }
if self.deviceKeyId.isEmpty { throw ContractValidationError(field: "device_key_id", code: "required") }
if !self.deviceKeyId.isEmpty && self.deviceKeyId.utf8.count < 1 { throw ContractValidationError(field: "device_key_id", code: "min_length") }
if self.deviceKeyId.utf8.count > 128 { throw ContractValidationError(field: "device_key_id", code: "max_length") }
if self.expectedVersion < 1 { throw ContractValidationError(field: "expected_version", code: "minimum") }
}
public static func decodeJSON(_ data: Data) throws -> Self { try rejectDuplicateJSONKeys(data); return try JSONDecoder().decode(Self.self, from: data) }
public func encodeJSON() throws -> Data { try validate(); return try JSONEncoder().encode(self) }
}
public struct RefreshRequest: Codable, Equatable {
public let familyId: String
public let refreshToken: String
enum CodingKeys: String, CodingKey {
case familyId = "family_id"
case refreshToken = "refresh_token"
}
public init(familyId: String, refreshToken: String) throws {
self.familyId = familyId
self.refreshToken = refreshToken
try validate()
}
public init(from decoder: Decoder) throws {
let all = try decoder.container(keyedBy: AnyCodingKey.self)
for key in all.allKeys where CodingKeys(stringValue: key.stringValue) == nil { throw ContractValidationError(field: key.stringValue, code: "unknown_field") }
let c = try decoder.container(keyedBy: CodingKeys.self)
try self.init(familyId: try c.decode(String.self, forKey: .familyId), refreshToken: try c.decode(String.self, forKey: .refreshToken))
}
public func validate() throws {
if self.familyId.isEmpty { throw ContractValidationError(field: "family_id", code: "required") }
if !self.familyId.isEmpty && self.familyId.utf8.count < 1 { throw ContractValidationError(field: "family_id", code: "min_length") }
if self.familyId.utf8.count > 128 { throw ContractValidationError(field: "family_id", code: "max_length") }
if self.refreshToken.isEmpty { throw ContractValidationError(field: "refresh_token", code: "required") }
if !self.refreshToken.isEmpty && self.refreshToken.utf8.count < 1 { throw ContractValidationError(field: "refresh_token", code: "min_length") }
if self.refreshToken.utf8.count > 256 { throw ContractValidationError(field: "refresh_token", code: "max_length") }
}
public static func decodeJSON(_ data: Data) throws -> Self { try rejectDuplicateJSONKeys(data); return try JSONDecoder().decode(Self.self, from: data) }
public func encodeJSON() throws -> Data { try validate(); return try JSONEncoder().encode(self) }
}
public struct Resource: Codable, Equatable {
public let id: String
public let kind: String
public let name: String
public let state: String
public let assignmentState: String?
public let version: Int64
public let links: [ResourceLink]
enum CodingKeys: String, CodingKey {
case id = "id"
case kind = "kind"
case name = "name"
case state = "state"
case assignmentState = "assignment_state"
case version = "version"
case links = "links"
}
public init(id: String, kind: String, name: String, state: String, assignmentState: String?, version: Int64, links: [ResourceLink]) throws {
self.id = id
self.kind = kind
self.name = name
self.state = state
self.assignmentState = assignmentState
self.version = version
self.links = links
try validate()
}
public init(from decoder: Decoder) throws {
let all = try decoder.container(keyedBy: AnyCodingKey.self)
for key in all.allKeys where CodingKeys(stringValue: key.stringValue) == nil { throw ContractValidationError(field: key.stringValue, code: "unknown_field") }
let c = try decoder.container(keyedBy: CodingKeys.self)
try self.init(id: try c.decode(String.self, forKey: .id), kind: try c.decode(String.self, forKey: .kind), name: try c.decode(String.self, forKey: .name), state: try c.decode(String.self, forKey: .state), assignmentState: try c.decodeIfPresent(String.self, forKey: .assignmentState), version: try c.decode(Int64.self, forKey: .version), links: try c.decode([ResourceLink].self, forKey: .links))
}
public func validate() throws {
if self.id.isEmpty { throw ContractValidationError(field: "id", code: "required") }
if !self.id.isEmpty && self.id.utf8.count < 1 { throw ContractValidationError(field: "id", code: "min_length") }
if self.id.utf8.count > 128 { throw ContractValidationError(field: "id", code: "max_length") }
if self.kind.isEmpty { throw ContractValidationError(field: "kind", code: "required") }
if !self.kind.isEmpty && self.kind.utf8.count < 1 { throw ContractValidationError(field: "kind", code: "min_length") }
if self.kind.utf8.count > 64 { throw ContractValidationError(field: "kind", code: "max_length") }
if self.name.isEmpty { throw ContractValidationError(field: "name", code: "required") }
if !self.name.isEmpty && self.name.utf8.count < 1 { throw ContractValidationError(field: "name", code: "min_length") }
if self.name.utf8.count > 256 { throw ContractValidationError(field: "name", code: "max_length") }
if self.state.isEmpty { throw ContractValidationError(field: "state", code: "required") }
if !self.state.isEmpty && self.state.utf8.count < 1 { throw ContractValidationError(field: "state", code: "min_length") }
if self.state.utf8.count > 64 { throw ContractValidationError(field: "state", code: "max_length") }
if let value = self.assignmentState {
if value.utf8.count > 64 { throw ContractValidationError(field: "assignment_state", code: "max_length") }
}
if self.version < 1 { throw ContractValidationError(field: "version", code: "minimum") }
if self.links.count > 16 { throw ContractValidationError(field: "links", code: "max_items") }
for item in self.links { try item.validate() }
}
public static func decodeJSON(_ data: Data) throws -> Self { try rejectDuplicateJSONKeys(data); return try JSONDecoder().decode(Self.self, from: data) }
public func encodeJSON() throws -> Data { try validate(); return try JSONEncoder().encode(self) }
}
public struct ResourceLink: Codable, Equatable {
public let type: String
public let id: String
public let version: Int64
enum CodingKeys: String, CodingKey {
case type = "type"
case id = "id"
case version = "version"
}
public init(type: String, id: String, version: Int64) throws {
self.type = type
self.id = id
self.version = version
try validate()
}
public init(from decoder: Decoder) throws {
let all = try decoder.container(keyedBy: AnyCodingKey.self)
for key in all.allKeys where CodingKeys(stringValue: key.stringValue) == nil { throw ContractValidationError(field: key.stringValue, code: "unknown_field") }
let c = try decoder.container(keyedBy: CodingKeys.self)
try self.init(type: try c.decode(String.self, forKey: .type), id: try c.decode(String.self, forKey: .id), version: try c.decode(Int64.self, forKey: .version))
}
public func validate() throws {
if self.type.isEmpty { throw ContractValidationError(field: "type", code: "required") }
if !self.type.isEmpty && self.type.utf8.count < 1 { throw ContractValidationError(field: "type", code: "min_length") }
if self.type.utf8.count > 64 { throw ContractValidationError(field: "type", code: "max_length") }
if self.id.isEmpty { throw ContractValidationError(field: "id", code: "required") }
if !self.id.isEmpty && self.id.utf8.count < 1 { throw ContractValidationError(field: "id", code: "min_length") }
if self.id.utf8.count > 128 { throw ContractValidationError(field: "id", code: "max_length") }
if self.version < 1 { throw ContractValidationError(field: "version", code: "minimum") }
}
public static func decodeJSON(_ data: Data) throws -> Self { try rejectDuplicateJSONKeys(data); return try JSONDecoder().decode(Self.self, from: data) }
public func encodeJSON() throws -> Data { try validate(); return try JSONEncoder().encode(self) }
}
public struct ResourceList: Codable, Equatable {
public let assignedDesktops: [AssignedDesktop]
public let entitledPools: [EntitledPool]
public let page: PageInfo
enum CodingKeys: String, CodingKey {
case assignedDesktops = "assigned_desktops"
case entitledPools = "entitled_pools"
case page = "page"
}
public init(assignedDesktops: [AssignedDesktop], entitledPools: [EntitledPool], page: PageInfo) throws {
self.assignedDesktops = assignedDesktops
self.entitledPools = entitledPools
self.page = page
try validate()
}
public init(from decoder: Decoder) throws {
let all = try decoder.container(keyedBy: AnyCodingKey.self)
for key in all.allKeys where CodingKeys(stringValue: key.stringValue) == nil { throw ContractValidationError(field: key.stringValue, code: "unknown_field") }
let c = try decoder.container(keyedBy: CodingKeys.self)
try self.init(assignedDesktops: try c.decode([AssignedDesktop].self, forKey: .assignedDesktops), entitledPools: try c.decode([EntitledPool].self, forKey: .entitledPools), page: try c.decode(PageInfo.self, forKey: .page))
}
public func validate() throws {
if self.assignedDesktops.count > 100 { throw ContractValidationError(field: "assigned_desktops", code: "max_items") }
for item in self.assignedDesktops { try item.validate() }
if self.entitledPools.count > 100 { throw ContractValidationError(field: "entitled_pools", code: "max_items") }
for item in self.entitledPools { try item.validate() }
try self.page.validate()
}
public static func decodeJSON(_ data: Data) throws -> Self { try rejectDuplicateJSONKeys(data); return try JSONDecoder().decode(Self.self, from: data) }
public func encodeJSON() throws -> Data { try validate(); return try JSONEncoder().encode(self) }
}
public struct SelectedSessionDescriptor: Codable, Equatable {
public let videoProfile: VideoProfile
public let audioProfile: AudioProfile
public let displayMode: DisplayMode
public let bitrateTargetKbps: Int64
public let bitrateMaximumKbps: Int64
public let adjustment: SessionAdjustment
public let mediaTimestampBasis: String
enum CodingKeys: String, CodingKey {
case videoProfile = "video_profile"
case audioProfile = "audio_profile"
case displayMode = "display_mode"
case bitrateTargetKbps = "bitrate_target_kbps"
case bitrateMaximumKbps = "bitrate_maximum_kbps"
case adjustment = "adjustment"
case mediaTimestampBasis = "media_timestamp_basis"
}
public init(videoProfile: VideoProfile, audioProfile: AudioProfile, displayMode: DisplayMode, bitrateTargetKbps: Int64, bitrateMaximumKbps: Int64, adjustment: SessionAdjustment, mediaTimestampBasis: String) throws {
self.videoProfile = videoProfile
self.audioProfile = audioProfile
self.displayMode = displayMode
self.bitrateTargetKbps = bitrateTargetKbps
self.bitrateMaximumKbps = bitrateMaximumKbps
self.adjustment = adjustment
self.mediaTimestampBasis = mediaTimestampBasis
try validate()
}
public init(from decoder: Decoder) throws {
let all = try decoder.container(keyedBy: AnyCodingKey.self)
for key in all.allKeys where CodingKeys(stringValue: key.stringValue) == nil { throw ContractValidationError(field: key.stringValue, code: "unknown_field") }
let c = try decoder.container(keyedBy: CodingKeys.self)
try self.init(videoProfile: try c.decode(VideoProfile.self, forKey: .videoProfile), audioProfile: try c.decode(AudioProfile.self, forKey: .audioProfile), displayMode: try c.decode(DisplayMode.self, forKey: .displayMode), bitrateTargetKbps: try c.decode(Int64.self, forKey: .bitrateTargetKbps), bitrateMaximumKbps: try c.decode(Int64.self, forKey: .bitrateMaximumKbps), adjustment: try c.decode(SessionAdjustment.self, forKey: .adjustment), mediaTimestampBasis: try c.decode(String.self, forKey: .mediaTimestampBasis))
}
public func validate() throws {
try self.videoProfile.validate()
try self.audioProfile.validate()
try self.displayMode.validate()
if self.bitrateTargetKbps < 100 { throw ContractValidationError(field: "bitrate_target_kbps", code: "minimum") }
if self.bitrateTargetKbps > 1000000 { throw ContractValidationError(field: "bitrate_target_kbps", code: "maximum") }
if self.bitrateMaximumKbps < 100 { throw ContractValidationError(field: "bitrate_maximum_kbps", code: "minimum") }
if self.bitrateMaximumKbps > 1000000 { throw ContractValidationError(field: "bitrate_maximum_kbps", code: "maximum") }
try self.adjustment.validate()
if self.mediaTimestampBasis != "gateway-send-wall-clock-ms" { throw ContractValidationError(field: "media_timestamp_basis", code: "invalid_value") }
if bitrateTargetKbps > bitrateMaximumKbps { throw ContractValidationError(field: "bitrate_bounds", code: "invalid_order") }
}
public static func decodeJSON(_ data: Data) throws -> Self { try rejectDuplicateJSONKeys(data); return try JSONDecoder().decode(Self.self, from: data) }
public func encodeJSON() throws -> Data { try validate(); return try JSONEncoder().encode(self) }
}
public struct SessionAdjustment: Codable, Equatable {
public let displayReason: String
public let bitrateReason: String
enum CodingKeys: String, CodingKey {
case displayReason = "display_reason"
case bitrateReason = "bitrate_reason"
}
public init(displayReason: String, bitrateReason: String) throws {
self.displayReason = displayReason
self.bitrateReason = bitrateReason
try validate()
}
public init(from decoder: Decoder) throws {
let all = try decoder.container(keyedBy: AnyCodingKey.self)
for key in all.allKeys where CodingKeys(stringValue: key.stringValue) == nil { throw ContractValidationError(field: key.stringValue, code: "unknown_field") }
let c = try decoder.container(keyedBy: CodingKeys.self)
try self.init(displayReason: try c.decode(String.self, forKey: .displayReason), bitrateReason: try c.decode(String.self, forKey: .bitrateReason))
}
public func validate() throws {
if !["none", "policy_clamp", "direct_entitlement_override"].contains(self.displayReason) { throw ContractValidationError(field: "display_reason", code: "invalid_value") }
if !["none", "policy_default", "session_ceiling_clamp", "aggregate_capacity_clamp"].contains(self.bitrateReason) { throw ContractValidationError(field: "bitrate_reason", code: "invalid_value") }
}
public static func decodeJSON(_ data: Data) throws -> Self { try rejectDuplicateJSONKeys(data); return try JSONDecoder().decode(Self.self, from: data) }
public func encodeJSON() throws -> Data { try validate(); return try JSONEncoder().encode(self) }
}
public struct SessionAuthority: Codable, Equatable {
public let version: String
public let sessionId: String
public let gatewayId: String
public let audience: String
public let reconnectSequence: Int64
public let expiresAt: String
public let capabilities: CapabilityProfile
public let providerProfile: String
public let providerIdentity: String
public let selectedDescriptor: SelectedSessionDescriptor
enum CodingKeys: String, CodingKey {
case version = "version"
case sessionId = "session_id"
case gatewayId = "gateway_id"
case audience = "audience"
case reconnectSequence = "reconnect_sequence"
case expiresAt = "expires_at"
case capabilities = "capabilities"
case providerProfile = "provider_profile"
case providerIdentity = "provider_identity"
case selectedDescriptor = "selected_descriptor"
}
public init(version: String, sessionId: String, gatewayId: String, audience: String, reconnectSequence: Int64, expiresAt: String, capabilities: CapabilityProfile, providerProfile: String, providerIdentity: String, selectedDescriptor: SelectedSessionDescriptor) throws {
self.version = version
self.sessionId = sessionId
self.gatewayId = gatewayId
self.audience = audience
self.reconnectSequence = reconnectSequence
self.expiresAt = expiresAt
self.capabilities = capabilities
self.providerProfile = providerProfile
self.providerIdentity = providerIdentity
self.selectedDescriptor = selectedDescriptor
try validate()
}
public init(from decoder: Decoder) throws {
let all = try decoder.container(keyedBy: AnyCodingKey.self)
for key in all.allKeys where CodingKeys(stringValue: key.stringValue) == nil { throw ContractValidationError(field: key.stringValue, code: "unknown_field") }
let c = try decoder.container(keyedBy: CodingKeys.self)
try self.init(version: try c.decode(String.self, forKey: .version), sessionId: try c.decode(String.self, forKey: .sessionId), gatewayId: try c.decode(String.self, forKey: .gatewayId), audience: try c.decode(String.self, forKey: .audience), reconnectSequence: try c.decode(Int64.self, forKey: .reconnectSequence), expiresAt: try c.decode(String.self, forKey: .expiresAt), capabilities: try c.decode(CapabilityProfile.self, forKey: .capabilities), providerProfile: try c.decode(String.self, forKey: .providerProfile), providerIdentity: try c.decode(String.self, forKey: .providerIdentity), selectedDescriptor: try c.decode(SelectedSessionDescriptor.self, forKey: .selectedDescriptor))
}
public func validate() throws {
if self.version != "1" { throw ContractValidationError(field: "version", code: "invalid_value") }
if self.sessionId.isEmpty { throw ContractValidationError(field: "session_id", code: "required") }
if !self.sessionId.isEmpty && self.sessionId.utf8.count < 1 { throw ContractValidationError(field: "session_id", code: "min_length") }
if self.sessionId.utf8.count > 128 { throw ContractValidationError(field: "session_id", code: "max_length") }
if self.gatewayId.isEmpty { throw ContractValidationError(field: "gateway_id", code: "required") }
if !self.gatewayId.isEmpty && self.gatewayId.utf8.count < 1 { throw ContractValidationError(field: "gateway_id", code: "min_length") }
if self.gatewayId.utf8.count > 128 { throw ContractValidationError(field: "gateway_id", code: "max_length") }
if self.audience.isEmpty { throw ContractValidationError(field: "audience", code: "required") }
if !self.audience.isEmpty && self.audience.utf8.count < 1 { throw ContractValidationError(field: "audience", code: "min_length") }
if self.audience.utf8.count > 256 { throw ContractValidationError(field: "audience", code: "max_length") }
if self.reconnectSequence < 0 { throw ContractValidationError(field: "reconnect_sequence", code: "minimum") }
if self.expiresAt.utf8.count > 64 { throw ContractValidationError(field: "expires_at", code: "max_length") }
if !validRFC3339UTC(self.expiresAt) { throw ContractValidationError(field: "expires_at", code: "invalid_time") }
try self.capabilities.validate()
if !["apollo"].contains(self.providerProfile) { throw ContractValidationError(field: "provider_profile", code: "invalid_value") }
if self.providerIdentity.isEmpty { throw ContractValidationError(field: "provider_identity", code: "required") }
if !self.providerIdentity.isEmpty && self.providerIdentity.utf8.count < 1 { throw ContractValidationError(field: "provider_identity", code: "min_length") }
if self.providerIdentity.utf8.count > 256 { throw ContractValidationError(field: "provider_identity", code: "max_length") }
try self.selectedDescriptor.validate()
}
public static func decodeJSON(_ data: Data) throws -> Self { try rejectDuplicateJSONKeys(data); return try JSONDecoder().decode(Self.self, from: data) }
public func encodeJSON() throws -> Data { try validate(); return try JSONEncoder().encode(self) }
}
public struct SessionQualityLimits: Codable, Equatable {
public let policyVersionId: String
public let policyDisplayLimit: DisplayMode
public let selectableDisplayMaximum: DisplayMode
public let displayLimitOverride: Bool
public let bitrateMinimumKbps: Int64
public let bitrateTargetKbps: Int64
public let bitrateMaximumKbps: Int64
enum CodingKeys: String, CodingKey {
case policyVersionId = "policy_version_id"
case policyDisplayLimit = "policy_display_limit"
case selectableDisplayMaximum = "selectable_display_maximum"
case displayLimitOverride = "display_limit_override"
case bitrateMinimumKbps = "bitrate_minimum_kbps"
case bitrateTargetKbps = "bitrate_target_kbps"
case bitrateMaximumKbps = "bitrate_maximum_kbps"
}
public init(policyVersionId: String, policyDisplayLimit: DisplayMode, selectableDisplayMaximum: DisplayMode, displayLimitOverride: Bool, bitrateMinimumKbps: Int64, bitrateTargetKbps: Int64, bitrateMaximumKbps: Int64) throws {
self.policyVersionId = policyVersionId
self.policyDisplayLimit = policyDisplayLimit
self.selectableDisplayMaximum = selectableDisplayMaximum
self.displayLimitOverride = displayLimitOverride
self.bitrateMinimumKbps = bitrateMinimumKbps
self.bitrateTargetKbps = bitrateTargetKbps
self.bitrateMaximumKbps = bitrateMaximumKbps
try validate()
}
public init(from decoder: Decoder) throws {
let all = try decoder.container(keyedBy: AnyCodingKey.self)
for key in all.allKeys where CodingKeys(stringValue: key.stringValue) == nil { throw ContractValidationError(field: key.stringValue, code: "unknown_field") }
let c = try decoder.container(keyedBy: CodingKeys.self)
try self.init(policyVersionId: try c.decode(String.self, forKey: .policyVersionId), policyDisplayLimit: try c.decode(DisplayMode.self, forKey: .policyDisplayLimit), selectableDisplayMaximum: try c.decode(DisplayMode.self, forKey: .selectableDisplayMaximum), displayLimitOverride: try c.decode(Bool.self, forKey: .displayLimitOverride), bitrateMinimumKbps: try c.decode(Int64.self, forKey: .bitrateMinimumKbps), bitrateTargetKbps: try c.decode(Int64.self, forKey: .bitrateTargetKbps), bitrateMaximumKbps: try c.decode(Int64.self, forKey: .bitrateMaximumKbps))
}
public func validate() throws {
if self.policyVersionId.isEmpty { throw ContractValidationError(field: "policy_version_id", code: "required") }
if !self.policyVersionId.isEmpty && self.policyVersionId.utf8.count < 1 { throw ContractValidationError(field: "policy_version_id", code: "min_length") }
if self.policyVersionId.utf8.count > 128 { throw ContractValidationError(field: "policy_version_id", code: "max_length") }
try self.policyDisplayLimit.validate()
try self.selectableDisplayMaximum.validate()
if self.bitrateMinimumKbps < 100 { throw ContractValidationError(field: "bitrate_minimum_kbps", code: "minimum") }
if self.bitrateMinimumKbps > 1000000 { throw ContractValidationError(field: "bitrate_minimum_kbps", code: "maximum") }
if self.bitrateTargetKbps < 100 { throw ContractValidationError(field: "bitrate_target_kbps", code: "minimum") }
if self.bitrateTargetKbps > 1000000 { throw ContractValidationError(field: "bitrate_target_kbps", code: "maximum") }
if self.bitrateMaximumKbps < 100 { throw ContractValidationError(field: "bitrate_maximum_kbps", code: "minimum") }
if self.bitrateMaximumKbps > 1000000 { throw ContractValidationError(field: "bitrate_maximum_kbps", code: "maximum") }
if bitrateMinimumKbps > bitrateTargetKbps || bitrateTargetKbps > bitrateMaximumKbps { throw ContractValidationError(field: "bitrate_bounds", code: "invalid_order") }
}
public static func decodeJSON(_ data: Data) throws -> Self { try rejectDuplicateJSONKeys(data); return try JSONDecoder().decode(Self.self, from: data) }
public func encodeJSON() throws -> Data { try validate(); return try JSONEncoder().encode(self) }
}
public struct SessionRequest: Codable, Equatable {
public let clientDeviceId: String
public let deviceKeyId: String
public let poolId: String
public let idempotencyKey: String
public let videoProfiles: [VideoProfile]
public let bitratePreference: BitratePreference
public let requestedDisplayMode: DisplayMode?
enum CodingKeys: String, CodingKey {
case clientDeviceId = "client_device_id"
case deviceKeyId = "device_key_id"
case poolId = "pool_id"
case idempotencyKey = "idempotency_key"
case videoProfiles = "video_profiles"
case bitratePreference = "bitrate_preference"
case requestedDisplayMode = "requested_display_mode"
}
public init(clientDeviceId: String, deviceKeyId: String, poolId: String, idempotencyKey: String, videoProfiles: [VideoProfile], bitratePreference: BitratePreference, requestedDisplayMode: DisplayMode?) throws {
self.clientDeviceId = clientDeviceId
self.deviceKeyId = deviceKeyId
self.poolId = poolId
self.idempotencyKey = idempotencyKey
self.videoProfiles = videoProfiles
self.bitratePreference = bitratePreference
self.requestedDisplayMode = requestedDisplayMode
try validate()
}
public init(from decoder: Decoder) throws {
let all = try decoder.container(keyedBy: AnyCodingKey.self)
for key in all.allKeys where CodingKeys(stringValue: key.stringValue) == nil { throw ContractValidationError(field: key.stringValue, code: "unknown_field") }
let c = try decoder.container(keyedBy: CodingKeys.self)
try self.init(clientDeviceId: try c.decode(String.self, forKey: .clientDeviceId), deviceKeyId: try c.decode(String.self, forKey: .deviceKeyId), poolId: try c.decode(String.self, forKey: .poolId), idempotencyKey: try c.decode(String.self, forKey: .idempotencyKey), videoProfiles: try c.decode([VideoProfile].self, forKey: .videoProfiles), bitratePreference: try c.decode(BitratePreference.self, forKey: .bitratePreference), requestedDisplayMode: try c.contains(.requestedDisplayMode) ? c.decode(DisplayMode.self, forKey: .requestedDisplayMode) : nil)
}
public func validate() throws {
if self.clientDeviceId.isEmpty { throw ContractValidationError(field: "client_device_id", code: "required") }
if !self.clientDeviceId.isEmpty && self.clientDeviceId.utf8.count < 1 { throw ContractValidationError(field: "client_device_id", code: "min_length") }
if self.clientDeviceId.utf8.count > 128 { throw ContractValidationError(field: "client_device_id", code: "max_length") }
if self.deviceKeyId.isEmpty { throw ContractValidationError(field: "device_key_id", code: "required") }
if !self.deviceKeyId.isEmpty && self.deviceKeyId.utf8.count < 1 { throw ContractValidationError(field: "device_key_id", code: "min_length") }
if self.deviceKeyId.utf8.count > 128 { throw ContractValidationError(field: "device_key_id", code: "max_length") }
if self.poolId.isEmpty { throw ContractValidationError(field: "pool_id", code: "required") }
if !self.poolId.isEmpty && self.poolId.utf8.count < 1 { throw ContractValidationError(field: "pool_id", code: "min_length") }
if self.poolId.utf8.count > 128 { throw ContractValidationError(field: "pool_id", code: "max_length") }
if self.idempotencyKey.isEmpty { throw ContractValidationError(field: "idempotency_key", code: "required") }
if !self.idempotencyKey.isEmpty && self.idempotencyKey.utf8.count < 1 { throw ContractValidationError(field: "idempotency_key", code: "min_length") }
if self.idempotencyKey.utf8.count > 256 { throw ContractValidationError(field: "idempotency_key", code: "max_length") }
if self.videoProfiles.count < 1 { throw ContractValidationError(field: "video_profiles", code: "min_items") }
if self.videoProfiles.count > 12 { throw ContractValidationError(field: "video_profiles", code: "max_items") }
for (index, item) in self.videoProfiles.enumerated() where self.videoProfiles[..<index].contains(item) { throw ContractValidationError(field: "video_profiles", code: "duplicate_item") }
for item in self.videoProfiles { try item.validate() }
try self.bitratePreference.validate()
if let value = self.requestedDisplayMode {
try value.validate()
}
}
public static func decodeJSON(_ data: Data) throws -> Self { try rejectDuplicateJSONKeys(data); return try JSONDecoder().decode(Self.self, from: data) }
public func encodeJSON() throws -> Data { try validate(); return try JSONEncoder().encode(self) }
}
public struct StableError: Codable, Equatable {
public let version: String
public let code: String
public let message: String
public let retryable: Bool
enum CodingKeys: String, CodingKey {
case version = "version"
case code = "code"
case message = "message"
case retryable = "retryable"
}
public init(version: String, code: String, message: String, retryable: Bool) throws {
self.version = version
self.code = code
self.message = message
self.retryable = retryable
try validate()
}
public init(from decoder: Decoder) throws {
let all = try decoder.container(keyedBy: AnyCodingKey.self)
for key in all.allKeys where CodingKeys(stringValue: key.stringValue) == nil { throw ContractValidationError(field: key.stringValue, code: "unknown_field") }
let c = try decoder.container(keyedBy: CodingKeys.self)
try self.init(version: try c.decode(String.self, forKey: .version), code: try c.decode(String.self, forKey: .code), message: try c.decode(String.self, forKey: .message), retryable: try c.decode(Bool.self, forKey: .retryable))
}
public func validate() throws {
if self.version != "1" { throw ContractValidationError(field: "version", code: "invalid_value") }
if self.code.isEmpty { throw ContractValidationError(field: "code", code: "required") }
if !self.code.isEmpty && self.code.utf8.count < 1 { throw ContractValidationError(field: "code", code: "min_length") }
if self.code.utf8.count > 128 { throw ContractValidationError(field: "code", code: "max_length") }
if self.message.isEmpty { throw ContractValidationError(field: "message", code: "required") }
if !self.message.isEmpty && self.message.utf8.count < 1 { throw ContractValidationError(field: "message", code: "min_length") }
if self.message.utf8.count > 512 { throw ContractValidationError(field: "message", code: "max_length") }
}
public static func decodeJSON(_ data: Data) throws -> Self { try rejectDuplicateJSONKeys(data); return try JSONDecoder().decode(Self.self, from: data) }
public func encodeJSON() throws -> Data { try validate(); return try JSONEncoder().encode(self) }
}
public struct StopOperation: Codable, Equatable {
public let operationId: String
public let sessionId: String
public let state: String
public let sessionVersion: Int64
public let createdAt: String
public let deadlineAt: String
public let updatedAt: String
public let failureCode: String?
enum CodingKeys: String, CodingKey {
case operationId = "operation_id"
case sessionId = "session_id"
case state = "state"
case sessionVersion = "session_version"
case createdAt = "created_at"
case deadlineAt = "deadline_at"
case updatedAt = "updated_at"
case failureCode = "failure_code"
}
public init(operationId: String, sessionId: String, state: String, sessionVersion: Int64, createdAt: String, deadlineAt: String, updatedAt: String, failureCode: String?) throws {
self.operationId = operationId
self.sessionId = sessionId
self.state = state
self.sessionVersion = sessionVersion
self.createdAt = createdAt
self.deadlineAt = deadlineAt
self.updatedAt = updatedAt
self.failureCode = failureCode
try validate()
}
public init(from decoder: Decoder) throws {
let all = try decoder.container(keyedBy: AnyCodingKey.self)
for key in all.allKeys where CodingKeys(stringValue: key.stringValue) == nil { throw ContractValidationError(field: key.stringValue, code: "unknown_field") }
let c = try decoder.container(keyedBy: CodingKeys.self)
try self.init(operationId: try c.decode(String.self, forKey: .operationId), sessionId: try c.decode(String.self, forKey: .sessionId), state: try c.decode(String.self, forKey: .state), sessionVersion: try c.decode(Int64.self, forKey: .sessionVersion), createdAt: try c.decode(String.self, forKey: .createdAt), deadlineAt: try c.decode(String.self, forKey: .deadlineAt), updatedAt: try c.decode(String.self, forKey: .updatedAt), failureCode: try c.decodeIfPresent(String.self, forKey: .failureCode))
}
public func validate() throws {
if self.operationId.isEmpty { throw ContractValidationError(field: "operation_id", code: "required") }
if !self.operationId.isEmpty && self.operationId.utf8.count < 36 { throw ContractValidationError(field: "operation_id", code: "min_length") }
if self.operationId.utf8.count > 36 { throw ContractValidationError(field: "operation_id", code: "max_length") }
if !validCanonicalUUID(self.operationId) { throw ContractValidationError(field: "operation_id", code: "invalid_uuid") }
if self.sessionId.isEmpty { throw ContractValidationError(field: "session_id", code: "required") }
if !self.sessionId.isEmpty && self.sessionId.utf8.count < 1 { throw ContractValidationError(field: "session_id", code: "min_length") }
if self.sessionId.utf8.count > 128 { throw ContractValidationError(field: "session_id", code: "max_length") }
if !["pending", "attempting", "applied", "failed", "termination_unconfirmed"].contains(self.state) { throw ContractValidationError(field: "state", code: "invalid_value") }
if self.sessionVersion < 1 { throw ContractValidationError(field: "session_version", code: "minimum") }
if self.createdAt.utf8.count > 64 { throw ContractValidationError(field: "created_at", code: "max_length") }
if !validRFC3339UTC(self.createdAt) { throw ContractValidationError(field: "created_at", code: "invalid_time") }
if self.deadlineAt.utf8.count > 64 { throw ContractValidationError(field: "deadline_at", code: "max_length") }
if !validRFC3339UTC(self.deadlineAt) { throw ContractValidationError(field: "deadline_at", code: "invalid_time") }
if self.updatedAt.utf8.count > 64 { throw ContractValidationError(field: "updated_at", code: "max_length") }
if !validRFC3339UTC(self.updatedAt) { throw ContractValidationError(field: "updated_at", code: "invalid_time") }
if let value = self.failureCode {
if !value.isEmpty && value.utf8.count < 1 { throw ContractValidationError(field: "failure_code", code: "min_length") }
if value.utf8.count > 128 { throw ContractValidationError(field: "failure_code", code: "max_length") }
}
}
public static func decodeJSON(_ data: Data) throws -> Self { try rejectDuplicateJSONKeys(data); return try JSONDecoder().decode(Self.self, from: data) }
public func encodeJSON() throws -> Data { try validate(); return try JSONEncoder().encode(self) }
}
public struct TunnelAdmissionRequest: Codable, Equatable {
public let version: String
public let sessionId: String
public let gatewayId: String
public let audience: String
public let grant: String
public let reconnectSequence: Int64
public let clientNonce: String
public let deviceSignature: String
public let capabilities: CapabilityProfile
enum CodingKeys: String, CodingKey {
case version = "version"
case sessionId = "session_id"
case gatewayId = "gateway_id"
case audience = "audience"
case grant = "grant"
case reconnectSequence = "reconnect_sequence"
case clientNonce = "client_nonce"
case deviceSignature = "device_signature"
case capabilities = "capabilities"
}
public init(version: String, sessionId: String, gatewayId: String, audience: String, grant: String, reconnectSequence: Int64, clientNonce: String, deviceSignature: String, capabilities: CapabilityProfile) throws {
self.version = version
self.sessionId = sessionId
self.gatewayId = gatewayId
self.audience = audience
self.grant = grant
self.reconnectSequence = reconnectSequence
self.clientNonce = clientNonce
self.deviceSignature = deviceSignature
self.capabilities = capabilities
try validate()
}
public init(from decoder: Decoder) throws {
let all = try decoder.container(keyedBy: AnyCodingKey.self)
for key in all.allKeys where CodingKeys(stringValue: key.stringValue) == nil { throw ContractValidationError(field: key.stringValue, code: "unknown_field") }
let c = try decoder.container(keyedBy: CodingKeys.self)
try self.init(version: try c.decode(String.self, forKey: .version), sessionId: try c.decode(String.self, forKey: .sessionId), gatewayId: try c.decode(String.self, forKey: .gatewayId), audience: try c.decode(String.self, forKey: .audience), grant: try c.decode(String.self, forKey: .grant), reconnectSequence: try c.decode(Int64.self, forKey: .reconnectSequence), clientNonce: try c.decode(String.self, forKey: .clientNonce), deviceSignature: try c.decode(String.self, forKey: .deviceSignature), capabilities: try c.decode(CapabilityProfile.self, forKey: .capabilities))
}
public func validate() throws {
if self.version != "1" { throw ContractValidationError(field: "version", code: "invalid_value") }
if self.sessionId.isEmpty { throw ContractValidationError(field: "session_id", code: "required") }
if !self.sessionId.isEmpty && self.sessionId.utf8.count < 1 { throw ContractValidationError(field: "session_id", code: "min_length") }
if self.sessionId.utf8.count > 128 { throw ContractValidationError(field: "session_id", code: "max_length") }
if self.gatewayId.isEmpty { throw ContractValidationError(field: "gateway_id", code: "required") }
if !self.gatewayId.isEmpty && self.gatewayId.utf8.count < 1 { throw ContractValidationError(field: "gateway_id", code: "min_length") }
if self.gatewayId.utf8.count > 128 { throw ContractValidationError(field: "gateway_id", code: "max_length") }
if self.audience.isEmpty { throw ContractValidationError(field: "audience", code: "required") }
if !self.audience.isEmpty && self.audience.utf8.count < 1 { throw ContractValidationError(field: "audience", code: "min_length") }
if self.audience.utf8.count > 256 { throw ContractValidationError(field: "audience", code: "max_length") }
if self.grant.isEmpty { throw ContractValidationError(field: "grant", code: "required") }
if !self.grant.isEmpty && self.grant.utf8.count < 43 { throw ContractValidationError(field: "grant", code: "min_length") }
if self.grant.utf8.count > 256 { throw ContractValidationError(field: "grant", code: "max_length") }
if self.reconnectSequence < 0 { throw ContractValidationError(field: "reconnect_sequence", code: "minimum") }
if self.clientNonce.isEmpty { throw ContractValidationError(field: "client_nonce", code: "required") }
if !self.clientNonce.isEmpty && self.clientNonce.utf8.count < 16 { throw ContractValidationError(field: "client_nonce", code: "min_length") }
if self.clientNonce.utf8.count > 128 { throw ContractValidationError(field: "client_nonce", code: "max_length") }
if self.deviceSignature.isEmpty { throw ContractValidationError(field: "device_signature", code: "required") }
if !self.deviceSignature.isEmpty && self.deviceSignature.utf8.count < 86 { throw ContractValidationError(field: "device_signature", code: "min_length") }
if self.deviceSignature.utf8.count > 86 { throw ContractValidationError(field: "device_signature", code: "max_length") }
try self.capabilities.validate()
}
public static func decodeJSON(_ data: Data) throws -> Self { try rejectDuplicateJSONKeys(data); return try JSONDecoder().decode(Self.self, from: data) }
public func encodeJSON() throws -> Data { try validate(); return try JSONEncoder().encode(self) }
}
public struct VersionNegotiation: Codable, Equatable {
public let supportedVersions: [String]
public let features: [String]
enum CodingKeys: String, CodingKey {
case supportedVersions = "supported_versions"
case features = "features"
}
public init(supportedVersions: [String], features: [String]) throws {
self.supportedVersions = supportedVersions
self.features = features
try validate()
}
public init(from decoder: Decoder) throws {
let all = try decoder.container(keyedBy: AnyCodingKey.self)
for key in all.allKeys where CodingKeys(stringValue: key.stringValue) == nil { throw ContractValidationError(field: key.stringValue, code: "unknown_field") }
let c = try decoder.container(keyedBy: CodingKeys.self)
try self.init(supportedVersions: try c.decode([String].self, forKey: .supportedVersions), features: try c.decode([String].self, forKey: .features))
}
public func validate() throws {
if self.supportedVersions.count < 1 { throw ContractValidationError(field: "supported_versions", code: "min_items") }
if self.supportedVersions.count > 3 { throw ContractValidationError(field: "supported_versions", code: "max_items") }
for item in self.supportedVersions where item.utf8.count > 16 { throw ContractValidationError(field: "supported_versions", code: "max_item_length") }
if self.features.count > 64 { throw ContractValidationError(field: "features", code: "max_items") }
for item in self.features where item.utf8.count > 64 { throw ContractValidationError(field: "features", code: "max_item_length") }
}
public static func decodeJSON(_ data: Data) throws -> Self { try rejectDuplicateJSONKeys(data); return try JSONDecoder().decode(Self.self, from: data) }
public func encodeJSON() throws -> Data { try validate(); return try JSONEncoder().encode(self) }
}
public struct VideoProfile: Codable, Equatable {
public let codec: String
public let bitDepth: Int64
public let chromaSubsampling: String
public let colorSpace: String
public let transferFunction: String
enum CodingKeys: String, CodingKey {
case codec = "codec"
case bitDepth = "bit_depth"
case chromaSubsampling = "chroma_subsampling"
case colorSpace = "color_space"
case transferFunction = "transfer_function"
}
public init(codec: String, bitDepth: Int64, chromaSubsampling: String, colorSpace: String, transferFunction: String) throws {
self.codec = codec
self.bitDepth = bitDepth
self.chromaSubsampling = chromaSubsampling
self.colorSpace = colorSpace
self.transferFunction = transferFunction
try validate()
}
public init(from decoder: Decoder) throws {
let all = try decoder.container(keyedBy: AnyCodingKey.self)
for key in all.allKeys where CodingKeys(stringValue: key.stringValue) == nil { throw ContractValidationError(field: key.stringValue, code: "unknown_field") }
let c = try decoder.container(keyedBy: CodingKeys.self)
try self.init(codec: try c.decode(String.self, forKey: .codec), bitDepth: try c.decode(Int64.self, forKey: .bitDepth), chromaSubsampling: try c.decode(String.self, forKey: .chromaSubsampling), colorSpace: try c.decode(String.self, forKey: .colorSpace), transferFunction: try c.decode(String.self, forKey: .transferFunction))
}
public func validate() throws {
if !["h264", "hevc", "av1"].contains(self.codec) { throw ContractValidationError(field: "codec", code: "invalid_value") }
if self.bitDepth < 8 { throw ContractValidationError(field: "bit_depth", code: "minimum") }
if self.bitDepth > 8 { throw ContractValidationError(field: "bit_depth", code: "maximum") }
if self.chromaSubsampling != "4:2:0" { throw ContractValidationError(field: "chroma_subsampling", code: "invalid_value") }
if self.colorSpace != "bt709-limited" { throw ContractValidationError(field: "color_space", code: "invalid_value") }
if self.transferFunction != "sdr" { throw ContractValidationError(field: "transfer_function", code: "invalid_value") }
}
public static func decodeJSON(_ data: Data) throws -> Self { try rejectDuplicateJSONKeys(data); return try JSONDecoder().decode(Self.self, from: data) }
public func encodeJSON() throws -> Data { try validate(); return try JSONEncoder().encode(self) }
}
public func deviceRegistrationProofTranscript(serverID: Data, principalID: Data, deviceID: Data, challenge: Data, expiryUnixMilliseconds: Int64) throws -> Data {
for (field, value, length) in [("server_id", serverID, 16), ("principal_id", principalID, 16), ("device_id", deviceID, 16), ("challenge", challenge, 32)] {
if value.count != length { throw ContractValidationError(field: field, code: "invalid_length") }
}
if expiryUnixMilliseconds < 0 { throw ContractValidationError(field: "expiry_unix_milliseconds", code: "minimum") }
var transcript = Data("versevdi-device-proof-v1".utf8)
transcript.append(serverID)
transcript.append(principalID)
transcript.append(deviceID)
transcript.append(challenge)
var expiry = UInt64(expiryUnixMilliseconds).bigEndian
Swift.withUnsafeBytes(of: &expiry) { transcript.append(contentsOf: $0) }
return transcript
}
public extension TunnelAdmissionRequest {
func deviceAdmissionTranscript() -> Data {
var fields = [sessionId, gatewayId, audience, grant, String(reconnectSequence), clientNonce, capabilities.transport, capabilities.framing, capabilities.media, capabilities.sourceRateControl, String(capabilities.videoProfiles.count), String(capabilities.audioProfiles.count)]
for profile in capabilities.videoProfiles { fields.append(contentsOf: [profile.codec, String(profile.bitDepth), profile.chromaSubsampling, profile.colorSpace, profile.transferFunction]) }
for profile in capabilities.audioProfiles { fields.append(contentsOf: [profile.codec, String(profile.sampleRateHz), String(profile.channels), profile.channelLayout, String(profile.packetDurationMs)]) }
var transcript = "versevdi/tunnel-admission/v1"
for field in fields { transcript += "\(field.utf8.count):\(field)" }
return Data(transcript.utf8)
}
}
public extension CapabilityProfile {
static func intersection(_ profiles: [CapabilityProfile]) throws -> CapabilityProfile {
guard let selected = profiles.first else { throw ContractValidationError(field: "capabilities", code: "no_overlap") }
try selected.validate()
var commonVideo = selected.videoProfiles
var commonAudio = selected.audioProfiles
for profile in profiles.dropFirst() {
try profile.validate()
if profile.transport != selected.transport || profile.framing != selected.framing || profile.media != selected.media || profile.sourceRateControl != selected.sourceRateControl { throw ContractValidationError(field: "capabilities", code: "no_overlap") }
commonVideo = commonVideo.filter { profile.videoProfiles.contains($0) }
commonAudio = commonAudio.filter { profile.audioProfiles.contains($0) }
if commonVideo.isEmpty || commonAudio.isEmpty { throw ContractValidationError(field: "capabilities", code: "no_overlap") }
}
return try CapabilityProfile(transport: selected.transport, framing: selected.framing, media: selected.media, sourceRateControl: selected.sourceRateControl, videoProfiles: commonVideo, audioProfiles: commonAudio)
}
}