Repository: Azure/azure-sdk-for-go
Pull request #20716 (2023-04-28 18:47:08)

Cosmos DB: Enable merge support
Cosmos Go SDK is currently merge proof from the functional perspective, but the Cosmos DB service was relying on a header to be sent from the client to signal this support.

This PR adds the required header. Future Cosmos Go SDK features will be merge proof by design once added (cross partition query, change feed).

- [x] The purpose of this PR is explained in this or a referenced issue.
- [x] The PR does not update generated files.
   - These files are managed by the codegen framework at [Azure/autorest.go][].
- [x] Tests are included and/or updated for code changes.
- [x] Updates to [CHANGELOG.md][] are included.
- [x] MIT license headers are included in each file.

Closes https://github.com/Azure/azure-sdk-for-go/issues/20709


Patch:
diff --git a/sdk/data/azcosmos/CHANGELOG.md b/sdk/data/azcosmos/CHANGELOG.md
index 951442859e..f4652730f5 100644
--- a/sdk/data/azcosmos/CHANGELOG.md
+++ b/sdk/data/azcosmos/CHANGELOG.md
@@ -2,6 +2,9 @@
 
 ## 0.3.5 (2023-05-09)
 
+### Features Added
+* Added support for accounts with [merge support](https://aka.ms/cosmosdbsdksupportformerge) enabled
+
 ### Bugs Fixed
 * Fixed unmarshalling error when using projections in value queries
 
diff --git a/sdk/data/azcosmos/cosmos_client.go b/sdk/data/azcosmos/cosmos_client.go
index 94c455aed1..41807ab416 100644
--- a/sdk/data/azcosmos/cosmos_client.go
+++ b/sdk/data/azcosmos/cosmos_client.go
@@ -395,6 +395,7 @@ func (c *Client) createRequest(
 
 	req.Raw().Header.Set(headerXmsDate, time.Now().UTC().Format(http.TimeFormat))
 	req.Raw().Header.Set(headerXmsVersion, "2020-11-05")
+	req.Raw().Header.Set(cosmosHeaderSDKSupportedCapabilities, supportedCapabilitiesHeaderValue)
 
 	req.SetOperationValue(operationContext)
 
diff --git a/sdk/data/azcosmos/cosmos_headers.go b/sdk/data/azcosmos/cosmos_headers.go
index d054bd652b..5c8ea72c48 100644
--- a/sdk/data/azcosmos/cosmos_headers.go
+++ b/sdk/data/azcosmos/cosmos_headers.go
@@ -33,6 +33,7 @@ const (
 	cosmosHeaderIsBatchRequest                     string = "x-ms-cosmos-is-batch-request"
 	cosmosHeaderIsBatchAtomic                      string = "x-ms-cosmos-batch-atomic"
 	cosmosHeaderIsBatchOrdered                     string = "x-ms-cosmos-batch-ordered"
+	cosmosHeaderSDKSupportedCapabilities           string = "x-ms-cosmos-sdk-supportedcapabilities"
 	headerXmsDate                                  string = "x-ms-date"
 	headerAuthorization                            string = "Authorization"
 	headerContentType                              string = "Content-Type"
diff --git a/sdk/data/azcosmos/sdk_capabilities.go b/sdk/data/azcosmos/sdk_capabilities.go
new file mode 100644
index 0000000000..71157b5fed
--- /dev/null
+++ b/sdk/data/azcosmos/sdk_capabilities.go
@@ -0,0 +1,21 @@
+// Copyright (c) Microsoft Corporation. All rights reserved.
+// Licensed under the MIT License.
+
+package azcosmos
+
+import "strconv"
+
+type supportedCapabilities uint64
+
+const (
+	supportedCapabilitiesNone           supportedCapabilities = 0
+	supportedCapabilitiesPartitionMerge supportedCapabilities = 1 << 0
+)
+
+var supportedCapabilitiesHeaderValue = supportedCapabilitiesAsString()
+
+func supportedCapabilitiesAsString() string {
+	supported := supportedCapabilitiesNone
+	supported |= supportedCapabilitiesPartitionMerge
+	return strconv.FormatUint(uint64(supported), 10)
+}


Test patch:
diff --git a/sdk/data/azcosmos/cosmos_client_test.go b/sdk/data/azcosmos/cosmos_client_test.go
index f33e730722..d93f4ca93d 100644
--- a/sdk/data/azcosmos/cosmos_client_test.go
+++ b/sdk/data/azcosmos/cosmos_client_test.go
@@ -258,6 +258,10 @@ func TestCreateRequest(t *testing.T) {
 		t.Errorf("Expected %v, but got %v", "2020-11-05", req.Raw().Header.Get(headerXmsVersion))
 	}
 
+	if req.Raw().Header.Get(cosmosHeaderSDKSupportedCapabilities) != supportedCapabilitiesHeaderValue {
+		t.Errorf("Expected %v, but got %v", supportedCapabilitiesHeaderValue, req.Raw().Header.Get(cosmosHeaderSDKSupportedCapabilities))
+	}
+
 	opValue := pipelineRequestOptions{}
 	if !req.OperationValue(&opValue) {
 		t.Error("Expected to find operation value")