Files
zeekay a5d59ebc9d one document, one generator, one lock
Regenerated from hanzoai/cloud's openapi.yaml at the commit .spec-lock now
names, by hanzoai/openapi's generate.py under a `swift:` row — the same driver,
the same pinned generator and the same document as every other client.

What was here projected hanzo.yaml at info.version 8.0.0 through a generator
version nothing else in the fleet uses, and recorded neither: 1937 of the 2308
addresses it published appear in neither cloud's emission nor any projection of
it. This client publishes 2479, as 192 API types over 2460 models, with no
dependency.

Four things Swift needs said, all of them in the row: swift6 for typed throws,
four model names its own modules own, the legacy snake/camel property pairs it
would otherwise declare twice, and the two schemas that store themselves, which
a struct cannot. One generator template is overridden so the transport compiles
where corelibs Foundation keeps URLSession — which is what makes `swift build`
a gate this fleet's runners can run.

Package.swift comes from the generator now, so the language mode and the code
it compiles have one home. The Carthage, CocoaPods and XcodeGen manifests are
gone with the old generator's docs: SwiftPM resolves this package.
2026-08-14 20:19:17 -07:00

39 lines
1.5 KiB
Swift

import Foundation
import Hanzo
/// Where the API is and who we are. Every flow reads it from here and nothing
/// else configures a client.
public enum Flow {
/// `https://api.hanzo.ai`, or whatever `HANZO_BASE_URL` names — a staging
/// cloud, a local one, a tunnel.
public static var base: String {
ProcessInfo.processInfo.environment["HANZO_BASE_URL"] ?? "https://api.hanzo.ai"
}
/// The document declares one security scheme, `bearer`, and the generator
/// has no token field — so the credential goes in this header and nowhere
/// else. `authenticated: false` is for the four operations that carry
/// `security: []`.
public static func configure(authenticated: Bool = true) {
HanzoAPIConfiguration.shared.basePath = base
guard authenticated else { return }
guard let key = ProcessInfo.processInfo.environment["HANZO_API_KEY"] else {
fail("HANZO_API_KEY is not set — export an IAM access token or an API key")
}
HanzoAPIConfiguration.shared.customHeaders["Authorization"] = "Bearer \(key)"
}
/// The server's own message, which the status code alone never carries.
public static func fail(_ message: String) -> Never {
FileHandle.standardError.write(Data((message + "\n").utf8))
exit(1)
}
public static func fail(_ error: ErrorResponse) -> Never {
switch error {
case let .error(status, data, _, _):
fail("HTTP \(status): \(String(decoding: data ?? Data(), as: UTF8.self))")
}
}
}