Cross-platform Xcode replacement. Build and deploy iOS apps with SwiftPM on Linux, Windows, macOS.
Support for logging OpenAPI responses (#75)
Kabir Oberai2265449730a4
diff --git a/Sources/DeveloperAPI/Generated/Types.swift b/Sources/DeveloperAPI/Generated/Types.swiftindex 84bf00f..0609e31 100644--- a/Sources/DeveloperAPI/Generated/Types.swift+++ b/Sources/DeveloperAPI/Generated/Types.swift@@ -5021,6 +5021,7 @@ public enum Components {case ios = "IOS"case macOs = "MAC_OS"case universal = "UNIVERSAL"+ case services = "SERVICES"}/// - Remark: Generated from `#/components/schemas/CapabilityOption`.public struct CapabilityOption: Codable, Hashable, Sendable {diff --git a/Sources/DeveloperAPI/openapi-overlay.yaml b/Sources/DeveloperAPI/openapi-overlay.yamlindex ea68eea..ea5fcbe 100644--- a/Sources/DeveloperAPI/openapi-overlay.yaml+++ b/Sources/DeveloperAPI/openapi-overlay.yaml@@ -23,3 +23,6 @@ actions:- target: '$.components.schemas.Device.properties.attributes.properties.deviceClass'update:enum: ["APPLE_VISION_PRO"]+ - target: '$.components.schemas.BundleIdPlatform'+ update:+ enum: ["SERVICES"]diff --git a/Sources/XKit/DeveloperServices/DeveloperServices+OpenAPI.swift b/Sources/XKit/DeveloperServices/DeveloperServices+OpenAPI.swiftindex ad720ef..3ba555e 100644--- a/Sources/XKit/DeveloperServices/DeveloperServices+OpenAPI.swift+++ b/Sources/XKit/DeveloperServices/DeveloperServices+OpenAPI.swift@@ -17,7 +17,8 @@ extension DeveloperAPIClient {),transport: httpClient.asOpenAPITransport,middlewares: [- auth.middleware+ auth.middleware,+ LoggingMiddleware(),])}@@ -219,3 +220,39 @@ public struct DeveloperAPIASCAuthMiddleware: ClientMiddleware {return try await next(request, body, baseURL)}}++struct LoggingMiddleware: ClientMiddleware {+ static let regex: NSRegularExpression? = {+ guard let pat = ProcessInfo.processInfo.environment["XTL_DEV_LOG"] else { return nil }+ return try? NSRegularExpression(pattern: pat)+ }()++ func intercept(+ _ request: HTTPRequest,+ body: HTTPBody?,+ baseURL: URL,+ operationID: String,+ next: (HTTPRequest, HTTPBody?, URL) async throws -> (HTTPResponse, HTTPBody?)+ ) async throws -> (HTTPResponse, HTTPBody?) {+ var (response, body) = try await next(request, body, baseURL)++ guard Self.regex?.firstMatch(+ in: operationID,+ range: NSRange(operationID.startIndex..., in: operationID)+ ) != nil+ else { return (response, body) }++ print("\n\(operationID) response status -> \(response.status)")++ if let unwrapped = body {+ let data = try await Data(collecting: unwrapped, upTo: .max)+ // body may only be consumable once, replace it with the collected data+ body = .init(data)++ let text = String(decoding: data, as: UTF8.self)+ print("\(operationID) response body -> \(text)")+ }++ return (response, body)+ }+}