Skip to content

Commit 8fbb1c9

Browse files
committed
fix: Improve string payload handling for RestJson protocol services
1 parent 062cc18 commit 8fbb1c9

File tree

8 files changed

+85
-72
lines changed

8 files changed

+85
-72
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"core": {
3+
"changeLogMessages": [
4+
"Updated `restJson1` protocol services to use `text/plain` as `Content-Type` (instead of `application/json`) for string payloads"
5+
],
6+
"type": "Patch",
7+
"updateMinimum": false
8+
},
9+
"services": [
10+
{
11+
"serviceName": "DataExchange",
12+
"type": "Patch",
13+
"changeLogMessages": [
14+
"Updated `SendApiAsset` operation to set correct `Content-Type` header"
15+
]
16+
}
17+
]
18+
}

generator/ProtocolTestsGenerator/smithy-dotnet-codegen/src/main/java/software/amazon/smithy/dotnet/codegen/customizations/ProtocolTestCustomizations.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,6 @@ private ProtocolTestCustomizations() {
100100
);
101101
public static final List<String> VNextTests = Arrays.asList(
102102
//These are the tests that are failing in v4 after updating to 1.54.0 and artifacts 1.0.3004.0. Each one needs to be investigated.
103-
"RestJsonStringPayloadRequest",
104103
"RestJsonNullAndEmptyHeaders",
105104
"RestJsonSerializesSparseNullMapValues",
106105
"NullAndEmptyHeaders"

generator/ServiceClientGeneratorLib/Generators/Marshallers/JsonRPCRequestMarshaller.cs

Lines changed: 56 additions & 57 deletions
Large diffs are not rendered by default.

generator/ServiceClientGeneratorLib/Generators/Marshallers/JsonRPCRequestMarshaller.tt

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ namespace <#=this.Config.Namespace #>.Model.Internal.MarshallTransformations
4949
request.Headers["X-Amz-Target"] = target;
5050
<#
5151
}
52+
53+
var payload = this.Operation.RequestPayloadMember;
5254
if (this.Operation.HttpMethod != "GET" && this.Operation.HttpMethod != "DELETE")
5355
{
5456

@@ -62,6 +64,12 @@ namespace <#=this.Config.Namespace #>.Model.Internal.MarshallTransformations
6264
{
6365
#>
6466
request.Headers["Content-Type"] = "application/x-amz-json-<#=this.Config.ServiceModel.JsonVersion #>";
67+
<#
68+
}
69+
else if (payload?.Shape.IsString == true)
70+
{
71+
#>
72+
request.Headers["Content-Type"] = "text/plain";
6573
<#
6674
}
6775
else if (this.Operation.RequestHasBodyMembers || this.Operation.RequestPayloadMember != null)
@@ -90,7 +98,6 @@ namespace <#=this.Config.Namespace #>.Model.Internal.MarshallTransformations
9098
request.ResourcePath = "<#=this.Operation.RequestUri #>";
9199
<#
92100

93-
var payload = this.Operation.RequestPayloadMember;
94101
var shouldMarshallPayload = (payload != null && !payload.IsMemoryStream && !payload.Shape.IsString);
95102
// Process any members which are marshalled as part of the request body
96103
if (this.Operation.RequestHasBodyMembers || shouldMarshallPayload)
@@ -143,9 +150,6 @@ namespace <#=this.Config.Namespace #>.Model.Internal.MarshallTransformations
143150
{
144151
#>
145152
request.Content = System.Text.Encoding.UTF8.GetBytes(publicRequest.<#= payload.PropertyName #>);
146-
<# if (payload.Shape.IsEnum) { #>
147-
request.Headers["Content-Type"] = "text/plain";
148-
<# } #>
149153
<#
150154
}
151155
else if (payload?.IsMemoryStream == true)

sdk/src/Services/DataExchange/Generated/Model/Internal/MarshallTransformations/SendApiAssetRequestMarshaller.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public IRequest Marshall(AmazonWebServiceRequest input)
5959
public IRequest Marshall(SendApiAssetRequest publicRequest)
6060
{
6161
IRequest request = new DefaultRequest(publicRequest, "Amazon.DataExchange");
62-
request.Headers["Content-Type"] = "application/json";
62+
request.Headers["Content-Type"] = "text/plain";
6363
request.Headers[Amazon.Util.HeaderKeys.XAmzApiVersion] = "2017-07-25";
6464
request.HttpMethod = "POST";
6565

sdk/test/ProtocolTests/Generated/RestJsonProtocol/dotnet-protocol-test-codegen/HttpStringPayload.cs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,6 @@ namespace AWSSDK.ProtocolTests.RestJson
4040
[TestClass]
4141
public class HttpStringPayload
4242
{
43-
/*
44-
* This test either requires a breaking change and will be addressed
45-
* in V4, or has a backlog item to be fixed in the future. Please
46-
* refer to the VNextTests list to see which it is.
47-
* */
48-
[Ignore]
4943
[TestMethod]
5044
[TestCategory("ProtocolTest")]
5145
[TestCategory("RequestTest")]

sdk/test/Services/RestJsonProtocol/Generated/Model/Internal/MarshallTransformations/HttpEnumPayloadRequestMarshaller.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,13 +59,12 @@ public IRequest Marshall(AmazonWebServiceRequest input)
5959
public IRequest Marshall(HttpEnumPayloadRequest publicRequest)
6060
{
6161
IRequest request = new DefaultRequest(publicRequest, "Amazon.RestJsonProtocol");
62-
request.Headers["Content-Type"] = "application/json";
62+
request.Headers["Content-Type"] = "text/plain";
6363
request.Headers[Amazon.Util.HeaderKeys.XAmzApiVersion] = "2019-12-16";
6464
request.HttpMethod = "POST";
6565

6666
request.ResourcePath = "/EnumPayload";
6767
request.Content = System.Text.Encoding.UTF8.GetBytes(publicRequest.Payload);
68-
request.Headers["Content-Type"] = "text/plain";
6968

7069
return request;
7170
}

sdk/test/Services/RestJsonProtocol/Generated/Model/Internal/MarshallTransformations/HttpStringPayloadRequestMarshaller.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public IRequest Marshall(AmazonWebServiceRequest input)
5959
public IRequest Marshall(HttpStringPayloadRequest publicRequest)
6060
{
6161
IRequest request = new DefaultRequest(publicRequest, "Amazon.RestJsonProtocol");
62-
request.Headers["Content-Type"] = "application/json";
62+
request.Headers["Content-Type"] = "text/plain";
6363
request.Headers[Amazon.Util.HeaderKeys.XAmzApiVersion] = "2019-12-16";
6464
request.HttpMethod = "POST";
6565

0 commit comments

Comments
 (0)