zeep
zeep copied to clipboard
Reserved Keywords in structure's field names
Excluding type, reserved keywords can be used as struct or field names due to the schema. Here is an example:
<!-- InvalidNames.xsd -->
<xsd:complexType name="InParams">
<xsd:annotation>
<xsd:documentation>Input parameters</xsd:documentation>
</xsd:annotation>
<xsd:sequence>
<xsd:element minOccurs="0" name="abif" type="wsct:WSTypeChar4">
<xsd:annotation>
<xsd:documentation>Field length: 4
</xsd:documentation>
</xsd:annotation>
</xsd:element>
<xsd:element minOccurs="0" name="type" type="wsct:WSTypeChar6">
<xsd:annotation>
<xsd:documentation>Field length: 6
</xsd:documentation>
</xsd:annotation>
</xsd:element>
<xsd:element minOccurs="0" name="as" type="wsct:WSTypeChar3">
<xsd:annotation>
<xsd:documentation>Field length: 3
</xsd:documentation>
</xsd:annotation>
</xsd:element>
</xsd:sequence>
</xsd:complexType>
And result:
pub struct InParams {
#[yaserde(rename = "if", prefix = "nsi2", default)]
pub if: Option<WstypeChar4>,
#[yaserde(rename = "type", prefix = "nsi2", default)]
pub rs_type: Option<WstypeChar6>,
#[yaserde(rename = "as", prefix = "nsi2", default)]
pub as: Option<WstypeChar3>,
}
I suggest expanding the name conversion logic. Currently, it is as follows:
fn shield_reserved_names<'a>(&self, type_name: &'a str) -> &'a str {
match type_name {
"type" => "rs_type",
other => other,
}
}
Instead of rs_type perhaps instead do r#type, so if => r#if?
The 0.2 release now includes alternatives for many reserved keywords:
pub fn rename_keywords(field_name: &str) -> &str {
match field_name {
"type" => "r#type",
"as" => "r#as",
"where" => "r#where",
"break" => "r#break",
"override" => "r#override",
"continue" => "r#continue",
"crate" => "r#crate",
"else" => "r#else",
"enum" => "r#enum",
"extern" => "r#extern",
"false" => "r#false",
"true" => "r#true",
"fn" => "r#fn",
"for" => "r#for",
"if" => "r#if",
"impl" => "r#impl",
"in" => "r#in",
"let" => "r#let",
"loop" => "r#loop",
"match" => "r#match",
"mod" => "r#mod",
"move" => "r#move",
"mut" => "r#mut",
"pub" => "r#pub",
"ref" => "r#ref",
"return" => "r#return",
"self" => "r#self",
_ => field_name,
}
}