Skip to content

Commit 438e077

Browse files
algolia-botkai687millotp
committed
fix(specs): required prop for dictionaryEntry (generated)
algolia/api-clients-automation#3449 Co-authored-by: algolia-bot <[email protected]> Co-authored-by: Kai Welke <[email protected]> Co-authored-by: Pierre Millot <[email protected]>
1 parent 9adf819 commit 438e077

File tree

1 file changed

+7
-9
lines changed

1 file changed

+7
-9
lines changed

Sources/Search/Models/DictionaryEntry.swift

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import Foundation
1010
public struct DictionaryEntry: Codable, JSONEncodable {
1111
/// Unique identifier for the dictionary entry.
1212
public var objectID: String
13-
public var language: SearchSupportedLanguage
13+
public var language: SearchSupportedLanguage?
1414
/// Matching dictionary word for `stopwords` and `compounds` dictionaries.
1515
public var word: String?
1616
/// Matching words in the `plurals` dictionary including declensions.
@@ -21,7 +21,7 @@ public struct DictionaryEntry: Codable, JSONEncodable {
2121

2222
public init(
2323
objectID: String,
24-
language: SearchSupportedLanguage,
24+
language: SearchSupportedLanguage? = nil,
2525
word: String? = nil,
2626
words: [String]? = nil,
2727
decomposition: [String]? = nil,
@@ -64,10 +64,8 @@ public struct DictionaryEntry: Codable, JSONEncodable {
6464
throw GenericError(description: "Failed to cast")
6565
}
6666
self.objectID = objectID
67-
guard let language = dictionary["language"]?.value as? SearchSupportedLanguage else {
68-
throw GenericError(description: "Failed to cast")
69-
}
70-
self.language = language
67+
self.language = dictionary["language"]?.value as? SearchSupportedLanguage
68+
7169
self.word = dictionary["word"]?.value as? String
7270

7371
self.words = dictionary["words"]?.value as? [String]
@@ -91,7 +89,7 @@ public struct DictionaryEntry: Codable, JSONEncodable {
9189
public func encode(to encoder: Encoder) throws {
9290
var container = encoder.container(keyedBy: CodingKeys.self)
9391
try container.encode(self.objectID, forKey: .objectID)
94-
try container.encode(self.language, forKey: .language)
92+
try container.encodeIfPresent(self.language, forKey: .language)
9593
try container.encodeIfPresent(self.word, forKey: .word)
9694
try container.encodeIfPresent(self.words, forKey: .words)
9795
try container.encodeIfPresent(self.decomposition, forKey: .decomposition)
@@ -106,7 +104,7 @@ public struct DictionaryEntry: Codable, JSONEncodable {
106104
let container = try decoder.container(keyedBy: CodingKeys.self)
107105

108106
self.objectID = try container.decode(String.self, forKey: .objectID)
109-
self.language = try container.decode(SearchSupportedLanguage.self, forKey: .language)
107+
self.language = try container.decodeIfPresent(SearchSupportedLanguage.self, forKey: .language)
110108
self.word = try container.decodeIfPresent(String.self, forKey: .word)
111109
self.words = try container.decodeIfPresent([String].self, forKey: .words)
112110
self.decomposition = try container.decodeIfPresent([String].self, forKey: .decomposition)
@@ -141,7 +139,7 @@ extension DictionaryEntry: Equatable {
141139
extension DictionaryEntry: Hashable {
142140
public func hash(into hasher: inout Hasher) {
143141
hasher.combine(self.objectID.hashValue)
144-
hasher.combine(self.language.hashValue)
142+
hasher.combine(self.language?.hashValue)
145143
hasher.combine(self.word?.hashValue)
146144
hasher.combine(self.words?.hashValue)
147145
hasher.combine(self.decomposition?.hashValue)

0 commit comments

Comments
 (0)