Skip to content

Commit

Permalink
Fix non-streaming request with non-structured (not xml) plain string/…
Browse files Browse the repository at this point in the history
…blob payload serialization
  • Loading branch information
SergeyRyabinin committed Jan 30, 2025
1 parent 2f3410d commit 692c95c
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ namespace ${serviceNamespace}
{
namespace Model
{
#foreach($forwardDeclaration in $typeInfo.forwardDeclarations)
class $forwardDeclaration;
#end
#set($xmlRef = "${typeInfo.xmlNodeType}&")
#set($classNameRef = "${typeInfo.className}&")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,12 @@
#if($shapeMember.shape.enum)
${shapeMember.shape.name}Mapper::GetNameFor${shapeMember.shape.name}(${memberVarName})##
#elseif($shapeMember.shape.timeStamp)
#if($member.shape.timestampFormat != "unixTimestamp")
#set($timestamptFormatStr = $CppViewHelper.computeTimestampFormatInXml($shapeMember.shape))
${memberVarName}.ToGmtString(Aws::Utils::DateFormat::${timestamptFormatStr})##
#else
StringUtils::to_string(${memberVarName}.Seconds())##
#end
#elseif($shapeMember.shape.boolean)
std::boolalpha << ${memberVarName}##
#elseif($shapeMember.shape.blob)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,15 @@ Aws::String ${typeInfo.className}::SerializePayload() const
#set($xmlNamespace = ${payloadMember.xmlNamespace})
#set($locationName = $payloadMember.locationName)
#end
#if(!$payloadMember || !$payloadMember.shape.enum && !$payloadMember.shape.string && !$payloadMember.shape.string)##if payload is structured
#if($locationName)
XmlDocument payloadDoc = XmlDocument::CreateWithRootNode("${locationName}");
#else
XmlDocument payloadDoc = XmlDocument::CreateWithRootNode("${shape.payload}");
#end

XmlNode parentNode = payloadDoc.GetRootElement();
#end
#if($xmlNamespace)
#if($xmlNamespace.prefix)
#set($xmlnsKey = "xmlns:${xmlNamespace.prefix}")
Expand All @@ -85,14 +87,29 @@ Aws::String ${typeInfo.className}::SerializePayload() const
parentNode.SetAttributeValue("${xmlnsKey}", "${xmlNamespace.uri}");
#end

#if($payloadMember && !$member.shape.enum)
#if($payloadMember)
#if($payloadMember.shape.enum || $payloadMember.shape.string || $payloadMember.shape.string)
##payload member is "streamed", i.e. payload doc is not the XML, but the enum string/string/blob itself
##and CPP SDK did not generate legacy "streaming" request for some modelling quirks) - we need to set the payload to just a string/buffer.
#if($payloadMember.shape.enum)
if ($payloadMember.shape.name::NOT_SET != ${CppViewHelper.computeMemberVariableName($shape.payload)}) {
return ${payloadMember.shape.name}Mapper::GetNameFor${payloadMember.shape.name}(${CppViewHelper.computeMemberVariableName($shape.payload)});
}
return {};
#elseif($payloadMember.shape.string)
return ${CppViewHelper.computeMemberVariableName($shape.payload)};
#else
static_assert(false, "Failed to generate code to serialize non-streaming request with non-structured (not xml) plain string/blob payload" /*payloadMember: $payloadMember*/);
#end
#else
${CppViewHelper.computeMemberVariableName($shape.payload)}.AddToNode(parentNode);
if(parentNode.HasChildren())
{
return payloadDoc.ConvertToString();
}

return {};
#end
#else
#set($useRequiredField = true)
#set($callFromRequestShape = true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ namespace ${serviceNamespace}
{
namespace Model
{
#foreach($forwardDeclaration in $typeInfo.forwardDeclarations)
class $forwardDeclaration;
#end
#set($xmlRef = "${typeInfo.xmlNodeType}&")
#set($classNameRef = "${typeInfo.className}&")

Expand Down
10 changes: 5 additions & 5 deletions tools/scripts/codegen/protocol_tests_gen.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,10 +157,10 @@ def _collect_test_client_models(self) -> dict:
PROTOCOL_TESTS_ENDPOINT_RULES, None, use_smithy)
return service_models

def _get_client_models_metadata(self) -> set:
models = set()
def _get_client_models_metadata(self) -> list:
models = list()
model_files = os.listdir(self.client_models_dir)
for filename in model_files:
for filename in sorted(model_files):
if not os.path.isfile("/".join([self.client_models_dir, filename])):
continue
model_abspath = str(pathlib.Path(f"{self.client_models_dir}/{filename}").resolve())
Expand All @@ -169,7 +169,7 @@ def _get_client_models_metadata(self) -> set:
c2j_model = json.load(file_content)
model_metadata = self.ProtoTestC2jClientModelMetadata(filename, model_abspath,
c2j_model.get("metadata"))
models.add(model_metadata)
models.append(model_metadata)
except Exception as exc:
print(f"ERROR: unexpected file content in protocol tests clients dir {self.client_models_dir}. "
f"Expected c2j client model, but json metadata kew is missing: {exc}")
Expand All @@ -194,7 +194,7 @@ def _collect_test_definition_models(self) -> dict:

test_def_path = str(pathlib.Path(f"{self.test_definitions_dir}/{test_def_group}/{filename}").resolve())

def _get_corresponding_test_client(test_clients_md: set, test_path: str) -> list:
def _get_corresponding_test_client(test_clients_md: list, test_path: str) -> list:
# Get c2j client models matching the test suite
# more than 1 is possible (ex: xml and xml with namespace clients for a single test suite)
result = list()
Expand Down

0 comments on commit 692c95c

Please sign in to comment.