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

Duplicate structs for xs:choice elements #138

Open
lnicola opened this issue Jan 25, 2022 · 1 comment
Open

Duplicate structs for xs:choice elements #138

lnicola opened this issue Jan 25, 2022 · 1 comment

Comments

@lnicola
Copy link

lnicola commented Jan 25, 2022

Given this snippet:

   <xs:complexType name="RightsController">
      <xs:annotation>
         <xs:documentation source="ddex:Definition">A ddex:Composite containing details of a ddex:RightsController. ddex:RightsControllers are typicallydescribed by ddex:Name, ddex:Identifier and role(s).</xs:documentation>
      </xs:annotation>
      <xs:sequence>
         <xs:choice>
            <xs:element name="PartyId" type="ddexC:PartyId">
               <xs:annotation>
                  <xs:documentation source="ddex:Definition">A ddex:Composite containing details of the ddex:PartyId for the ddex:Party. If no ddex:Namespace is given, the ddex:Identifier is a ddex:DdexPartyId (DPID). Note that DPIDs are not normally used to identify ddex:Artists, ddex:Producers or other ddex:Creators.</xs:documentation>
               </xs:annotation>
            </xs:element>
            <xs:sequence>
               <xs:element name="PartyName" maxOccurs="unbounded" type="ddexC:PartyName">
                  <xs:annotation>
                     <xs:documentation source="ddex:Definition">A ddex:Composite containing details of the PartyName(s).</xs:documentation>
                  </xs:annotation>
               </xs:element>
               <xs:element name="PartyId" minOccurs="0" type="ddexC:PartyId">
                  <xs:annotation>
                     <xs:documentation source="ddex:Definition">A ddex:Composite containing details of the ddex:PartyId for the ddex:Party. If no ddex:Namespace is given, the ddex:Identifier is a ddex:DdexPartyId (DPID). Note that DPIDs are not normally used to identify ddex:Artists, ddex:Producers or other ddex:Creators.</xs:documentation>
                  </xs:annotation>
               </xs:element>
            </xs:sequence>
         </xs:choice>
         <xs:element name="RightsControllerRole" minOccurs="0" maxOccurs="unbounded"
            type="ddex:RightsControllerRole">
            <xs:annotation>
               <xs:documentation source="ddex:Definition">A role that describes the ddex:Party involved in the administration of ddex:Rights.</xs:documentation>
            </xs:annotation>
         </xs:element>
         <xs:choice>
            <xs:element name="RightShareUnknown" type="xs:boolean">
               <xs:annotation>
                  <xs:documentation source="ddex:Definition">The ddex:Flag indicating whether the ddex:RightSharePercentage is unknown (=True) or not (=False).</xs:documentation>
               </xs:annotation>
            </xs:element>
            <xs:element name="RightSharePercentage" type="xs:string">
               <xs:annotation>
                  <xs:documentation source="ddex:Definition">The share of the licensed Rights owned by the ddexC:RightsController. ddex:RightShare information is given as a xs:decimal value (e.g. '0.125' represents 12.5%). If no information is given, 100% is assumed.</xs:documentation>
               </xs:annotation>
            </xs:element>
         </xs:choice>
         <xs:element name="RightsControllerType" minOccurs="0" type="ddex:RightsControllerType">
            <xs:annotation>
               <xs:documentation source="ddex:Definition">A type of the ddex:RightsController.</xs:documentation>
            </xs:annotation>
         </xs:element>
         <xs:element name="TerritoryOfRegistration" minOccurs="0" type="ddexC:TerritoryCode">
            <xs:annotation>
               <xs:documentation source="ddex:Definition">The country of registration (represented by an ISO 3166-1 iso3166a2:TerritoryCode).</xs:documentation>
            </xs:annotation>
         </xs:element>
         <xs:element name="StartDate" type="xs:date">
            <xs:annotation>
               <xs:documentation source="ddex:Definition">The Date that marks the beginning of the title (in ISO 8601:2004 format: YYYY-MM-DD). This cannot be a Date in the future.</xs:documentation>
            </xs:annotation>
         </xs:element>
         <xs:element name="EndDate" minOccurs="0" type="xs:date">
            <xs:annotation>
               <xs:documentation source="ddex:Definition">The Date that marks the end of the title (in ISO 8601:2004 format: YYYY-MM-DD).</xs:documentation>
            </xs:annotation>
         </xs:element>
      </xs:sequence>
      <xs:attribute name="SequenceNumber" type="xs:integer">
         <xs:annotation>
            <xs:documentation source="ddex:Definition">The number indicating the order of the ddexC:RightsController in a group of ddex:RightsControllers. This is represented in an XML schema as an XML ddex:Attribute. </xs:documentation>
         </xs:annotation>
      </xs:attribute>
   </xs:complexType>

