Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Public properties : Fixes public types to be upgrade safe so new content is not lost on deserialize and serialize paths. #2712

Merged
merged 13 commits into from
Sep 15, 2021
Merged
Prev Previous commit
Next Next commit
Add additional property for few more properties
  • Loading branch information
sourabh1007 committed Sep 15, 2021
commit a84752685709f4975dd96caae2553eec6748a84b
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ namespace Microsoft.Azure.Cosmos
using System.Linq;
using Microsoft.Azure.Documents;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;

/// <summary>
/// Details of an encryption key for use with the Azure Cosmos DB service.
Expand Down Expand Up @@ -61,6 +62,7 @@ internal ClientEncryptionKeyProperties(ClientEncryptionKeyProperties source)
this.WrappedDataEncryptionKey = new byte[source.WrappedDataEncryptionKey.Length];
source.WrappedDataEncryptionKey.CopyTo(this.WrappedDataEncryptionKey, index: 0);
}
this.AdditionalProperties = source.AdditionalProperties;
}

/// <summary>
Expand Down Expand Up @@ -148,6 +150,13 @@ internal ClientEncryptionKeyProperties(ClientEncryptionKeyProperties source)
[JsonProperty(PropertyName = Constants.Properties.RId, NullValueHandling = NullValueHandling.Ignore)]
internal string ResourceId { get; set; }

/// <summary>
/// This contains additional values for scenarios where the SDK is not aware of new fields.
/// This ensures that if resource is read and updated none of the fields will be lost in the process.
/// </summary>
[JsonExtensionData]
internal IDictionary<string, JToken> AdditionalProperties { get; private set; }

/// <summary>
/// Compares this instance of client encryption key properties to another object.
/// </summary>
Expand All @@ -170,13 +179,43 @@ public bool Equals(ClientEncryptionKeyProperties other)
this.EncryptionAlgorithm == other.EncryptionAlgorithm &&
ClientEncryptionKeyProperties.Equals(this.WrappedDataEncryptionKey, other.WrappedDataEncryptionKey) &&
EqualityComparer<EncryptionKeyWrapMetadata>.Default.Equals(this.EncryptionKeyWrapMetadata, other.EncryptionKeyWrapMetadata) &&
this.AdditionalProperties != null && other.AdditionalProperties != null &&
this.CompareDictionary(this.AdditionalProperties, other.AdditionalProperties) &&
this.CreatedTime == other.CreatedTime &&
this.ETag == other.ETag &&
this.LastModified == other.LastModified &&
this.SelfLink == other.SelfLink &&
this.ResourceId == other.ResourceId;
}

private bool CompareDictionary(IDictionary<string, JToken> dict1, IDictionary<string, JToken> dict2)
sourabh1007 marked this conversation as resolved.
Show resolved Hide resolved
{
bool isEqual = false;
if (dict1.Count == dict2.Count)
{
isEqual = true;
foreach (KeyValuePair<string, JToken> pair in dict1)
{
if (dict2.TryGetValue(pair.Key, out JToken value))
{
// Require value be equal.
if (!value.ToString().Equals(pair.Value.ToString()))
{
isEqual = false;
break;
}
}
else
{
// Require key be present.
isEqual = false;
break;
}
}
}
sourabh1007 marked this conversation as resolved.
Show resolved Hide resolved
return isEqual;
}

/// <summary>
/// Gets a hash code for the properties of this instance to optimize comparisons.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@

