Loading codegen/src/ops.rs +10 −0 Original line number Diff line number Diff line Loading @@ -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, Loading Loading @@ -77,6 +79,12 @@ pub fn collect_operations(model: &smithy::Model) -> Operations { smithy_http_code }; // https://smithy.io/2.0/aws/customizations/s3-customizations.html // https://github.com/Nugine/s3s/pull/127 if sh.traits.s3_unwrapped_xml_output() { assert_eq!(op_name, "GetBucketLocation"); } let op = Operation { name: op_name.clone(), Loading @@ -86,6 +94,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(), Loading codegen/src/smithy.rs +4 −0 Original line number Diff line number Diff line Loading @@ -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") } Loading codegen/src/xml.rs +8 −1 Original line number Diff line number Diff line Loading @@ -154,8 +154,15 @@ fn codegen_xml_ser(ops: &Operations, rust_types: &RustTypes) { g!("s.timestamp(\"{}\", &self.{}, TimestampFormat::{})?;", xml_name, field.name, fmt); } } else if field.option_type { let s3_unwrapped_xml_output = ops.iter().any(|(_, op)| op.s3_unwrapped_xml_output && op.output == ty.name); g!("if let Some(ref val) = self.{} {{", field.name); if s3_unwrapped_xml_output { g!("val.serialize_content(s)?;"); } else { g!("s.content(\"{xml_name}\", val)?;"); } g!("}}"); } else { let default_is_zero = match field.default_value.as_ref() { Loading crates/s3s/src/xml/generated.rs +1 −1 Original line number Diff line number Diff line Loading @@ -505,7 +505,7 @@ impl SerializeContent for GetBucketLifecycleConfigurationOutput { impl SerializeContent for GetBucketLocationOutput { fn serialize_content<W: Write>(&self, s: &mut Serializer<W>) -> SerResult { if let Some(ref val) = self.location_constraint { s.content("LocationConstraint", val)?; val.serialize_content(s)?; } Ok(()) } Loading crates/s3s/src/xml/tests.rs +34 −0 Original line number Diff line number Diff line Loading @@ -19,6 +19,15 @@ fn serialize_content<T: xml::SerializeContent>(val: &T) -> xml::SerResult<String Ok(String::from_utf8(buf).unwrap()) } fn serialize<T: xml::Serialize>(val: &T) -> xml::SerResult<String> { let mut buf = Vec::with_capacity(256); { let mut ser = xml::Serializer::new(&mut buf); val.serialize(&mut ser)?; } Ok(String::from_utf8(buf).unwrap()) } /// See <https://github.com/Nugine/s3s/issues/2> #[test] fn d001() { Loading Loading @@ -146,3 +155,28 @@ fn s001() { assert_eq!(ans, expected); } #[test] fn s002() { { let us_west_2 = crate::dto::BucketLocationConstraint::from_static(crate::dto::BucketLocationConstraint::US_WEST_2); let val = crate::dto::GetBucketLocationOutput { location_constraint: Some(us_west_2), }; let ans = serialize(&val).unwrap(); let expected = "<LocationConstraint>us-west-2</LocationConstraint>"; assert_eq!(ans, expected); } { let val = crate::dto::GetBucketLocationOutput { location_constraint: None, }; let ans = serialize(&val).unwrap(); let expected = "<LocationConstraint></LocationConstraint>"; assert_eq!(ans, expected); } } Loading
codegen/src/ops.rs +10 −0 Original line number Diff line number Diff line Loading @@ -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, Loading Loading @@ -77,6 +79,12 @@ pub fn collect_operations(model: &smithy::Model) -> Operations { smithy_http_code }; // https://smithy.io/2.0/aws/customizations/s3-customizations.html // https://github.com/Nugine/s3s/pull/127 if sh.traits.s3_unwrapped_xml_output() { assert_eq!(op_name, "GetBucketLocation"); } let op = Operation { name: op_name.clone(), Loading @@ -86,6 +94,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(), Loading
codegen/src/smithy.rs +4 −0 Original line number Diff line number Diff line Loading @@ -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") } Loading
codegen/src/xml.rs +8 −1 Original line number Diff line number Diff line Loading @@ -154,8 +154,15 @@ fn codegen_xml_ser(ops: &Operations, rust_types: &RustTypes) { g!("s.timestamp(\"{}\", &self.{}, TimestampFormat::{})?;", xml_name, field.name, fmt); } } else if field.option_type { let s3_unwrapped_xml_output = ops.iter().any(|(_, op)| op.s3_unwrapped_xml_output && op.output == ty.name); g!("if let Some(ref val) = self.{} {{", field.name); if s3_unwrapped_xml_output { g!("val.serialize_content(s)?;"); } else { g!("s.content(\"{xml_name}\", val)?;"); } g!("}}"); } else { let default_is_zero = match field.default_value.as_ref() { Loading
crates/s3s/src/xml/generated.rs +1 −1 Original line number Diff line number Diff line Loading @@ -505,7 +505,7 @@ impl SerializeContent for GetBucketLifecycleConfigurationOutput { impl SerializeContent for GetBucketLocationOutput { fn serialize_content<W: Write>(&self, s: &mut Serializer<W>) -> SerResult { if let Some(ref val) = self.location_constraint { s.content("LocationConstraint", val)?; val.serialize_content(s)?; } Ok(()) } Loading
crates/s3s/src/xml/tests.rs +34 −0 Original line number Diff line number Diff line Loading @@ -19,6 +19,15 @@ fn serialize_content<T: xml::SerializeContent>(val: &T) -> xml::SerResult<String Ok(String::from_utf8(buf).unwrap()) } fn serialize<T: xml::Serialize>(val: &T) -> xml::SerResult<String> { let mut buf = Vec::with_capacity(256); { let mut ser = xml::Serializer::new(&mut buf); val.serialize(&mut ser)?; } Ok(String::from_utf8(buf).unwrap()) } /// See <https://github.com/Nugine/s3s/issues/2> #[test] fn d001() { Loading Loading @@ -146,3 +155,28 @@ fn s001() { assert_eq!(ans, expected); } #[test] fn s002() { { let us_west_2 = crate::dto::BucketLocationConstraint::from_static(crate::dto::BucketLocationConstraint::US_WEST_2); let val = crate::dto::GetBucketLocationOutput { location_constraint: Some(us_west_2), }; let ans = serialize(&val).unwrap(); let expected = "<LocationConstraint>us-west-2</LocationConstraint>"; assert_eq!(ans, expected); } { let val = crate::dto::GetBucketLocationOutput { location_constraint: None, }; let ans = serialize(&val).unwrap(); let expected = "<LocationConstraint></LocationConstraint>"; assert_eq!(ans, expected); } }