lumeohq / xsd-parser-rs

A xsd/wsdl => rust code generator written in rust
Apache License 2.0
96 stars 34 forks source link

Support enumerations with tricky values #32

Closed victor-soloviev closed 4 years ago

victor-soloviev commented 4 years ago

Enumerations may have values with punctuation within it. Currently, the following XSD

<xs:simpleType name="RelationshipType">
  <xs:restriction base="xs:anyURI">
     <xs:enumeration value="http://www.w3.org/2005/08/addressing/reply"/>
  </xs:restriction>
</xs:simpleType>

translates to

#[derive(PartialEq, Debug, YaSerialize, YaDeserialize)]
pub enum RelationshipType {
   http::WwwW3Org200508AddressingReply,
__Unknown__(String)
}

We should eather escape punctuation characters or store enumeration as strings with a value validation.

LeonidKrutovsky commented 4 years ago

The problem with these names is easy to solve. But there is a problem with namespaces: they can be imported under aliases.

 <xs:restriction base="xs:QName">
   <xs:enumeration value="tns:DataEncodingUnknown"/>
   <xs:enumeration value="tns:MustUnderstand"/>
   <xs:enumeration value="tns:Receiver"/>
   <xs:enumeration value="tns:Sender"/>
   <xs:enumeration value="tns:VersionMismatch"/>
 </xs:restriction>

godgen output:

#[derive(PartialEq, Debug, YaSerialize, YaDeserialize)]
pub enum FaultcodeEnum {
   #[yaserde(rename = "tns:DataEncodingUnknown")]
   DataEncodingUnknown,
   #[yaserde(rename = "tns:MustUnderstand")]
   MustUnderstand,
   #[yaserde(rename = "tns:Receiver")]
   Receiver,
   #[yaserde(rename = "tns:Sender")]
   Sender,
   #[yaserde(rename = "tns:VersionMismatch")]
   VersionMismatch,
   __Unknown__(String),
}

but 'tns' namespace could import as 's', for example:

<s:Fault>
   <s:Code>
       <s:Value>s:Sender</s:Value>
       <s:Subcode>
           <s:Value>ter:NotAuthorized</s:Value>
       </s:Subcode>
   </s:Code>
   <s:Reason>
       <s:Text xml:lang="en">Sender not Authorized</s:Text>
   </s:Reason>
</s:Fault>

We can't just compare lines, we can't just set a line in "rename" and we can't validate it like

available_values.contains(&current_value)