namespace Microsoft.Azure.Cosmos
{
using System.Collections.Generic;
using Microsoft.Azure.Documents;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;

internal sealed class OfferAutoscaleAutoUpgradeProperties
{
Expand All @@ -25,6 +27,13 @@ internal OfferAutoscaleAutoUpgradeProperties(int incrementPercent)
[JsonProperty(PropertyName = Constants.Properties.AutopilotThroughputPolicy, NullValueHandling = NullValueHandling.Ignore)]
public AutoscaleThroughputProperties ThroughputProperties { get; private set; }

/// <summary>
/// This contains additional values for scenarios where the SDK is not aware of new fields.
/// This ensures that if resource is read and updated none of the fields will be lost in the process.
/// </summary>
[JsonExtensionData]
internal IDictionary<string, JToken> AdditionalProperties { get; private set; }

internal string GetJsonString()
{
return JsonConvert.SerializeObject(this, Formatting.None);
Expand All @@ -39,6 +48,7 @@ public AutoscaleThroughputProperties(int incrementPercent)

[JsonProperty(PropertyName = Constants.Properties.AutopilotThroughputPolicyIncrementPercent, NullValueHandling = NullValueHandling.Ignore)]
public int IncrementPercent { get; private set; }

}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@

namespace Microsoft.Azure.Cosmos
{
using System.Collections.Generic;
using Microsoft.Azure.Documents;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;

internal sealed class OfferAutoscaleProperties
{
Expand Down Expand Up @@ -39,6 +41,13 @@ internal OfferAutoscaleProperties(
[JsonProperty(PropertyName = Constants.Properties.AutopilotAutoUpgradePolicy, NullValueHandling = NullValueHandling.Ignore)]
public OfferAutoscaleAutoUpgradeProperties AutoscaleAutoUpgradeProperties { get; private set; }

/// <summary>
/// This contains additional values for scenarios where the SDK is not aware of new fields.
/// This ensures that if resource is read and updated none of the fields will be lost in the process.
/// </summary>
[JsonExtensionData]
internal IDictionary<string, JToken> AdditionalProperties { get; private set; }

internal string GetJsonString()
{
return JsonConvert.SerializeObject(this, Formatting.None);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@
namespace Microsoft.Azure.Cosmos
{
using System;
using System.Collections.Generic;
using Microsoft.Azure.Documents;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;

internal sealed class OfferContentProperties
{
Expand Down Expand Up @@ -54,6 +56,13 @@ private OfferContentProperties(OfferAutoscaleProperties autoscaleProperties)
[JsonProperty(PropertyName = Constants.Properties.OfferLastReplaceTimestamp, DefaultValueHandling = DefaultValueHandling.Ignore)]
internal long? OfferLastReplaceTimestamp { get; private set; }

/// <summary>
/// This contains additional values for scenarios where the SDK is not aware of new fields.
/// This ensures that if resource is read and updated none of the fields will be lost in the process.
/// </summary>
[JsonExtensionData]
internal IDictionary<string, JToken> AdditionalProperties { get; private set; }

public static OfferContentProperties CreateManualOfferConent(int throughput)
{
return new OfferContentProperties(manualThroughput: throughput);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
//------------------------------------------------------------
namespace Microsoft.Azure.Cosmos
{
using System.Collections.Generic;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;

/// <summary>
/// Represents bounding box for geometry spatial path in the Azure Cosmos DB service
Expand Down Expand Up @@ -70,5 +72,12 @@ public double Ymax
{
get; set;
}

/// <summary>
/// This contains additional values for scenarios where the SDK is not aware of new fields.
/// This ensures that if resource is read and updated none of the fields will be lost in the process.
/// </summary>
[JsonExtensionData]
internal IDictionary<string, JToken> AdditionalProperties { get; private set; }
sourabh1007 marked this conversation as resolved.
Show resolved Hide resolved
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@
namespace Microsoft.Azure.Cosmos
{
using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Azure.Documents;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
using Newtonsoft.Json.Linq;

/// <summary>
/// Represents a permission in the Azure Cosmos DB service.
Expand Down Expand Up @@ -203,5 +205,12 @@ public PartitionKey? ResourcePartitionKey

[JsonProperty(PropertyName = Constants.Properties.ResourcePartitionKey, NullValueHandling = NullValueHandling.Ignore)]
internal Documents.Routing.PartitionKeyInternal InternalResourcePartitionKey { get; private set; }

/// <summary>
/// This contains additional values for scenarios where the SDK is not aware of new fields.
/// This ensures that if resource is read and updated none of the fields will be lost in the process.
/// </summary>
[JsonExtensionData]
internal IDictionary<string, JToken> AdditionalProperties { get; private set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@
namespace Microsoft.Azure.Cosmos
{
using System;
using System.Collections.Generic;
using Microsoft.Azure.Documents;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;

/// <summary>
/// Represents a throughput of the resources in the Azure Cosmos DB service.
Expand Down Expand Up @@ -169,5 +171,12 @@ internal static ThroughputProperties CreateAutoscaleThroughput(
/// </summary>
[JsonProperty(PropertyName = Constants.Properties.OfferVersion, DefaultValueHandling = DefaultValueHandling.Ignore)]
internal string OfferVersion { get; private set; }

/// <summary>
/// This contains additional values for scenarios where the SDK is not aware of new fields.
/// This ensures that if resource is read and updated none of the fields will be lost in the process.
/// </summary>
[JsonExtensionData]
internal IDictionary<string, JToken> AdditionalProperties { get; private set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@

namespace Microsoft.Azure.Cosmos.Scripts
{
using System.Collections.Generic;
using Microsoft.Azure.Documents;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
using Newtonsoft.Json.Linq;

/// <summary>
/// Represents a trigger in the Azure Cosmos DB service.
Expand Down Expand Up @@ -88,5 +90,12 @@ public class TriggerProperties
/// </remarks>
[JsonProperty(PropertyName = Constants.Properties.SelfLink, NullValueHandling = NullValueHandling.Ignore)]
public string SelfLink { get; private set; }

/// <summary>
/// This contains additional values for scenarios where the SDK is not aware of new fields.
/// This ensures that if resource is read and updated none of the fields will be lost in the process.
/// </summary>
[JsonExtensionData]
internal IDictionary<string, JToken> AdditionalProperties { get; private set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@

namespace Microsoft.Azure.Cosmos.Scripts
{
using System.Collections.Generic;
using Microsoft.Azure.Documents;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;

/// <summary>
/// Represents a user defined function in the Azure Cosmos service.
Expand Down Expand Up @@ -102,5 +104,12 @@ public class UserDefinedFunctionProperties
/// </remarks>
[JsonProperty(PropertyName = Constants.Properties.SelfLink, NullValueHandling = NullValueHandling.Ignore)]
public string SelfLink { get; private set; }

/// <summary>
/// This contains additional values for scenarios where the SDK is not aware of new fields.
/// This ensures that if resource is read and updated none of the fields will be lost in the process.
/// </summary>
[JsonExtensionData]
internal IDictionary<string, JToken> AdditionalProperties { get; private set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@
namespace Microsoft.Azure.Cosmos
{
using System;
using System.Collections.Generic;
using Microsoft.Azure.Documents;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;

/// <summary>
/// Represents a user in the Azure Cosmos DB service.
Expand Down Expand Up @@ -113,5 +115,12 @@ public string Id
/// </summary>
/// <value>The self-link of the permissions associated with the user.</value>
internal string PermissionsLink => $"{this.SelfLink?.TrimEnd('/')}/{ this.Permissions}";

/// <summary>
/// This contains additional values for scenarios where the SDK is not aware of new fields.
/// This ensures that if resource is read and updated none of the fields will be lost in the process.
/// </summary>
[JsonExtensionData]
internal IDictionary<string, JToken> AdditionalProperties { get; private set; }
}
}
Loading