Skip to content
Closed
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
Original file line number Diff line number Diff line change
Expand Up @@ -308,11 +308,42 @@ public void DeserializeFromStream_ShouldSucceed()
Assert.Equal("something", model.NullProperty);
}

[Fact]
public void Serialize_ShouldIncludeAdditionalOptions_WhenSerializingPostCursorOptions()
{
var body = new PostCursorBody
{
Options = new PostCursorOptions
{
FullCount = true,
AdditionalOptions = new Dictionary<string, object>
{
["fullCount"] = false,
["customFlag"] = false,
["oneShardAttributeValue"] = "tenant-123"
}
}
};

var serialization = new JsonNetApiClientSerialization();
byte[] jsonBytes = serialization.Serialize(body, new ApiClientSerializationOptions(
useCamelCasePropertyNames: true, ignoreNullValues: true));
string jsonString = Encoding.UTF8.GetString(jsonBytes);

// Ensure custom additional options are present
Assert.Contains("\"customFlag\":false", jsonString);
Assert.Matches("\"fullCount\":true.*\"fullCount\":false", jsonString);
Assert.Contains("\"oneShardAttributeValue\":\"tenant-123\"", jsonString);

// Ensure the AdditionalOptions property itself is not present
Assert.DoesNotContain("\"additionalOptions\"", jsonString);
}

private void AssertDefaultOptions(ApiClientSerializationOptions options)
{
Assert.False(options.UseCamelCasePropertyNames);
Assert.True(options.IgnoreNullValues);
Assert.False(options.UseStringEnumConversion);
}
}
}
}
15 changes: 13 additions & 2 deletions arangodb-net-standard/CursorApi/Models/PostCursorOptions.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
namespace ArangoDBNetStandard.CursorApi.Models
using System.Collections.Generic;
using Newtonsoft.Json;

namespace ArangoDBNetStandard.CursorApi.Models
{
/// <summary>
/// Represents extra options for the AQL query.
/// AdditionalOptions can hold arbitrary server options (flattened via JsonExtensionData).
/// </summary>
public class PostCursorOptions
{
Expand Down Expand Up @@ -119,5 +123,12 @@ public class PostCursorOptions
/// This feature is only available in the Enterprise Edition.
/// </summary>
public bool? SkipInaccessibleCollections { get; set; }

/// <summary>
/// Arbitrary additional options not (yet) modeled as strongly typed properties.
/// Entries are serialized at the same level as known properties (flattened).
/// </summary>
[JsonExtensionData]
public IDictionary<string, object> AdditionalOptions { get; set; }
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think we should avoid putting a direct dependency on Newtonsoft.Json in the models. In theory other serialization options are available (e.g. System.Text.Json).

I wonder if this same could be achieved by sub-classing PostCursorOptions in client code?

Copy link
Author

Choose a reason for hiding this comment

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

I've tested your suggestion and it indeed works. For example, given the following:

using System.Collections.Generic;
using Newtonsoft.Json;

namespace ArangoDBNetStandard.CursorApi.Models
{
    public class ExtendedPostCursorOptions : PostCursorOptions
    {
        [JsonExtensionData]
        public IDictionary<string, object> AdditionalOptions { get; set; }
    }
}

The given test passes as expected:

[Fact]
public void Serialize_ShouldIncludeAdditionalOptions_WhenSerializingPostCursorOptions()
{
    var body = new PostCursorBody
    {
        Options = new ExtendedPostCursorOptions
        {
            FullCount = true,
            AdditionalOptions = new Dictionary<string, object>
            {
                ["fullCount"] = false,
                ["customFlag"] = false,
                ["oneShardAttributeValue"] = "tenant-123"
            }
        }
    };

    var serialization = new JsonNetApiClientSerialization();
    byte[] jsonBytes = serialization.Serialize(body, new ApiClientSerializationOptions(
        useCamelCasePropertyNames: true, ignoreNullValues: true));
    string jsonString = Encoding.UTF8.GetString(jsonBytes);

    // Ensure custom additional options are present
    Assert.Contains("\"customFlag\":false", jsonString);
    Assert.Matches("\"fullCount\":true.*\"fullCount\":false", jsonString);
    Assert.Contains("\"oneShardAttributeValue\":\"tenant-123\"", jsonString);

    // Ensure the AdditionalOptions property itself is not present
    Assert.DoesNotContain("\"additionalOptions\"", jsonString);
}

I'm closing the PR because this solution is enough for additional options.
It's worth noting that in the options class summary, though.

}
}
}