Skip to content

Commit 8f7c3c9

Browse files
authored
fix: update generator and core for so xml map unmarshaller can unmarshall any key value name pair (#3652)
1 parent fdb5b25 commit 8f7c3c9

File tree

33 files changed

+50
-80
lines changed

33 files changed

+50
-80
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"core": {
3+
"changeLogMessages": [
4+
"Update XmlDictionary and KeyValueUnmarshallers to be able to handle any Key and Value Xml Element name"
5+
],
6+
"type": "patch",
7+
"updateMinimum": true
8+
}
9+
}

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

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -99,20 +99,10 @@ private ProtocolTestCustomizations() {
9999
"QueryNoInputAndOutput"
100100
);
101101
public static final List<String> VNextTests = Arrays.asList(
102-
// These tests are not actually breaking change but have their own backlog item to be addressed.
103-
// To avoid creating yet another list to check we'll add these here so they have an ignore flag.
104-
"XmlMapsXmlName",
105-
"FlattenedXmlMapWithXmlName",
106-
"RestXmlFlattenedXmlMapWithXmlNamespace",
107-
"QueryQueryXmlMapsXmlName",
108-
"QueryQueryFlattenedXmlMapWithXmlName",
109-
"QueryQueryFlattenedXmlMapWithXmlNamespace",
110-
"RestXmlXmlMapWithXmlNamespace",
111102
//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.
112103
"RestJsonStringPayloadRequest",
113104
"RestJsonNullAndEmptyHeaders",
114105
"RestJsonSerializesSparseNullMapValues",
115-
"NestedXmlMapWithXmlNameDeserializes",
116106
"NullAndEmptyHeaders"
117107
);
118108
}

