Skip to content

Commit

Permalink
feat(specs): recursive snippets and highlights result (generated)
Browse files Browse the repository at this point in the history
algolia/api-clients-automation#3497

Co-authored-by: algolia-bot <accounts+algolia-api-client-bot@algolia.com>
Co-authored-by: Clément Vannicatte <vannicattec@gmail.com>
  • Loading branch information
algolia-bot and shortcuts committed Aug 9, 2024
1 parent 23b5adf commit f181d2f
Show file tree
Hide file tree
Showing 22 changed files with 216 additions and 52 deletions.
4 changes: 2 additions & 2 deletions algoliasearch/Models/Recommend/AroundPrecision.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public int AsInt()
/// the InvalidClassException will be thrown
/// </summary>
/// <returns>An instance of List&lt;Range&gt;</returns>
public List<Range> AsList()
public List<Range> AsListRange()
{
return (List<Range>)ActualInstance;
}
Expand All @@ -80,7 +80,7 @@ public bool IsInt()
/// Check if the actual instance is of `List{Range}` type.
/// </summary>
/// <returns>Whether or not the instance is the type</returns>
public bool IsList()
public bool IsListRange()
{
return ActualInstance.GetType() == typeof(List<Range>);
}
Expand Down
4 changes: 2 additions & 2 deletions algoliasearch/Models/Recommend/FacetFilters.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public FacetFilters(string actualInstance)
/// the InvalidClassException will be thrown
/// </summary>
/// <returns>An instance of List&lt;FacetFilters&gt;</returns>
public List<FacetFilters> AsList()
public List<FacetFilters> AsListFacetFilters()
{
return (List<FacetFilters>)ActualInstance;
}
Expand All @@ -71,7 +71,7 @@ public string AsString()
/// Check if the actual instance is of `List{FacetFilters}` type.
/// </summary>
/// <returns>Whether or not the instance is the type</returns>
public bool IsList()
public bool IsListFacetFilters()
{
return ActualInstance.GetType() == typeof(List<FacetFilters>);
}
Expand Down
49 changes: 45 additions & 4 deletions algoliasearch/Models/Recommend/HighlightResult.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,16 @@ namespace Algolia.Search.Models.Recommend;
[JsonConverter(typeof(HighlightResultJsonConverter))]
public partial class HighlightResult : AbstractSchema
{
/// <summary>
/// Initializes a new instance of the HighlightResult class
/// with a Dictionary{string, HighlightResult}
/// </summary>
/// <param name="actualInstance">An instance of Dictionary&lt;string, HighlightResult&gt;.</param>
public HighlightResult(Dictionary<string, HighlightResult> actualInstance)
{
ActualInstance = actualInstance ?? throw new ArgumentException("Invalid instance found. Must not be null.");
}

/// <summary>
/// Initializes a new instance of the HighlightResult class
/// with a HighlightResultOption
Expand Down Expand Up @@ -56,6 +66,16 @@ public HighlightResult(List<HighlightResultOption> actualInstance)
/// </summary>
public sealed override object ActualInstance { get; set; }

/// <summary>
/// Get the actual instance of `Dictionary{string, HighlightResult}`. If the actual instance is not `Dictionary{string, HighlightResult}`,
/// the InvalidClassException will be thrown
/// </summary>
/// <returns>An instance of Dictionary&lt;string, HighlightResult&gt;</returns>
public Dictionary<string, HighlightResult> AsDictionaryHighlightResult()
{
return (Dictionary<string, HighlightResult>)ActualInstance;
}

/// <summary>
/// Get the actual instance of `HighlightResultOption`. If the actual instance is not `HighlightResultOption`,
/// the InvalidClassException will be thrown
Expand All @@ -71,7 +91,7 @@ public HighlightResultOption AsHighlightResultOption()
/// the InvalidClassException will be thrown
/// </summary>
/// <returns>An instance of Dictionary&lt;string, HighlightResultOption&gt;</returns>
public Dictionary<string, HighlightResultOption> AsDictionary()
public Dictionary<string, HighlightResultOption> AsDictionaryHighlightResultOption()
{
return (Dictionary<string, HighlightResultOption>)ActualInstance;
}
Expand All @@ -81,12 +101,21 @@ public Dictionary<string, HighlightResultOption> AsDictionary()
/// the InvalidClassException will be thrown
/// </summary>
/// <returns>An instance of List&lt;HighlightResultOption&gt;</returns>
public List<HighlightResultOption> AsList()
public List<HighlightResultOption> AsListHighlightResultOption()
{
return (List<HighlightResultOption>)ActualInstance;
}


/// <summary>
/// Check if the actual instance is of `Dictionary{string, HighlightResult}` type.
/// </summary>
/// <returns>Whether or not the instance is the type</returns>
public bool IsDictionaryHighlightResult()
{
return ActualInstance.GetType() == typeof(Dictionary<string, HighlightResult>);
}

/// <summary>
/// Check if the actual instance is of `HighlightResultOption` type.
/// </summary>
Expand All @@ -100,7 +129,7 @@ public bool IsHighlightResultOption()
/// Check if the actual instance is of `Dictionary{string, HighlightResultOption}` type.
/// </summary>
/// <returns>Whether or not the instance is the type</returns>
public bool IsDictionary()
public bool IsDictionaryHighlightResultOption()
{
return ActualInstance.GetType() == typeof(Dictionary<string, HighlightResultOption>);
}
Expand All @@ -109,7 +138,7 @@ public bool IsDictionary()
/// Check if the actual instance is of `List{HighlightResultOption}` type.
/// </summary>
/// <returns>Whether or not the instance is the type</returns>
public bool IsList()
public bool IsListHighlightResultOption()
{
return ActualInstance.GetType() == typeof(List<HighlightResultOption>);
}
Expand Down Expand Up @@ -199,6 +228,18 @@ public override HighlightResult Read(ref Utf8JsonReader reader, Type typeToConve
var jsonDocument = JsonDocument.ParseValue(ref reader);
var root = jsonDocument.RootElement;
if (root.ValueKind == JsonValueKind.Object)
{
try
{
return new HighlightResult(jsonDocument.Deserialize<Dictionary<string, HighlightResult>>(JsonConfig.Options));
}
catch (Exception exception)
{
// deserialization failed, try the next one
System.Diagnostics.Debug.WriteLine($"Failed to deserialize into Dictionary<string, HighlightResult>: {exception}");
}
}
if (root.ValueKind == JsonValueKind.Object)
{
try
{
Expand Down
4 changes: 2 additions & 2 deletions algoliasearch/Models/Recommend/IgnorePlurals.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public IgnorePlurals(bool actualInstance)
/// the InvalidClassException will be thrown
/// </summary>
/// <returns>An instance of List&lt;SupportedLanguage&gt;</returns>
public List<SupportedLanguage> AsList()
public List<SupportedLanguage> AsListSupportedLanguage()
{
return (List<SupportedLanguage>)ActualInstance;
}
Expand All @@ -71,7 +71,7 @@ public bool AsBool()
/// Check if the actual instance is of `List{SupportedLanguage}` type.
/// </summary>
/// <returns>Whether or not the instance is the type</returns>
public bool IsList()
public bool IsListSupportedLanguage()
{
return ActualInstance.GetType() == typeof(List<SupportedLanguage>);
}
Expand Down
4 changes: 2 additions & 2 deletions algoliasearch/Models/Recommend/NumericFilters.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public NumericFilters(string actualInstance)
/// the InvalidClassException will be thrown
/// </summary>
/// <returns>An instance of List&lt;NumericFilters&gt;</returns>
public List<NumericFilters> AsList()
public List<NumericFilters> AsListNumericFilters()
{
return (List<NumericFilters>)ActualInstance;
}
Expand All @@ -71,7 +71,7 @@ public string AsString()
/// Check if the actual instance is of `List{NumericFilters}` type.
/// </summary>
/// <returns>Whether or not the instance is the type</returns>
public bool IsList()
public bool IsListNumericFilters()
{
return ActualInstance.GetType() == typeof(List<NumericFilters>);
}
Expand Down
4 changes: 2 additions & 2 deletions algoliasearch/Models/Recommend/OptionalFilters.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public OptionalFilters(string actualInstance)
/// the InvalidClassException will be thrown
/// </summary>
/// <returns>An instance of List&lt;OptionalFilters&gt;</returns>
public List<OptionalFilters> AsList()
public List<OptionalFilters> AsListOptionalFilters()
{
return (List<OptionalFilters>)ActualInstance;
}
Expand All @@ -71,7 +71,7 @@ public string AsString()
/// Check if the actual instance is of `List{OptionalFilters}` type.
/// </summary>
/// <returns>Whether or not the instance is the type</returns>
public bool IsList()
public bool IsListOptionalFilters()
{
return ActualInstance.GetType() == typeof(List<OptionalFilters>);
}
Expand Down
4 changes: 2 additions & 2 deletions algoliasearch/Models/Recommend/ReRankingApplyFilter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public ReRankingApplyFilter(string actualInstance)
/// the InvalidClassException will be thrown
/// </summary>
/// <returns>An instance of List&lt;ReRankingApplyFilter&gt;</returns>
public List<ReRankingApplyFilter> AsList()
public List<ReRankingApplyFilter> AsListReRankingApplyFilter()
{
return (List<ReRankingApplyFilter>)ActualInstance;
}
Expand All @@ -71,7 +71,7 @@ public string AsString()
/// Check if the actual instance is of `List{ReRankingApplyFilter}` type.
/// </summary>
/// <returns>Whether or not the instance is the type</returns>
public bool IsList()
public bool IsListReRankingApplyFilter()
{
return ActualInstance.GetType() == typeof(List<ReRankingApplyFilter>);
}
Expand Down
4 changes: 2 additions & 2 deletions algoliasearch/Models/Recommend/RemoveStopWords.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public RemoveStopWords(bool actualInstance)
/// the InvalidClassException will be thrown
/// </summary>
/// <returns>An instance of List&lt;SupportedLanguage&gt;</returns>
public List<SupportedLanguage> AsList()
public List<SupportedLanguage> AsListSupportedLanguage()
{
return (List<SupportedLanguage>)ActualInstance;
}
Expand All @@ -71,7 +71,7 @@ public bool AsBool()
/// Check if the actual instance is of `List{SupportedLanguage}` type.
/// </summary>
/// <returns>Whether or not the instance is the type</returns>
public bool IsList()
public bool IsListSupportedLanguage()
{
return ActualInstance.GetType() == typeof(List<SupportedLanguage>);
}
Expand Down
49 changes: 45 additions & 4 deletions algoliasearch/Models/Recommend/SnippetResult.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,16 @@ namespace Algolia.Search.Models.Recommend;
[JsonConverter(typeof(SnippetResultJsonConverter))]
public partial class SnippetResult : AbstractSchema
{
/// <summary>
/// Initializes a new instance of the SnippetResult class
/// with a Dictionary{string, SnippetResult}
/// </summary>
/// <param name="actualInstance">An instance of Dictionary&lt;string, SnippetResult&gt;.</param>
public SnippetResult(Dictionary<string, SnippetResult> actualInstance)
{
ActualInstance = actualInstance ?? throw new ArgumentException("Invalid instance found. Must not be null.");
}

/// <summary>
/// Initializes a new instance of the SnippetResult class
/// with a SnippetResultOption
Expand Down Expand Up @@ -56,6 +66,16 @@ public SnippetResult(List<SnippetResultOption> actualInstance)
/// </summary>
public sealed override object ActualInstance { get; set; }

/// <summary>
/// Get the actual instance of `Dictionary{string, SnippetResult}`. If the actual instance is not `Dictionary{string, SnippetResult}`,
/// the InvalidClassException will be thrown
/// </summary>
/// <returns>An instance of Dictionary&lt;string, SnippetResult&gt;</returns>
public Dictionary<string, SnippetResult> AsDictionarySnippetResult()
{
return (Dictionary<string, SnippetResult>)ActualInstance;
}

/// <summary>
/// Get the actual instance of `SnippetResultOption`. If the actual instance is not `SnippetResultOption`,
/// the InvalidClassException will be thrown
Expand All @@ -71,7 +91,7 @@ public SnippetResultOption AsSnippetResultOption()
/// the InvalidClassException will be thrown
/// </summary>
/// <returns>An instance of Dictionary&lt;string, SnippetResultOption&gt;</returns>
public Dictionary<string, SnippetResultOption> AsDictionary()
public Dictionary<string, SnippetResultOption> AsDictionarySnippetResultOption()
{
return (Dictionary<string, SnippetResultOption>)ActualInstance;
}
Expand All @@ -81,12 +101,21 @@ public Dictionary<string, SnippetResultOption> AsDictionary()
/// the InvalidClassException will be thrown
/// </summary>
/// <returns>An instance of List&lt;SnippetResultOption&gt;</returns>
public List<SnippetResultOption> AsList()
public List<SnippetResultOption> AsListSnippetResultOption()
{
return (List<SnippetResultOption>)ActualInstance;
}


/// <summary>
/// Check if the actual instance is of `Dictionary{string, SnippetResult}` type.
/// </summary>
/// <returns>Whether or not the instance is the type</returns>
public bool IsDictionarySnippetResult()
{
return ActualInstance.GetType() == typeof(Dictionary<string, SnippetResult>);
}

/// <summary>
/// Check if the actual instance is of `SnippetResultOption` type.
/// </summary>
Expand All @@ -100,7 +129,7 @@ public bool IsSnippetResultOption()
/// Check if the actual instance is of `Dictionary{string, SnippetResultOption}` type.
/// </summary>
/// <returns>Whether or not the instance is the type</returns>
public bool IsDictionary()
public bool IsDictionarySnippetResultOption()
{
return ActualInstance.GetType() == typeof(Dictionary<string, SnippetResultOption>);
}
Expand All @@ -109,7 +138,7 @@ public bool IsDictionary()
/// Check if the actual instance is of `List{SnippetResultOption}` type.
/// </summary>
/// <returns>Whether or not the instance is the type</returns>
public bool IsList()
public bool IsListSnippetResultOption()
{
return ActualInstance.GetType() == typeof(List<SnippetResultOption>);
}
Expand Down Expand Up @@ -199,6 +228,18 @@ public override SnippetResult Read(ref Utf8JsonReader reader, Type typeToConvert
var jsonDocument = JsonDocument.ParseValue(ref reader);
var root = jsonDocument.RootElement;
if (root.ValueKind == JsonValueKind.Object)
{
try
{
return new SnippetResult(jsonDocument.Deserialize<Dictionary<string, SnippetResult>>(JsonConfig.Options));
}
catch (Exception exception)
{
// deserialization failed, try the next one
System.Diagnostics.Debug.WriteLine($"Failed to deserialize into Dictionary<string, SnippetResult>: {exception}");
}
}
if (root.ValueKind == JsonValueKind.Object)
{
try
{
Expand Down
4 changes: 2 additions & 2 deletions algoliasearch/Models/Recommend/TagFilters.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public TagFilters(string actualInstance)
/// the InvalidClassException will be thrown
/// </summary>
/// <returns>An instance of List&lt;TagFilters&gt;</returns>
public List<TagFilters> AsList()
public List<TagFilters> AsListTagFilters()
{
return (List<TagFilters>)ActualInstance;
}
Expand All @@ -71,7 +71,7 @@ public string AsString()
/// Check if the actual instance is of `List{TagFilters}` type.
/// </summary>
/// <returns>Whether or not the instance is the type</returns>
public bool IsList()
public bool IsListTagFilters()
{
return ActualInstance.GetType() == typeof(List<TagFilters>);
}
Expand Down
4 changes: 2 additions & 2 deletions algoliasearch/Models/Search/AroundPrecision.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public int AsInt()
/// the InvalidClassException will be thrown
/// </summary>
/// <returns>An instance of List&lt;Range&gt;</returns>
public List<Range> AsList()
public List<Range> AsListRange()
{
return (List<Range>)ActualInstance;
}
Expand All @@ -80,7 +80,7 @@ public bool IsInt()
/// Check if the actual instance is of `List{Range}` type.
/// </summary>
/// <returns>Whether or not the instance is the type</returns>
public bool IsList()
public bool IsListRange()
{
return ActualInstance.GetType() == typeof(List<Range>);
}
Expand Down
4 changes: 2 additions & 2 deletions algoliasearch/Models/Search/AutomaticFacetFilters.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public AutomaticFacetFilters(List<string> actualInstance)
/// the InvalidClassException will be thrown
/// </summary>
/// <returns>An instance of List&lt;AutomaticFacetFilter&gt;</returns>
public List<AutomaticFacetFilter> AsList()
public List<AutomaticFacetFilter> AsListAutomaticFacetFilter()
{
return (List<AutomaticFacetFilter>)ActualInstance;
}
Expand All @@ -71,7 +71,7 @@ public List<string> AsListString()
/// Check if the actual instance is of `List{AutomaticFacetFilter}` type.
/// </summary>
/// <returns>Whether or not the instance is the type</returns>
public bool IsList()
public bool IsListAutomaticFacetFilter()
{
return ActualInstance.GetType() == typeof(List<AutomaticFacetFilter>);
}
Expand Down
Loading

0 comments on commit f181d2f

Please sign in to comment.