Skip to content

Commit

Permalink
Change inner structs and enums to extensions
Browse files Browse the repository at this point in the history
Move protocol implementation to extension
  • Loading branch information
Renato Almeida committed Nov 22, 2023
1 parent ed44995 commit 7a9c33a
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 32 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Foundation

extension ElasticsearchClient {
public struct ValidationError: LocalizedError, Equatable {
public struct ValidationError: LocalizedError {
public static let invalidURLString = ValidationError(.invalidURLString)
public static let missingURLScheme = ValidationError(.missingURLScheme)
public static let invalidURLScheme = ValidationError(.invalidURLScheme)
Expand All @@ -12,28 +12,32 @@ extension ElasticsearchClient {
private let kind: Kind

private init(_ kind: Kind) { self.kind = kind }
}
}

extension ElasticsearchClient.ValidationError: Equatable {
public static func ==(lhs: ElasticsearchClient.ValidationError, rhs: ElasticsearchClient.ValidationError) -> Bool {
return lhs.kind == rhs.kind
}
}

extension ElasticsearchClient.ValidationError {
private enum Kind: LocalizedError {
case invalidURLString
case missingURLScheme
case invalidURLScheme
case missingURLHost

public static func ==(lhs: ValidationError, rhs: ValidationError) -> Bool {
return lhs.kind == rhs.kind
}

private enum Kind: LocalizedError {
case invalidURLString
case missingURLScheme
case invalidURLScheme
case missingURLHost

var localizedDescription: String {
let message: String = {
switch self {
case .invalidURLString: return "invalid URL string"
case .missingURLScheme: return "URL scheme is missing"
case .invalidURLScheme: return "invalid URL scheme, expected 'http' or 'https'"
case .missingURLHost: return "missing remote hostname"
}
}()
return "Elasticsearch connection configuration validation failed: \(message)"
}
var localizedDescription: String {
let message: String = {
switch self {
case .invalidURLString: return "invalid URL string"
case .missingURLScheme: return "URL scheme is missing"
case .invalidURLScheme: return "invalid URL scheme, expected 'http' or 'https'"
case .missingURLHost: return "missing remote hostname"
}
}()
return "Elasticsearch connection configuration validation failed: \(message)"
}
}
}
Original file line number Diff line number Diff line change
@@ -1,19 +1,25 @@
import Foundation

public struct ESGetMultipleDocumentsResponse<Document: Decodable>: Decodable {
public struct Hits: Decodable {
public struct Total: Decodable {
public let value: Int
public let relation: Relation

public enum Relation: String, Decodable {
case eq, gte
}
}
public let hits: Hits
}

extension ESGetMultipleDocumentsResponse {
public struct Hits: Decodable {
public let total: Total?
public let hits: [ESGetSingleDocumentResponse<Document>]
}
}

public let hits: Hits
extension ESGetMultipleDocumentsResponse.Hits {
public struct Total: Decodable {
public let value: Int
public let relation: Relation
}
}

extension ESGetMultipleDocumentsResponse.Hits.Total {
public enum Relation: String, Decodable {
case eq, gte
}
}

0 comments on commit 7a9c33a

Please sign in to comment.