From 407156b14f96f9e889914bcb69980bda9e5daa8e Mon Sep 17 00:00:00 2001 From: algolia-bot Date: Thu, 8 Aug 2024 10:42:30 +0000 Subject: [PATCH] feat(specs): add authentications to ingestion transformations (generated) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit https://github.com/algolia/api-clients-automation/pull/3494 Co-authored-by: algolia-bot Co-authored-by: Clément Vannicatte --- Sources/Ingestion/IngestionClient.swift | 69 ++++++++++++++++++- Sources/Ingestion/Models/Transformation.swift | 8 +++ .../Models/TransformationCreate.swift | 11 ++- .../Ingestion/Models/TransformationTry.swift | 10 ++- 4 files changed, 93 insertions(+), 5 deletions(-) diff --git a/Sources/Ingestion/IngestionClient.swift b/Sources/Ingestion/IngestionClient.swift index 17cb9e51..12f82f63 100644 --- a/Sources/Ingestion/IngestionClient.swift +++ b/Sources/Ingestion/IngestionClient.swift @@ -3095,7 +3095,7 @@ open class IngestionClient { return body } - // Try a transformation. + // Try a transformation before creating it. // Required API Key ACLs: // - addObject // - deleteIndex @@ -3124,6 +3124,73 @@ open class IngestionClient { ) } + /// - parameter transformationID: (path) Unique identifier of a transformation. + /// - parameter transformationTry: (body) + /// - returns: TransformationTryResponse + @available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *) + open func tryTransformationBeforeUpdate( + transformationID: String, + transformationTry: TransformationTry, + requestOptions: RequestOptions? = nil + ) async throws -> TransformationTryResponse { + let response: Response = try await tryTransformationBeforeUpdateWithHTTPInfo( + transformationID: transformationID, + transformationTry: transformationTry, + requestOptions: requestOptions + ) + + guard let body = response.body else { + throw AlgoliaError.missingData + } + + return body + } + + // Try a transformation before updating it. + // Required API Key ACLs: + // - addObject + // - deleteIndex + // - editSettings + // + // - parameter transformationID: (path) Unique identifier of a transformation. + // + // - parameter transformationTry: (body) + // - returns: RequestBuilder + + open func tryTransformationBeforeUpdateWithHTTPInfo( + transformationID: String, + transformationTry: TransformationTry, + requestOptions userRequestOptions: RequestOptions? = nil + ) async throws -> Response { + guard !transformationID.isEmpty else { + throw AlgoliaError.invalidArgument("transformationID", "tryTransformationBeforeUpdate") + } + + var resourcePath = "/1/transformations/{transformationID}/try" + let transformationIDPreEscape = "\(APIHelper.mapValueToPathItem(transformationID))" + let transformationIDPostEscape = transformationIDPreEscape + .addingPercentEncoding(withAllowedCharacters: .urlPathAlgoliaAllowed) ?? "" + resourcePath = resourcePath.replacingOccurrences( + of: "{transformationID}", + with: transformationIDPostEscape, + options: .literal, + range: nil + ) + let body = transformationTry + let queryParameters: [String: Any?]? = nil + + let nillableHeaders: [String: Any?]? = nil + + let headers = APIHelper.rejectNilHeaders(nillableHeaders) + + return try await self.transporter.send( + method: "POST", + path: resourcePath, + data: body, + requestOptions: RequestOptions(headers: headers, queryParameters: queryParameters) + userRequestOptions + ) + } + /// - parameter authenticationID: (path) Unique identifier of an authentication resource. /// - parameter authenticationUpdate: (body) /// - returns: AuthenticationUpdateResponse diff --git a/Sources/Ingestion/Models/Transformation.swift b/Sources/Ingestion/Models/Transformation.swift index 45b83545..cf384c82 100644 --- a/Sources/Ingestion/Models/Transformation.swift +++ b/Sources/Ingestion/Models/Transformation.swift @@ -9,6 +9,8 @@ import Foundation public struct Transformation: Codable, JSONEncodable { /// Universally unique identifier (UUID) of a transformation. public var transformationID: String + /// The authentications associated for the current transformation. + public var authenticationIDs: [String]? /// The source code of the transformation. public var code: String /// The uniquely identified name of your transformation. @@ -22,6 +24,7 @@ public struct Transformation: Codable, JSONEncodable { public init( transformationID: String, + authenticationIDs: [String]? = nil, code: String, name: String, description: String? = nil, @@ -29,6 +32,7 @@ public struct Transformation: Codable, JSONEncodable { updatedAt: String? = nil ) { self.transformationID = transformationID + self.authenticationIDs = authenticationIDs self.code = code self.name = name self.description = description @@ -38,6 +42,7 @@ public struct Transformation: Codable, JSONEncodable { public enum CodingKeys: String, CodingKey, CaseIterable { case transformationID + case authenticationIDs case code case name case description @@ -50,6 +55,7 @@ public struct Transformation: Codable, JSONEncodable { public func encode(to encoder: Encoder) throws { var container = encoder.container(keyedBy: CodingKeys.self) try container.encode(self.transformationID, forKey: .transformationID) + try container.encodeIfPresent(self.authenticationIDs, forKey: .authenticationIDs) try container.encode(self.code, forKey: .code) try container.encode(self.name, forKey: .name) try container.encodeIfPresent(self.description, forKey: .description) @@ -61,6 +67,7 @@ public struct Transformation: Codable, JSONEncodable { extension Transformation: Equatable { public static func ==(lhs: Transformation, rhs: Transformation) -> Bool { lhs.transformationID == rhs.transformationID && + lhs.authenticationIDs == rhs.authenticationIDs && lhs.code == rhs.code && lhs.name == rhs.name && lhs.description == rhs.description && @@ -72,6 +79,7 @@ extension Transformation: Equatable { extension Transformation: Hashable { public func hash(into hasher: inout Hasher) { hasher.combine(self.transformationID.hashValue) + hasher.combine(self.authenticationIDs?.hashValue) hasher.combine(self.code.hashValue) hasher.combine(self.name.hashValue) hasher.combine(self.description?.hashValue) diff --git a/Sources/Ingestion/Models/TransformationCreate.swift b/Sources/Ingestion/Models/TransformationCreate.swift index ff4ee32d..9f7743b1 100644 --- a/Sources/Ingestion/Models/TransformationCreate.swift +++ b/Sources/Ingestion/Models/TransformationCreate.swift @@ -14,17 +14,21 @@ public struct TransformationCreate: Codable, JSONEncodable { public var name: String /// A descriptive name for your transformation of what it does. public var description: String? + /// The authentications associated for the current transformation. + public var authenticationIDs: [String]? - public init(code: String, name: String, description: String? = nil) { + public init(code: String, name: String, description: String? = nil, authenticationIDs: [String]? = nil) { self.code = code self.name = name self.description = description + self.authenticationIDs = authenticationIDs } public enum CodingKeys: String, CodingKey, CaseIterable { case code case name case description + case authenticationIDs } // Encodable protocol methods @@ -34,6 +38,7 @@ public struct TransformationCreate: Codable, JSONEncodable { try container.encode(self.code, forKey: .code) try container.encode(self.name, forKey: .name) try container.encodeIfPresent(self.description, forKey: .description) + try container.encodeIfPresent(self.authenticationIDs, forKey: .authenticationIDs) } } @@ -41,7 +46,8 @@ extension TransformationCreate: Equatable { public static func ==(lhs: TransformationCreate, rhs: TransformationCreate) -> Bool { lhs.code == rhs.code && lhs.name == rhs.name && - lhs.description == rhs.description + lhs.description == rhs.description && + lhs.authenticationIDs == rhs.authenticationIDs } } @@ -50,5 +56,6 @@ extension TransformationCreate: Hashable { hasher.combine(self.code.hashValue) hasher.combine(self.name.hashValue) hasher.combine(self.description?.hashValue) + hasher.combine(self.authenticationIDs?.hashValue) } } diff --git a/Sources/Ingestion/Models/TransformationTry.swift b/Sources/Ingestion/Models/TransformationTry.swift index bce9af04..197736d4 100644 --- a/Sources/Ingestion/Models/TransformationTry.swift +++ b/Sources/Ingestion/Models/TransformationTry.swift @@ -11,15 +11,18 @@ public struct TransformationTry: Codable, JSONEncodable { public var code: String /// The record to apply the given code to. public var sampleRecord: AnyCodable + public var authentications: [AuthenticationCreate]? - public init(code: String, sampleRecord: AnyCodable) { + public init(code: String, sampleRecord: AnyCodable, authentications: [AuthenticationCreate]? = nil) { self.code = code self.sampleRecord = sampleRecord + self.authentications = authentications } public enum CodingKeys: String, CodingKey, CaseIterable { case code case sampleRecord + case authentications } // Encodable protocol methods @@ -28,13 +31,15 @@ public struct TransformationTry: Codable, JSONEncodable { var container = encoder.container(keyedBy: CodingKeys.self) try container.encode(self.code, forKey: .code) try container.encode(self.sampleRecord, forKey: .sampleRecord) + try container.encodeIfPresent(self.authentications, forKey: .authentications) } } extension TransformationTry: Equatable { public static func ==(lhs: TransformationTry, rhs: TransformationTry) -> Bool { lhs.code == rhs.code && - lhs.sampleRecord == rhs.sampleRecord + lhs.sampleRecord == rhs.sampleRecord && + lhs.authentications == rhs.authentications } } @@ -42,5 +47,6 @@ extension TransformationTry: Hashable { public func hash(into hasher: inout Hasher) { hasher.combine(self.code.hashValue) hasher.combine(self.sampleRecord.hashValue) + hasher.combine(self.authentications?.hashValue) } }