Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exclude namespace from tag name when comparing against field names #702

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

leftmostcat
Copy link

@leftmostcat leftmostcat commented Jan 10, 2024

Attempting to deserialize the following snippet to the following struct fails with "missing field $value" due to not_in() depending on the full name of the tag rather than the local name. This makes it impossible (or at least very difficult) to deserialize xs:choice values when they have a namespace prefix. Relying on local name addresses this without causing any noticeable complications.

              <t:FolderId Id="Zm9vYmFyCg==" ChangeKey="AQAAAA=="/>
              <t:ParentFolderId Id="Zm9vCg==" ChangeKey="AQAAAA=="/>
              <t:FolderClass>IPF.Note</t:FolderClass>
              <t:DisplayName>Inbox</t:DisplayName>
              <t:TotalCount>48</t:TotalCount>
              <t:ChildFolderCount>0</t:ChildFolderCount>
              <t:UnreadCount>46</t:UnreadCount>
#[derive(Debug, Deserialize)]
#[serde(rename_all = "PascalCase")]
pub struct FolderInner {
    pub folder_id: BaseFolderId,
    pub parent_folder_id: Option<ParentFolderId>,
    pub folder_class: Option<String>,
    pub display_name: Option<String>,
    total_count: Option<u32>,
    child_folder_count: Option<u32>,
    unread_count: Option<u32>,
}

#[derive(Debug, Deserialize)]
pub enum BaseFolderId {
    FolderId(FolderId),

    ...
}

#[derive(Debug, Deserialize)]
pub struct FolderId {
    #[serde(rename = "@Id")]
    pub id: String,

    #[serde(rename = "@ChangeKey")]
    pub change_key: Option<String>,
}

@leftmostcat
Copy link
Author

This seems to address #683.

@Mingun Mingun added serde Issues related to mapping from Rust types to XML namespaces Issues related to namespaces support labels Jan 11, 2024
@codecov-commenter
Copy link

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (de61fa1) 65.06% compared to head (a79f473) 65.32%.

❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #702      +/-   ##
==========================================
+ Coverage   65.06%   65.32%   +0.25%     
==========================================
  Files          38       38              
  Lines       17954    18127     +173     
==========================================
+ Hits        11682    11841     +159     
- Misses       6272     6286      +14     
Flag Coverage Δ
unittests 65.32% <100.00%> (+0.25%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@Mingun
Copy link
Collaborator

Mingun commented Jan 11, 2024

I would like to:

  1. have tests for that, at least this one in serde-issues.rs:
    /// Regression test for https://github.com/tafia/quick-xml/issues/683.
    #[test]
    fn issue683() {
        #[derive(Deserialize, Debug, PartialEq)]
        enum ScheduleLocation {
            #[serde(rename = "DT")]
            Destination,
        }
    
        #[derive(Deserialize, Debug, PartialEq)]
        #[allow(non_snake_case)]
        struct Schedule {
            cancelReason: Option<u32>,
            #[serde(rename = "$value")]
            locations: Vec<ScheduleLocation>,
        }
        let xml = r#"
            <schedule xmlns:ns2="http://www.thalesgroup.com/rtti/PushPort/Schedules/v3">
                <ns2:DT/>
                <ns2:cancelReason>918</ns2:cancelReason>
            </schedule>"#;
        let result = quick_xml::de::from_str::<Schedule>(xml);
        dbg!(&result);
        assert_eq!(
            result.unwrap(),
            Schedule {
                cancelReason: Some(918),
                locations: vec![ScheduleLocation::Destination],
            }
        );
    }
  2. Have any other tests which could be affected by this change (I think, in new tests/serde-namespaces.rs file)
  3. Have a changelog entry

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
namespaces Issues related to namespaces support serde Issues related to mapping from Rust types to XML
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Repeated choice plus other field
3 participants