Skip to content

Commit

Permalink
feat(specs): add authentications to ingestion transformations (genera…
Browse files Browse the repository at this point in the history
…ted)

algolia/api-clients-automation#3494

Co-authored-by: algolia-bot <[email protected]>
Co-authored-by: Clément Vannicatte <[email protected]>
  • Loading branch information
algolia-bot and shortcuts committed Aug 8, 2024
1 parent 36fcfc9 commit 407156b
Show file tree
Hide file tree
Showing 4 changed files with 93 additions and 5 deletions.
69 changes: 68 additions & 1 deletion Sources/Ingestion/IngestionClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3095,7 +3095,7 @@ open class IngestionClient {
return body
}

// Try a transformation.
// Try a transformation before creating it.
// Required API Key ACLs:
// - addObject
// - deleteIndex
Expand Down Expand Up @@ -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<TransformationTryResponse> = 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<TransformationTryResponse>

open func tryTransformationBeforeUpdateWithHTTPInfo(
transformationID: String,
transformationTry: TransformationTry,
requestOptions userRequestOptions: RequestOptions? = nil
) async throws -> Response<TransformationTryResponse> {
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
Expand Down
8 changes: 8 additions & 0 deletions Sources/Ingestion/Models/Transformation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -22,13 +24,15 @@ public struct Transformation: Codable, JSONEncodable {

public init(
transformationID: String,
authenticationIDs: [String]? = nil,
code: String,
name: String,
description: String? = nil,
createdAt: String,
updatedAt: String? = nil
) {
self.transformationID = transformationID
self.authenticationIDs = authenticationIDs
self.code = code
self.name = name
self.description = description
Expand All @@ -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
Expand All @@ -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)
Expand All @@ -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 &&
Expand All @@ -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)
Expand Down
11 changes: 9 additions & 2 deletions Sources/Ingestion/Models/TransformationCreate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -34,14 +38,16 @@ 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)
}
}

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
}
}

Expand All @@ -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)
}
}
10 changes: 8 additions & 2 deletions Sources/Ingestion/Models/TransformationTry.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -28,19 +31,22 @@ 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
}
}

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)
}
}

0 comments on commit 407156b

Please sign in to comment.