I get:

// A ddex:Composite containing details of a ddex:RightsController.
// ddex:RightsControllers are typicallydescribed by ddex:Name, ddex:Identifier
// and role(s).
#[derive(Default, PartialEq, Debug, YaSerialize, YaDeserialize)]
#[yaserde(prefix = "ern", namespace = "ern: http://ddex.net/xml/ern/351")]
pub struct RightsController {
    #[yaserde(prefix = "ern", rename = "RightsControllerChoice")]
    pub rights_controller_choice: rights_controller::RightsControllerChoice,

    // A role that describes the ddex:Party involved in the administration of
    // ddex:Rights.
    #[yaserde(prefix = "ern", rename = "RightsControllerRole")]
    pub rights_controller_role: Vec<ddex::RightsControllerRole>,

    #[yaserde(prefix = "ern", rename = "RightsControllerChoice")]
    pub rights_controller_choice: rights_controller::RightsControllerChoice,

    // A type of the ddex:RightsController.
    #[yaserde(prefix = "ern", rename = "RightsControllerType")]
    pub rights_controller_type: Option<ddex::RightsControllerType>,

    // The country of registration (represented by an ISO 3166-1
    // iso3166a2:TerritoryCode).
    #[yaserde(prefix = "ern", rename = "TerritoryOfRegistration")]
    pub territory_of_registration: Option<ddexC::TerritoryCode>,

    // The Date that marks the beginning of the title (in ISO 8601:2004 format:
    // YYYY-MM-DD). This cannot be a Date in the future.
    #[yaserde(prefix = "ern", rename = "StartDate")]
    pub start_date: xs::Date,

    // The Date that marks the end of the title (in ISO 8601:2004 format:
    // YYYY-MM-DD).
    #[yaserde(prefix = "ern", rename = "EndDate")]
    pub end_date: Option<xs::Date>,

    // The number indicating the order of the ddexC:RightsController in a group
    // of ddex:RightsControllers. This is represented in an XML schema as an XML
    // ddex:Attribute.
    #[yaserde(attribute, rename = "SequenceNumber")]
    pub sequence_number: Option<xs::Integer>,
}

pub mod rights_controller {
    use super::*;

    #[derive(PartialEq, Debug, YaSerialize, YaDeserialize)]
    #[yaserde(prefix = "ern", namespace = "ern: http://ddex.net/xml/ern/351")]

    pub enum RightsControllerChoice {
        // A ddex:Composite containing details of the ddex:PartyId for the
        // ddex:Party. If no ddex:Namespace is given, the ddex:Identifier is a
        // ddex:DdexPartyId (DPID). Note that DPIDs are not normally used to
        // identify ddex:Artists, ddex:Producers or other ddex:Creators.
        PartyId(ddexC::PartyId),
        __Unknown__(String),
    }

    impl Default for RightsControllerChoice {
        fn default() -> RightsControllerChoice {
            Self::__Unknown__("No valid variants".into())
        }
    }

    impl Validate for RightsControllerChoice {}

    #[derive(PartialEq, Debug, YaSerialize, YaDeserialize)]
    #[yaserde(prefix = "ern", namespace = "ern: http://ddex.net/xml/ern/351")]

    pub enum RightsControllerChoice {
        // The ddex:Flag indicating whether the ddex:RightSharePercentage is unknown
        // (=True) or not (=False).
        RightShareUnknown(bool),
        // The share of the licensed Rights owned by the ddexC:RightsController.
        // ddex:RightShare information is given as a xs:decimal value (e.g. '0.125'
        // represents 12.5%). If no information is given, 100% is assumed.
        RightSharePercentage(String),
        __Unknown__(String),
    }

    impl Default for RightsControllerChoice {
        fn default() -> RightsControllerChoice {
            Self::__Unknown__("No valid variants".into())
        }
    }

    impl Validate for RightsControllerChoice {}
}

Note the two rights_controller_choice fields and two RightsControllerChoice structs.

@zhangjiayin
Copy link

+1
seev.001.001.02.xsd.zip

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants