Skip to content

Commit 7b17d41

Browse files
refactor(specs): re-organise response for Composition API (generated)
algolia/api-clients-automation#5744 Co-authored-by: algolia-bot <accounts+algolia-api-client-bot@algolia.com> Co-authored-by: Clara Muller <5667350+ClaraMuller@users.noreply.github.com>
1 parent 9edcaba commit 7b17d41

8 files changed

+78
-219
lines changed

Sources/Composition/Models/CompositionRunAppliedRules.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import Foundation
77
#endif
88

99
public struct CompositionRunAppliedRules: Codable, JSONEncodable {
10-
/// Unique record identifier.
10+
/// The objectID of the applied composition rule on this query.
1111
public var objectID: String
1212

1313
public init(objectID: String) {

Sources/Composition/Models/CompositionRunSearchResponse.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import Foundation
77
#endif
88

99
public struct CompositionRunSearchResponse: Codable, JSONEncodable {
10-
/// Unique record identifier.
10+
/// The objectID of the composition which generated this result set.
1111
public var objectID: String
1212
public var appliedRules: [CompositionRunAppliedRules]?
1313

Sources/Composition/Models/CompositionSearchHits.swift

Lines changed: 0 additions & 115 deletions
This file was deleted.

Sources/Composition/Models/ResultsCompositionsResponse.swift

Lines changed: 0 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -17,71 +17,22 @@ public struct ResultsCompositionsResponse: Codable, JSONEncodable {
1717
case compositions
1818
}
1919

20-
public var additionalProperties: [String: AnyCodable] = [:]
21-
22-
public subscript(key: String) -> AnyCodable? {
23-
get {
24-
if let value = additionalProperties[key] {
25-
return value
26-
}
27-
return nil
28-
}
29-
30-
set {
31-
self.additionalProperties[key] = newValue
32-
}
33-
}
34-
35-
public init(from dictionary: [String: AnyCodable]) throws {
36-
guard let compositions = dictionary["compositions"]?.value as? [String: ResultsCompositionInfoResponse] else {
37-
throw GenericError(description: "Failed to cast")
38-
}
39-
self.compositions = compositions
40-
for (key, value) in dictionary {
41-
switch key {
42-
case "compositions":
43-
continue
44-
default:
45-
self.additionalProperties[key] = value
46-
}
47-
}
48-
}
49-
5020
// Encodable protocol methods
5121

5222
public func encode(to encoder: Encoder) throws {
5323
var container = encoder.container(keyedBy: CodingKeys.self)
5424
try container.encode(self.compositions, forKey: .compositions)
55-
var additionalPropertiesContainer = encoder.container(keyedBy: String.self)
56-
try additionalPropertiesContainer.encodeMap(self.additionalProperties)
57-
}
58-
59-
// Decodable protocol methods
60-
61-
public init(from decoder: Decoder) throws {
62-
let container = try decoder.container(keyedBy: CodingKeys.self)
63-
64-
self.compositions = try container.decode([String: ResultsCompositionInfoResponse].self, forKey: .compositions)
65-
var nonAdditionalPropertyKeys = Set<String>()
66-
nonAdditionalPropertyKeys.insert("compositions")
67-
let additionalPropertiesContainer = try decoder.container(keyedBy: String.self)
68-
self.additionalProperties = try additionalPropertiesContainer.decodeMap(
69-
AnyCodable.self,
70-
excludedKeys: nonAdditionalPropertyKeys
71-
)
7225
}
7326
}
7427

7528
extension ResultsCompositionsResponse: Equatable {
7629
public static func ==(lhs: ResultsCompositionsResponse, rhs: ResultsCompositionsResponse) -> Bool {
7730
lhs.compositions == rhs.compositions
78-
&& lhs.additionalProperties == rhs.additionalProperties
7931
}
8032
}
8133

8234
extension ResultsCompositionsResponse: Hashable {
8335
public func hash(into hasher: inout Hasher) {
8436
hasher.combine(self.compositions.hashValue)
85-
hasher.combine(self.additionalProperties.hashValue)
8637
}
8738
}

Sources/Composition/Models/ResultsInjectedItemAppliedRulesInfoResponse.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import Foundation
77
#endif
88

99
public struct ResultsInjectedItemAppliedRulesInfoResponse: Codable, JSONEncodable {
10-
/// Unique record identifier.
10+
/// The objectID of the applied index level rule on this injected group.
1111
public var objectID: String
1212

1313
public init(objectID: String) {

Sources/Composition/Models/ResultsInjectedItemInfoResponse.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import Foundation
77
#endif
88

99
public struct ResultsInjectedItemInfoResponse: Codable, JSONEncodable {
10+
/// The key of the injected group.
1011
public var key: String
1112
public var appliedRules: [ResultsInjectedItemAppliedRulesInfoResponse]?
1213

Sources/Composition/Models/CompositionSearchPagination.swift renamed to Sources/Composition/Models/SearchFields.swift

Lines changed: 41 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -6,55 +6,77 @@ import Foundation
66
import Core
77
#endif
88

9-
public struct CompositionSearchPagination: Codable, JSONEncodable {
10-
/// The current page of the results.
11-
public var page: Int
9+
public struct SearchFields<T: Codable>: Codable, JSONEncodable {
10+
/// Search results (hits). Hits are records from your index that match the search criteria, augmented with
11+
/// additional attributes, such as, for highlighting.
12+
public var hits: [T]
13+
/// Number of hits returned per page.
14+
public var hitsPerPage: Int
1215
/// Number of results (hits).
1316
public var nbHits: Int
1417
/// Number of pages of results.
1518
public var nbPages: Int
16-
/// Number of hits returned per page.
17-
public var hitsPerPage: Int
19+
/// The current page of the results.
20+
public var page: Int
21+
/// URL-encoded string of all search parameters.
22+
public var params: String
23+
/// The search query string.
24+
public var query: String
1825

19-
public init(page: Int, nbHits: Int, nbPages: Int, hitsPerPage: Int) {
20-
self.page = page
26+
public init(hits: [T], hitsPerPage: Int, nbHits: Int, nbPages: Int, page: Int, params: String, query: String) {
27+
self.hits = hits
28+
self.hitsPerPage = hitsPerPage
2129
self.nbHits = nbHits
2230
self.nbPages = nbPages
23-
self.hitsPerPage = hitsPerPage
31+
self.page = page
32+
self.params = params
33+
self.query = query
2434
}
2535

2636
public enum CodingKeys: String, CodingKey, CaseIterable {
27-
case page
37+
case hits
38+
case hitsPerPage
2839
case nbHits
2940
case nbPages
30-
case hitsPerPage
41+
case page
42+
case params
43+
case query
3144
}
3245

3346
// Encodable protocol methods
3447

3548
public func encode(to encoder: Encoder) throws {
3649
var container = encoder.container(keyedBy: CodingKeys.self)
37-
try container.encode(self.page, forKey: .page)
50+
try container.encode(self.hits, forKey: .hits)
51+
try container.encode(self.hitsPerPage, forKey: .hitsPerPage)
3852
try container.encode(self.nbHits, forKey: .nbHits)
3953
try container.encode(self.nbPages, forKey: .nbPages)
40-
try container.encode(self.hitsPerPage, forKey: .hitsPerPage)
54+
try container.encode(self.page, forKey: .page)
55+
try container.encode(self.params, forKey: .params)
56+
try container.encode(self.query, forKey: .query)
4157
}
4258
}
4359

44-
extension CompositionSearchPagination: Equatable {
45-
public static func ==(lhs: CompositionSearchPagination, rhs: CompositionSearchPagination) -> Bool {
46-
lhs.page == rhs.page &&
60+
extension SearchFields: Equatable where T: Equatable {
61+
public static func ==(lhs: SearchFields<T>, rhs: SearchFields<T>) -> Bool {
62+
lhs.hits == rhs.hits &&
63+
lhs.hitsPerPage == rhs.hitsPerPage &&
4764
lhs.nbHits == rhs.nbHits &&
4865
lhs.nbPages == rhs.nbPages &&
49-
lhs.hitsPerPage == rhs.hitsPerPage
66+
lhs.page == rhs.page &&
67+
lhs.params == rhs.params &&
68+
lhs.query == rhs.query
5069
}
5170
}
5271

53-
extension CompositionSearchPagination: Hashable {
72+
extension SearchFields: Hashable where T: Hashable {
5473
public func hash(into hasher: inout Hasher) {
55-
hasher.combine(self.page.hashValue)
74+
hasher.combine(self.hits.hashValue)
75+
hasher.combine(self.hitsPerPage.hashValue)
5676
hasher.combine(self.nbHits.hashValue)
5777
hasher.combine(self.nbPages.hashValue)
58-
hasher.combine(self.hitsPerPage.hashValue)
78+
hasher.combine(self.page.hashValue)
79+
hasher.combine(self.params.hashValue)
80+
hasher.combine(self.query.hashValue)
5981
}
6082
}

0 commit comments

Comments
 (0)