generator/ServiceClientGeneratorLib/Member.cs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -728,10 +728,12 @@ public string DetermineTypeUnmarshallerInstantiate(JsonData extendedData, string
728728
case "map":
729729
var keyType = DetermineType(memberShape[Shape.KeyKey], true);
730730
var keyTypeUnmarshaller = GetTypeUnmarshallerName(memberShape[Shape.KeyKey]);
731+
var keyLocationName = memberShape[Shape.KeyKey][ServiceModel.LocationNameKey] == null ? "key" : memberShape[Shape.KeyKey][ServiceModel.LocationNameKey].ToString();
731732
var keyTypeUnmarshallerInstantiate = DetermineTypeUnmarshallerInstantiate(memberShape[Shape.KeyKey], typeNode.ToString());
732733

733734
var valueType = DetermineType(memberShape[Shape.ValueKey], true, false);
734735
var valueTypeUnmarshaller = GetTypeUnmarshallerName(memberShape[Shape.ValueKey], false);
736+
var valueLocationName = memberShape[Shape.ValueKey][ServiceModel.LocationNameKey] == null ? "value" : memberShape[Shape.ValueKey][ServiceModel.LocationNameKey].ToString();
735737
var valueTypeUnmarshallerInstantiate = DetermineTypeUnmarshallerInstantiate(memberShape[Shape.ValueKey], typeNode.ToString(), false);
736738

737739
//Direct sub maps can not be flattened. If the parent was a map then force the sub map to not be flat.
@@ -745,11 +747,11 @@ public string DetermineTypeUnmarshallerInstantiate(JsonData extendedData, string
745747
return string.Format("new JsonDictionaryUnmarshaller<{0}, {1}, {2}, {3}>(StringUnmarshaller.Instance, {5})",
746748
keyType, valueType, keyTypeUnmarshaller, valueTypeUnmarshaller, keyTypeUnmarshallerInstantiate, valueTypeUnmarshallerInstantiate);
747749
else if (this.model.Type == ServiceType.Rest_Xml && !isFlat)
748-
return string.Format("new XmlDictionaryUnmarshaller<{0}, {1}, {2}, {3}>(StringUnmarshaller.Instance, {5})",
749-
keyType, valueType, keyTypeUnmarshaller, valueTypeUnmarshaller, keyTypeUnmarshallerInstantiate, valueTypeUnmarshallerInstantiate);
750+
return string.Format("new XmlDictionaryUnmarshaller<{0}, {1}, {2}, {3}>(StringUnmarshaller.Instance, {5}, \"{6}\", \"{7}\")",
751+
keyType, valueType, keyTypeUnmarshaller, valueTypeUnmarshaller, keyTypeUnmarshallerInstantiate, valueTypeUnmarshallerInstantiate, keyLocationName, valueLocationName);
750752
else
751-
return string.Format("new XmlKeyValueUnmarshaller<{0}, {1}, {2}, {3}>(StringUnmarshaller.Instance, {5})",
752-
keyType, valueType, keyTypeUnmarshaller, valueTypeUnmarshaller, keyTypeUnmarshallerInstantiate, valueTypeUnmarshallerInstantiate);
753+
return string.Format("new XmlKeyValueUnmarshaller<{0}, {1}, {2}, {3}>(StringUnmarshaller.Instance, {5}, \"{6}\", \"{7}\")",
754+
keyType, valueType, keyTypeUnmarshaller, valueTypeUnmarshaller, keyTypeUnmarshallerInstantiate, valueTypeUnmarshallerInstantiate, keyLocationName, valueLocationName);
753755
case "list":
754756
var listType = DetermineType(memberShape[Shape.MemberKey], true, false);
755757
var listTypeUnmarshaller = GetTypeUnmarshallerName(memberShape[Shape.MemberKey], false);

sdk/src/Core/Amazon.Runtime/Internal/Transform/SimpleTypeUnmarshaller.cs

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -843,32 +843,36 @@ public class XmlKeyValueUnmarshaller<K, V, KUnmarshaller, VUnmarshaller> :
843843
{
844844
private KUnmarshaller keyUnmarshaller;
845845
private VUnmarshaller valueUnmarshaller;
846+
private string keyName;
847+
private string valueName;
846848

847-
public XmlKeyValueUnmarshaller(KUnmarshaller keyUnmarshaller, VUnmarshaller valueUnmarshaller)
849+
public XmlKeyValueUnmarshaller(KUnmarshaller keyUnmarshaller, VUnmarshaller valueUnmarshaller, string keyName, string valueName)
848850
{
849851
this.keyUnmarshaller = keyUnmarshaller;
850852
this.valueUnmarshaller = valueUnmarshaller;
853+
this.keyName = keyName;
854+
this.valueName = valueName;
851855
}
852856

853857
public KeyValuePair<K, V> Unmarshall(XmlUnmarshallerContext context)
854858
{
855859
K key = default(K);
856860
V value = default(V);
861+
// skip namespaces and attributes, since we don't unmarshall the namespaces.
862+
// Read until the next non attribute so that the target depth is set correctly.
863+
while (context.IsAttribute)
864+
context.Read();
857865

858866
int originalDepth = context.CurrentDepth;
859867
int targetDepth = originalDepth + 1;
860868

861869
while (context.Read())
862870
{
863-
if (context.TestExpression("key", targetDepth))
871+
if (context.TestExpression(keyName, targetDepth))
864872
{
865873
key = this.keyUnmarshaller.Unmarshall(context);
866874
}
867-
else if (context.TestExpression("name", targetDepth))
868-
{
869-
key = this.keyUnmarshaller.Unmarshall(context);
870-
}
871-
else if (context.TestExpression("value", targetDepth))
875+
else if (context.TestExpression(valueName, targetDepth))
872876
{
873877
value = this.valueUnmarshaller.Unmarshall(context);
874878
}
@@ -974,16 +978,15 @@ public List<T> Unmarshall(JsonUnmarshallerContext context, ref StreamingUtf8Json
974978
}
975979
}
976980

977-
978981
public class XmlDictionaryUnmarshaller<TKey, TValue, TKeyUnmarshaller, TValueUnmarshaller> : IXmlUnmarshaller<Dictionary<TKey, TValue>, XmlUnmarshallerContext>
979982
where TKeyUnmarshaller : IXmlUnmarshaller<TKey, XmlUnmarshallerContext>
980983
where TValueUnmarshaller : IXmlUnmarshaller<TValue, XmlUnmarshallerContext>
981984
{
982985
private XmlKeyValueUnmarshaller<TKey, TValue, TKeyUnmarshaller, TValueUnmarshaller> KVUnmarshaller;
983986

984-
public XmlDictionaryUnmarshaller(TKeyUnmarshaller kUnmarshaller, TValueUnmarshaller vUnmarshaller)
987+
public XmlDictionaryUnmarshaller(TKeyUnmarshaller kUnmarshaller, TValueUnmarshaller vUnmarshaller, string keyName, string valueName)
985988
{
986-
KVUnmarshaller = new XmlKeyValueUnmarshaller<TKey, TValue, TKeyUnmarshaller, TValueUnmarshaller>(kUnmarshaller, vUnmarshaller);
989+
KVUnmarshaller = new XmlKeyValueUnmarshaller<TKey, TValue, TKeyUnmarshaller, TValueUnmarshaller>(kUnmarshaller, vUnmarshaller, keyName, valueName);
987990
}
988991

989992
public Dictionary<TKey, TValue> Unmarshall(XmlUnmarshallerContext context)

sdk/test/ProtocolTests/Generated/QueryProtocol/dotnet-protocol-test-codegen/FlattenedXmlMapWithXmlName.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,6 @@ public class FlattenedXmlMapWithXmlName
4242
/// Serializes flattened XML maps in responses that have xmlName on
4343
/// members
4444
/// </summary>
45-
// This test requires a breaking change, and will be addressed in V4
46-
[Ignore]
4745
[TestMethod]
4846
[TestCategory("ProtocolTest")]
4947
[TestCategory("ResponseTest")]

sdk/test/ProtocolTests/Generated/QueryProtocol/dotnet-protocol-test-codegen/FlattenedXmlMapWithXmlNamespace.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,6 @@ public class FlattenedXmlMapWithXmlNamespace
4242
/// Serializes flattened XML maps in responses that have xmlNamespace
4343
/// and xmlName on members
4444
/// </summary>
45-
// This test requires a breaking change, and will be addressed in V4
46-
[Ignore]
4745
[TestMethod]
4846
[TestCategory("ProtocolTest")]
4947
[TestCategory("ResponseTest")]

sdk/test/ProtocolTests/Generated/QueryProtocol/dotnet-protocol-test-codegen/XmlMapsXmlName.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,6 @@ public class XmlMapsXmlName
4141
/// <summary>
4242
/// Serializes XML lists
4343
/// </summary>
44-
// This test requires a breaking change, and will be addressed in V4
45-
[Ignore]
4644
[TestMethod]
4745
[TestCategory("ProtocolTest")]
4846
[TestCategory("ResponseTest")]

sdk/test/ProtocolTests/Generated/RestXmlProtocol/dotnet-protocol-test-codegen/FlattenedXmlMapWithXmlName.cs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,6 @@ public class FlattenedXmlMapWithXmlName
4444
/// Serializes flattened XML maps in requests that have xmlName on
4545
/// members
4646
/// </summary>
47-
/*
48-
* This test either requires a breaking change and will be addressed
49-
* in V4, or has a backlog item to be fixed in the future. Please
50-
* refer to the VNextTests list to see which it is.
51-
* */
52-
[Ignore]
5347
[TestMethod]
5448
[TestCategory("ProtocolTest")]
5549
[TestCategory("RequestTest")]
@@ -88,8 +82,6 @@ public void FlattenedXmlMapWithXmlNameRequest()
8882
/// Serializes flattened XML maps in responses that have xmlName on
8983
/// members
9084
/// </summary>
91-
// This test requires a breaking change, and will be addressed in V4
92-
[Ignore]
9385
[TestMethod]
9486
[TestCategory("ProtocolTest")]
9587
[TestCategory("ResponseTest")]

sdk/test/ProtocolTests/Generated/RestXmlProtocol/dotnet-protocol-test-codegen/FlattenedXmlMapWithXmlNamespace.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,6 @@ public class FlattenedXmlMapWithXmlNamespace
4444
/// Serializes flattened XML maps in responses that have xmlNamespace
4545
/// and xmlName on members
4646
/// </summary>
47-
// This test requires a breaking change, and will be addressed in V4
48-
[Ignore]
4947
[TestMethod]
5048
[TestCategory("ProtocolTest")]
5149
[TestCategory("ResponseTest")]

sdk/test/ProtocolTests/Generated/RestXmlProtocol/dotnet-protocol-test-codegen/NestedXmlMapWithXmlName.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,6 @@ public void NestedXmlMapWithXmlNameSerializesRequest()
9292
/// Serializes nested XML maps in responses that have xmlName on
9393
/// members
9494
/// </summary>
95-
// This test requires a breaking change, and will be addressed in V4
96-
[Ignore]
9795
[TestMethod]
9896
[TestCategory("ProtocolTest")]
9997
[TestCategory("ResponseTest")]

0 commit comments

Comments
 (0)