Unverified Commit cfd35609 authored by Nugine's avatar Nugine
Browse files

codegen: xml: de: member_xml_name

parent 6ff81b3b
Loading
Loading
Loading
Loading
+3 −1
Original line number Diff line number Diff line
@@ -331,8 +331,10 @@ fn codegen_xml_de(ops: &Operations, rust_types: &RustTypes, g: &mut Codegen) {
                                g.ln(f!("let ans: {} = d.content()?;", list_ty.member.type_));
                                g.ln(f!("{field_name}.get_or_insert_with(List::new).push(ans);"));
                            } else {
                                let member_xml_name = list_ty.member.xml_name.as_deref().unwrap();

                                g.ln(f!("if {field_name}.is_some() {{ return Err(DeError::DuplicateField); }}"));
                                g.ln(f!("{field_name} = Some(d.list_content(\"member\")?);"));
                                g.ln(f!("{field_name} = Some(d.list_content(\"{member_xml_name}\")?);"));
                            }
                        } else if let rust::Type::Timestamp(ts_ty) = field_type {
                            let fmt = ts_ty.format.as_deref().unwrap_or("DateTime");
+13 −6
Original line number Diff line number Diff line
@@ -23,10 +23,8 @@ where
/// See <https://github.com/Nugine/s3s/issues/2>
#[test]
fn d001() {
    use crate::dto::CompletedMultipartUpload;

    let input = read(concat!(DATA_DIR, "/d001.xml"));
    let ans = deserialize::<CompletedMultipartUpload>(&input).unwrap();
    let ans = deserialize::<crate::dto::CompletedMultipartUpload>(&input).unwrap();

    let parts = ans.parts.as_deref().unwrap();
    assert_eq!(parts.len(), 3);
@@ -43,13 +41,22 @@ fn d001() {

#[test]
fn d002() {
    use crate::dto::SelectObjectContentRequest;

    let input = read(concat!(DATA_DIR, "/d002.xml"));
    let ans = deserialize::<SelectObjectContentRequest>(&input).unwrap();
    let ans = deserialize::<crate::dto::SelectObjectContentRequest>(&input).unwrap();

    {
        let csv = ans.input_serialization.csv.as_ref().unwrap();
        assert_eq!(csv.allow_quoted_record_delimiter, false);
    }
}

#[test]
fn d003() {
    let input = read(concat!(DATA_DIR, "/d003.xml"));
    let ans = deserialize::<crate::dto::Tagging>(&input).unwrap();

    assert_eq!(ans.tag_set.len(), 1);
    let tag = &ans.tag_set[0];
    assert_eq!(tag.key, "Key4");
    assert_eq!(tag.value, "Value4");
}
+8 −0
Original line number Diff line number Diff line
<Tagging xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
    <TagSet>
        <Tag>
            <Key>Key4</Key>
            <Value>Value4</Value>
        </Tag>
    </TagSet>
</Tagging>
 No newline at end of file
+7 −7
Original line number Diff line number Diff line
@@ -2220,7 +2220,7 @@ impl<'xml> DeserializeContent<'xml> for AccessControlPolicy {
                if grants.is_some() {
                    return Err(DeError::DuplicateField);
                }
                grants = Some(d.list_content("member")?);
                grants = Some(d.list_content("Grant")?);
                Ok(())
            }
            b"Owner" => {
@@ -3423,7 +3423,7 @@ impl<'xml> DeserializeContent<'xml> for InventoryConfiguration {
                if optional_fields.is_some() {
                    return Err(DeError::DuplicateField);
                }
                optional_fields = Some(d.list_content("member")?);
                optional_fields = Some(d.list_content("Field")?);
                Ok(())
            }
            b"Schedule" => {
@@ -3890,7 +3890,7 @@ impl<'xml> DeserializeContent<'xml> for LoggingEnabled {
                if target_grants.is_some() {
                    return Err(DeError::DuplicateField);
                }
                target_grants = Some(d.list_content("member")?);
                target_grants = Some(d.list_content("Grant")?);
                Ok(())
            }
            b"TargetPrefix" => {
@@ -5076,7 +5076,7 @@ impl<'xml> DeserializeContent<'xml> for S3Location {
                if access_control_list.is_some() {
                    return Err(DeError::DuplicateField);
                }
                access_control_list = Some(d.list_content("member")?);
                access_control_list = Some(d.list_content("Grant")?);
                Ok(())
            }
            b"BucketName" => {
@@ -5125,7 +5125,7 @@ impl<'xml> DeserializeContent<'xml> for S3Location {
                if user_metadata.is_some() {
                    return Err(DeError::DuplicateField);
                }
                user_metadata = Some(d.list_content("member")?);
                user_metadata = Some(d.list_content("MetadataEntry")?);
                Ok(())
            }
            _ => Err(DeError::UnexpectedTagName),
@@ -5568,7 +5568,7 @@ impl<'xml> DeserializeContent<'xml> for Tagging {
                if tag_set.is_some() {
                    return Err(DeError::DuplicateField);
                }
                tag_set = Some(d.list_content("member")?);
                tag_set = Some(d.list_content("Tag")?);
                Ok(())
            }
            _ => Err(DeError::UnexpectedTagName),
@@ -5788,7 +5788,7 @@ impl<'xml> DeserializeContent<'xml> for WebsiteConfiguration {
                if routing_rules.is_some() {
                    return Err(DeError::DuplicateField);
                }
                routing_rules = Some(d.list_content("member")?);
                routing_rules = Some(d.list_content("RoutingRule")?);
                Ok(())
            }
            _ => Err(DeError::UnexpectedTagName),
+1 −0
Original line number Diff line number Diff line
@@ -63,3 +63,4 @@ if __name__ == "__main__":

    # TODO: pass more tests
    assert counts["s3cmd"]["fail"] == 0
    assert counts["aws-sdk-go"]["fail"] == 0