Skip to content

Commit

Permalink
fix(specs): required prop for dictionaryEntry (#3449) (generated) [sk…
Browse files Browse the repository at this point in the history
…ip ci]

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 9a2e7a8 commit dfb2aa7
Show file tree
Hide file tree
Showing 37 changed files with 94 additions and 297 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,9 @@ public DictionaryEntry()
/// Initializes a new instance of the DictionaryEntry class.
/// </summary>
/// <param name="objectID">Unique identifier for the dictionary entry. (required).</param>
/// <param name="language">language (required).</param>
public DictionaryEntry(string objectID, SupportedLanguage? language)
public DictionaryEntry(string objectID)
{
ObjectID = objectID ?? throw new ArgumentNullException(nameof(objectID));
Language = language;
AdditionalProperties = new Dictionary<string, object>();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ final class DictionaryEntry extends DelegatingMap<String, dynamic> {
/// Returns a new [DictionaryEntry] instance.
const DictionaryEntry({
required this.objectID,
required this.language,
this.language,
this.word,
this.words,
this.decomposition,
Expand All @@ -26,7 +26,7 @@ final class DictionaryEntry extends DelegatingMap<String, dynamic> {
final String objectID;

@JsonKey(name: r'language')
final SupportedLanguage language;
final SupportedLanguage? language;

/// Matching dictionary word for `stopwords` and `compounds` dictionaries.
@JsonKey(name: r'word')
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public DictionaryEntry setLanguage(SupportedLanguage language) {
}

/** Get language */
@javax.annotation.Nonnull
@javax.annotation.Nullable
public SupportedLanguage getLanguage() {
return language;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export type DictionaryEntry = Record<string, any> & {
*/
objectID: string;

language: SupportedLanguage;
language?: SupportedLanguage;

/**
* Matching dictionary word for `stopwords` and `compounds` dictionaries.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public data class DictionaryEntry(
/** Unique identifier for the dictionary entry. */
val objectID: String,

val language: SupportedLanguage,
val language: SupportedLanguage? = null,

/** Matching dictionary word for `stopwords` and `compounds` dictionaries. */
val word: String? = null,
Expand All @@ -43,7 +43,7 @@ internal object DictionaryEntrySerializer : KSerializer<DictionaryEntry> {

override val descriptor: SerialDescriptor = buildClassSerialDescriptor("DictionaryEntry") {
element<String>("objectID")
element<SupportedLanguage>("language")
element<SupportedLanguage>("language", isOptional = true)
element<String>("word", isOptional = true)
element<List<String>>("words", isOptional = true)
element<List<String>>("decomposition", isOptional = true)
Expand All @@ -55,7 +55,7 @@ internal object DictionaryEntrySerializer : KSerializer<DictionaryEntry> {
val tree = input.decodeJsonObject()
return DictionaryEntry(
objectID = tree.getValue("objectID").let { input.json.decodeFromJsonElement(it) },
language = tree.getValue("language").let { input.json.decodeFromJsonElement(it) },
language = tree["language"]?.let { input.json.decodeFromJsonElement(it) },
word = tree["word"]?.let { input.json.decodeFromJsonElement(it) },
words = tree["words"]?.let { input.json.decodeFromJsonElement(it) },
decomposition = tree["decomposition"]?.let { input.json.decodeFromJsonElement(it) },
Expand All @@ -68,7 +68,7 @@ internal object DictionaryEntrySerializer : KSerializer<DictionaryEntry> {
val output = encoder.asJsonEncoder()
val json = buildJsonObject {
put("objectID", output.json.encodeToJsonElement(value.objectID))
put("language", output.json.encodeToJsonElement(value.language))
value.language?.let { put("language", output.json.encodeToJsonElement(it)) }
value.word?.let { put("word", output.json.encodeToJsonElement(it)) }
value.words?.let { put("words", output.json.encodeToJsonElement(it)) }
value.decomposition?.let { put("decomposition", output.json.encodeToJsonElement(it)) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,9 +183,6 @@ public function listInvalidProperties()
if (!isset($this->container['objectID']) || null === $this->container['objectID']) {
$invalidProperties[] = "'objectID' can't be null";
}
if (!isset($this->container['language']) || null === $this->container['language']) {
$invalidProperties[] = "'language' can't be null";
}

return $invalidProperties;
}
Expand Down Expand Up @@ -228,7 +225,7 @@ public function setObjectID($objectID)
/**
* Gets language.
*
* @return SupportedLanguage
* @return null|SupportedLanguage
*/
public function getLanguage()
{
Expand All @@ -238,7 +235,7 @@ public function getLanguage()
/**
* Sets language.
*
* @param SupportedLanguage $language language
* @param null|SupportedLanguage $language language
*
* @return self
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class DictionaryEntry(BaseModel):
object_id: StrictStr = Field(
description="Unique identifier for the dictionary entry.", alias="objectID"
)
language: SupportedLanguage
language: Optional[SupportedLanguage] = None
word: Optional[StrictStr] = Field(
default=None,
description="Matching dictionary word for `stopwords` and `compounds` dictionaries.",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,6 @@ def initialize(attributes = {})

if attributes.key?(:language)
self.language = attributes[:language]
else
self.language = nil
end

if attributes.key?(:word)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ import org.json4s.{Extraction, Formats, JField, JObject, JValue, Serializer, Typ
*/
case class DictionaryEntry(
objectID: String,
language: SupportedLanguage,
language: Option[SupportedLanguage] = scala.None,
word: Option[String] = scala.None,
words: Option[Seq[String]] = scala.None,
decomposition: Option[Seq[String]] = scala.None,
Expand Down
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
10 changes: 1 addition & 9 deletions snippets/csharp/src/Search.cs
Original file line number Diff line number Diff line change
Expand Up @@ -381,15 +381,7 @@ public async Task SnippetForSearchClientBatchDictionaryEntries1()
new BatchDictionaryEntriesRequest
{
Action = Enum.Parse<DictionaryAction>("DeleteEntry"),
Body = new DictionaryEntry
{
ObjectID = "1",
Language = Enum.Parse<SupportedLanguage>("En"),
Word = "fancy",
Words = new List<string> { "believe", "algolia" },
Decomposition = new List<string> { "trust", "algolia" },
State = Enum.Parse<DictionaryEntryState>("Enabled"),
},
Body = new DictionaryEntry { ObjectID = "1", },
}
},
}
Expand Down
11 changes: 0 additions & 11 deletions snippets/dart/lib/search.dart
Original file line number Diff line number Diff line change
Expand Up @@ -342,17 +342,6 @@ void snippetForbatchDictionaryEntries1() async {
action: DictionaryAction.fromJson("deleteEntry"),
body: DictionaryEntry(
objectID: "1",
language: SupportedLanguage.fromJson("en"),
word: "fancy",
words: [
"believe",
"algolia",
],
decomposition: [
"trust",
"algolia",
],
state: DictionaryEntryState.fromJson("enabled"),
),
),
],
Expand Down
4 changes: 1 addition & 3 deletions snippets/go/src/search.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit dfb2aa7

Please sign in to comment.