Skip to content

Commit

Permalink
fix(specs): required prop for dictionaryEntry (generated)
Browse files Browse the repository at this point in the history
algolia/api-clients-automation#3449

Co-authored-by: algolia-bot <accounts+algolia-api-client-bot@algolia.com>
Co-authored-by: Kai Welke <kai.welke@algolia.com>
Co-authored-by: Pierre Millot <pierre.millot@algolia.com>
  • Loading branch information
3 people committed Jul 30, 2024
1 parent 9adf819 commit 438e077
Showing 1 changed file with 7 additions and 9 deletions.
16 changes: 7 additions & 9 deletions Sources/Search/Models/DictionaryEntry.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import Foundation
public struct DictionaryEntry: Codable, JSONEncodable {
/// Unique identifier for the dictionary entry.
public var objectID: String
public var language: SearchSupportedLanguage
public var language: SearchSupportedLanguage?
/// Matching dictionary word for `stopwords` and `compounds` dictionaries.
public var word: String?
/// Matching words in the `plurals` dictionary including declensions.
Expand All @@ -21,7 +21,7 @@ public struct DictionaryEntry: Codable, JSONEncodable {

public init(
objectID: String,
language: SearchSupportedLanguage,
language: SearchSupportedLanguage? = nil,
word: String? = nil,
words: [String]? = nil,
decomposition: [String]? = nil,
Expand Down Expand Up @@ -64,10 +64,8 @@ public struct DictionaryEntry: Codable, JSONEncodable {
throw GenericError(description: "Failed to cast")
}
self.objectID = objectID
guard let language = dictionary["language"]?.value as? SearchSupportedLanguage else {
throw GenericError(description: "Failed to cast")
}
self.language = language
self.language = dictionary["language"]?.value as? SearchSupportedLanguage

self.word = dictionary["word"]?.value as? String

self.words = dictionary["words"]?.value as? [String]
Expand All @@ -91,7 +89,7 @@ public struct DictionaryEntry: Codable, JSONEncodable {
public func encode(to encoder: Encoder) throws {
var container = encoder.container(keyedBy: CodingKeys.self)
try container.encode(self.objectID, forKey: .objectID)
try container.encode(self.language, forKey: .language)
try container.encodeIfPresent(self.language, forKey: .language)
try container.encodeIfPresent(self.word, forKey: .word)
try container.encodeIfPresent(self.words, forKey: .words)
try container.encodeIfPresent(self.decomposition, forKey: .decomposition)
Expand All @@ -106,7 +104,7 @@ public struct DictionaryEntry: Codable, JSONEncodable {
let container = try decoder.container(keyedBy: CodingKeys.self)

self.objectID = try container.decode(String.self, forKey: .objectID)
self.language = try container.decode(SearchSupportedLanguage.self, forKey: .language)
self.language = try container.decodeIfPresent(SearchSupportedLanguage.self, forKey: .language)
self.word = try container.decodeIfPresent(String.self, forKey: .word)
self.words = try container.decodeIfPresent([String].self, forKey: .words)
self.decomposition = try container.decodeIfPresent([String].self, forKey: .decomposition)
Expand Down Expand Up @@ -141,7 +139,7 @@ extension DictionaryEntry: Equatable {
extension DictionaryEntry: Hashable {
public func hash(into hasher: inout Hasher) {
hasher.combine(self.objectID.hashValue)
hasher.combine(self.language.hashValue)
hasher.combine(self.language?.hashValue)
hasher.combine(self.word?.hashValue)
hasher.combine(self.words?.hashValue)
hasher.combine(self.decomposition?.hashValue)
Expand Down

0 comments on commit 438e077

Please sign in to comment.