Skip to content

Commit

Permalink
Fix s3UnwrappedXmlOutput of LocationConstraint
Browse files Browse the repository at this point in the history
  • Loading branch information
nomick committed Jan 17, 2024
1 parent f01f0c5 commit da2d01c
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 2 deletions.
9 changes: 9 additions & 0 deletions codegen/src/dto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -202,11 +202,17 @@ pub fn collect_rust_types(model: &smithy::Model, ops: &Operations) -> RustTypes
};
fields.push(field);
}

let s3_unwrapped_xml_output = ops
.iter()
.any(|(_, op)| op.s3_unwrapped_xml_output && op.output == rs_shape_name);

let ty = rust::Type::Struct(rust::Struct {
name: rs_shape_name.clone(),
fields,
doc: shape.traits.doc().map(ToOwned::to_owned),

s3_unwrapped_xml_output,
xml_name: shape.traits.xml_name().map(o),
is_error_type: shape.traits.error().is_some(),
});
Expand Down Expand Up @@ -258,6 +264,7 @@ fn patch_types(space: &mut RustTypes) {
name: ty.name.clone(),
fields: ty.fields.iter().filter(|x| x.position == "xml").cloned().collect(),
doc: ty.doc.clone(),
s3_unwrapped_xml_output: false,
xml_name: None,
is_error_type: false,
};
Expand Down Expand Up @@ -297,6 +304,7 @@ fn unify_operation_types(ops: &Operations, space: &mut RustTypes) {
name: op.input.clone(),
fields: default(),
doc: None,
s3_unwrapped_xml_output: false,
xml_name: None,
is_error_type: false,
}
Expand All @@ -316,6 +324,7 @@ fn unify_operation_types(ops: &Operations, space: &mut RustTypes) {
name: op.output.clone(),
fields: default(),
doc: None,
s3_unwrapped_xml_output: false,
xml_name: None,
is_error_type: false,
}
Expand Down
4 changes: 4 additions & 0 deletions codegen/src/ops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ pub struct Operation {
pub smithy_input: String,
pub smithy_output: String,

pub s3_unwrapped_xml_output: bool,

pub doc: Option<String>,

pub http_method: String,
Expand Down Expand Up @@ -86,6 +88,8 @@ pub fn collect_operations(model: &smithy::Model) -> Operations {
smithy_input,
smithy_output,

s3_unwrapped_xml_output: sh.traits.s3_unwrapped_xml_output(),

doc: sh.traits.doc().map(o),

http_method: sh.traits.http_method().unwrap().to_owned(),
Expand Down
1 change: 1 addition & 0 deletions codegen/src/rust.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ pub struct Struct {
pub name: String,
pub fields: Vec<StructField>,
pub doc: Option<String>,
pub s3_unwrapped_xml_output: bool,

pub xml_name: Option<String>,
pub is_error_type: bool,
Expand Down
4 changes: 4 additions & 0 deletions codegen/src/smithy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,10 @@ impl Traits {
self.get("smithy.api#xmlFlattened").is_some()
}

pub fn s3_unwrapped_xml_output(&self) -> bool {
self.get("aws.customizations#s3UnwrappedXmlOutput").is_some()
}

pub fn http_label(&self) -> Option<&Value> {
self.get("smithy.api#httpLabel")
}
Expand Down
6 changes: 5 additions & 1 deletion codegen/src/xml.rs
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,11 @@ fn codegen_xml_ser(ops: &Operations, rust_types: &RustTypes) {
g!("fn serialize<W: Write>(&self, s: &mut Serializer<W>) -> SerResult {{");

let xml_name = ty.xml_name.as_deref().unwrap_or(ty.name.as_str());
g!("s.content(\"{xml_name}\", self)");
if ty.s3_unwrapped_xml_output {
g!("self.serialize_content(s)");
} else {
g!("s.content(\"{xml_name}\", self)");
}

g!("}}");
g!("}}");
Expand Down
2 changes: 1 addition & 1 deletion crates/s3s/src/xml/generated.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1999,7 +1999,7 @@ impl Serialize for GetBucketLifecycleConfigurationOutput {

impl Serialize for GetBucketLocationOutput {
fn serialize<W: Write>(&self, s: &mut Serializer<W>) -> SerResult {
s.content("LocationConstraint", self)
self.serialize_content(s)
}
}

Expand Down

0 comments on commit da2d01c

Please sign in to comment.