Skip to content

Commit 6e1ff4d

Browse files
committed
Add convenience constructors so that clients do not have to know about the value<x> field of the anyOf to assign.
1 parent e706c33 commit 6e1ff4d

File tree

2 files changed

+50
-14
lines changed

2 files changed

+50
-14
lines changed

Sources/SwiftlyCore/HTTPClient.swift

Lines changed: 48 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import NIOHTTP1
88
import OpenAPIAsyncHTTPClient
99
import OpenAPIRuntime
1010

11-
extension Components.Schemas.SwiftlyRelease {
11+
public extension Components.Schemas.SwiftlyRelease {
1212
public var swiftlyVersion: SwiftlyVersion {
1313
get throws {
1414
guard let releaseVersion = try? SwiftlyVersion(parsing: self.version) else {
@@ -20,7 +20,7 @@ extension Components.Schemas.SwiftlyRelease {
2020
}
2121
}
2222

23-
extension Components.Schemas.SwiftlyReleasePlatformArtifacts {
23+
public extension Components.Schemas.SwiftlyReleasePlatformArtifacts {
2424
public var isDarwin: Bool {
2525
self.platform.value1 == .darwin
2626
}
@@ -50,6 +50,12 @@ extension Components.Schemas.SwiftlyReleasePlatformArtifacts {
5050
}
5151
}
5252

53+
public extension Components.Schemas.SwiftlyPlatformIdentifier {
54+
init(_ knownSwiftlyPlatformIdentifier: Components.Schemas.KnownSwiftlyPlatformIdentifier) {
55+
self.init(value1: knownSwiftlyPlatformIdentifier)
56+
}
57+
}
58+
5359
public protocol HTTPRequestExecutor {
5460
func execute(_ request: HTTPClientRequest, timeout: TimeAmount) async throws -> HTTPClientResponse
5561
func getCurrentSwiftlyRelease() async throws -> Components.Schemas.SwiftlyRelease
@@ -179,9 +185,39 @@ extension Components.Schemas.Release {
179185
}
180186
}
181187

188+
public extension Components.Schemas.Architecture {
189+
init(_ knownArchitecture: Components.Schemas.KnownArchitecture) {
190+
self.init(value1: knownArchitecture, value2: knownArchitecture.rawValue)
191+
}
192+
193+
init(_ string: String) {
194+
self.init(value2: string)
195+
}
196+
}
197+
198+
public extension Components.Schemas.PlatformIdentifier {
199+
init(_ knownPlatformIdentifier: Components.Schemas.KnownPlatformIdentifier) {
200+
self.init(value1: knownPlatformIdentifier)
201+
}
202+
203+
init(_ string: String) {
204+
self.init(value2: string)
205+
}
206+
}
207+
208+
public extension Components.Schemas.SourceBranch {
209+
init(_ knownSourceBranch: Components.Schemas.KnownSourceBranch) {
210+
self.init(value1: knownSourceBranch)
211+
}
212+
213+
init(_ string: String) {
214+
self.init(value2: string)
215+
}
216+
}
217+
182218
extension Components.Schemas.Architecture {
183-
static var x8664: Components.Schemas.Architecture = .init(value1: Components.Schemas.KnownArchitecture.x8664, value2: "x86_64")
184-
static var aarch64: Components.Schemas.Architecture = .init(value1: Components.Schemas.KnownArchitecture.aarch64, value2: "aarch64")
219+
static var x8664: Components.Schemas.Architecture = .init(Components.Schemas.KnownArchitecture.x8664)
220+
static var aarch64: Components.Schemas.Architecture = .init(Components.Schemas.KnownArchitecture.aarch64)
185221
}
186222

187223
extension Components.Schemas.Platform {
@@ -374,27 +410,27 @@ public struct SwiftlyHTTPClient {
374410
let platformId: Components.Schemas.PlatformIdentifier = switch platform.name {
375411
// These are new platforms that aren't yet in the list of known platforms in the OpenAPI schema
376412
case PlatformDefinition.ubuntu2404.name, PlatformDefinition.debian12.name, PlatformDefinition.fedora39.name:
377-
.init(value2: platform.name)
413+
.init(platform.name)
378414

379415
case PlatformDefinition.ubuntu2204.name:
380-
.init(value1: .ubuntu2204)
416+
.init(.ubuntu2204)
381417
case PlatformDefinition.ubuntu2004.name:
382-
.init(value1: .ubuntu2004)
418+
.init(.ubuntu2004)
383419
case PlatformDefinition.rhel9.name:
384-
.init(value1: .ubi9)
420+
.init(.ubi9)
385421
case PlatformDefinition.amazonlinux2.name:
386-
.init(value1: .amazonlinux2)
422+
.init(.amazonlinux2)
387423
case PlatformDefinition.macOS.name:
388-
.init(value1: .macos)
424+
.init(.macos)
389425
default:
390426
throw SwiftlyError(message: "No snapshot toolchains available for platform \(platform.name)")
391427
}
392428

393429
let sourceBranch: Components.Schemas.SourceBranch = switch branch {
394430
case .main:
395-
.init(value1: .main)
431+
.init(.main)
396432
case let .release(major, minor):
397-
.init(value2: "\(major).\(minor)")
433+
.init("\(major).\(minor)")
398434
}
399435

400436
let devToolchains = try await SwiftlyCore.httpRequestExecutor.getSnapshotToolchains(branch: sourceBranch, platform: platformId)

Tests/SwiftlyTests/SwiftlyTests.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -533,8 +533,8 @@ public class MockToolchainDownloader: HTTPRequestExecutor {
533533
let release = Components.Schemas.SwiftlyRelease(
534534
version: self.latestSwiftlyVersion.description,
535535
platforms: [
536-
.init(platform: .init(value1: .darwin), arm64: "https://download.swift.org/swiftly-darwin.pkg", x8664: "https://download.swift.org/swiftly-darwin.pkg"),
537-
.init(platform: .init(value1: .linux), arm64: "https://download.swift.org/swiftly-linux.tar.gz", x8664: "https://download.swift.org/swiftly-linux.tar.gz"),
536+
.init(platform: .init(.darwin), arm64: "https://download.swift.org/swiftly-darwin.pkg", x8664: "https://download.swift.org/swiftly-darwin.pkg"),
537+
.init(platform: .init(.linux), arm64: "https://download.swift.org/swiftly-linux.tar.gz", x8664: "https://download.swift.org/swiftly-linux.tar.gz"),
538538
]
539539
)
540540

0 commit comments

Comments
 (0)