Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions src/Constructorio_NET.Tests/client/modules/SearchTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -567,6 +567,20 @@ public async Task GetSearchResultsWithRedirect()
Assert.IsNotNull(res.ResultId, "ResultId should exist");
}

[Test]
public void RedirectDataIndexerAccessesArbitraryKeys()
{
string json = @"{""url"":""/test"",""rule_id"":49023,""match_id"":185282,""foo"":""bar"",""custom_key"":123}";
RedirectData data = Newtonsoft.Json.JsonConvert.DeserializeObject<RedirectData>(json);

Assert.AreEqual("/test", data.Url, "Url property should be accessible");
Assert.AreEqual(49023, data.RuleId, "RuleId property should be accessible");
Assert.AreEqual(185282, data.MatchId, "MatchId property should be accessible");
Assert.AreEqual("bar", data["foo"]?.ToString(), "Indexer should access arbitrary string key");
Assert.AreEqual(123L, data["custom_key"], "Indexer should access arbitrary numeric key");
Assert.IsNull(data["nonexistent"], "Indexer should return null for missing keys");
}

[Test]
public async Task GetSearchResultsShouldReturnResultWithRefinedContent()
{
Expand Down
17 changes: 17 additions & 0 deletions src/constructor.io/models/Search/RedirectData.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Collections.Generic;
using Newtonsoft.Json;

/**
Expand All @@ -16,5 +17,21 @@ public class RedirectData

[JsonProperty("match_id")]
public int MatchId { get; set; }

[JsonExtensionData]
private Dictionary<string, object> _additionalData;
Copy link

Copilot AI Feb 5, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The private field _additionalData is not accessible to consumers who might need to enumerate all additional data keys. Consider adding a public method or property to expose the keys or entries, such as IEnumerable<string> GetAdditionalDataKeys() or a read-only view of the dictionary.

Copilot uses AI. Check for mistakes.

/// <summary>
/// Indexer for accessing arbitrary metadata keys
/// </summary>
public object this[string key]
{
get => _additionalData?.TryGetValue(key, out var value) == true ? value : null;
set
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we really need a setter here? RedirectData comes from the API response, users read it, they don't construct it themselves AFAIU 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's fair. I thought about this for a bit as well. I thought it might be helpful for testing in the future and I wanted to keep it consistent with other attributes of this call. But I agree, it's not necessary 🤔

{
_additionalData ??= new Dictionary<string, object>();
_additionalData[key] = value;
}
}
}
}
Loading