Skip to content

Commit

Permalink
Upgrade roxmltree
Browse files Browse the repository at this point in the history
  • Loading branch information
DmitrySamoylov committed Apr 17, 2024
1 parent 23c3629 commit 07da98f
Show file tree
Hide file tree
Showing 9 changed files with 42 additions and 26 deletions.
13 changes: 2 additions & 11 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion wsdl-parser-cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@ path = "src/main.rs"
[dependencies]
anyhow = "1"
clap = { version = "4", features = ["derive"] }
roxmltree = { version = "0.14", features = ["std"] }
roxmltree = { version = "0.19", features = ["std"] }
wsdl-parser = { path = "../wsdl-parser" }
xsd-parser = { path = "../xsd-parser" }
2 changes: 1 addition & 1 deletion wsdl-parser/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ license = "MIT OR Apache-2.0"

[dependencies]
Inflector = "0.11"
roxmltree = "0.14"
roxmltree = "0.19"

[dev-dependencies]
syn = { version = "2", features = ["full", "extra-traits"] }
Expand Down
2 changes: 1 addition & 1 deletion wsdl-parser/src/parser/definitions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ pub struct Definitions<'a> {
impl<'a> Definitions<'a> {
pub fn target_namespace(&self) -> Option<&'a Namespace<'_>> {
match self.node().attribute(attribute::TARGET_NAMESPACE) {
Some(tn) => self.node().namespaces().iter().find(|a| a.uri() == tn),
Some(tn) => self.node().namespaces().find(|a| a.uri() == tn),
None => None,
}
}
Expand Down
2 changes: 1 addition & 1 deletion xsd-parser/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ license = "MIT OR Apache-2.0"

[dependencies]
Inflector = "0.11"
roxmltree = "0.14"
roxmltree = "0.19"

[dev-dependencies]
num-bigint = "0.4"
Expand Down
6 changes: 4 additions & 2 deletions xsd-parser/src/generator/default.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,10 @@ mod test {
)
.unwrap()
.root_element()
.namespaces()[0]
.clone(),
.namespaces()
.next()
.cloned()
.unwrap(),
);
assert_eq!(default_format_type("tt:Type", &ns), "Type");
assert_eq!(default_format_type("tt:TyName", &ns), "TyName");
Expand Down
6 changes: 4 additions & 2 deletions xsd-parser/src/generator/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -217,8 +217,10 @@ mod test {
)
.unwrap()
.root_element()
.namespaces()[0]
.clone(),
.namespaces()
.next()
.cloned()
.unwrap(),
);

let match_type = |name| match_built_in_type(name, &xsd_ns);
Expand Down
33 changes: 27 additions & 6 deletions xsd-parser/src/parser/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,18 @@ use crate::parser::{
};

pub fn parse_schema<'input>(schema: &Node<'_, 'input>) -> RsFile<'input> {
let mut xsd_namespaces = schema
.namespaces()
.filter(|namespace| namespace.uri() == "http://www.w3.org/2001/XMLSchema");

RsFile {
name: "".into(),
namespace: None,
target_ns: target_namespace(schema).cloned(),
xsd_ns: schema
.namespaces()
.iter()
.rev()
.find(|a| a.uri() == "http://www.w3.org/2001/XMLSchema")
xsd_ns: xsd_namespaces
.clone()
.find(|namespace| namespace.name().is_some())
.or_else(|| xsd_namespaces.next())
.cloned(),
types: schema
.children()
Expand All @@ -39,6 +42,24 @@ pub fn parse_schema<'input>(schema: &Node<'_, 'input>) -> RsFile<'input> {
mod test {
use crate::parser::schema::parse_schema;

#[test]
fn test_single_xsd_ns() {
let doc = roxmltree::Document::parse(
r#"
<xs:schema
xmlns:tt="http://www.onvif.org/ver10/schema"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://www.onvif.org/ver10/schema"
>
</xs:schema>
"#,
)
.unwrap();

let res = parse_schema(&doc.root_element());
assert_eq!(res.xsd_ns.unwrap().name().unwrap(), "xs");
}

#[test]
fn test_multiple_xsd_ns() {
let doc = roxmltree::Document::parse(
Expand All @@ -56,6 +77,6 @@ mod test {
.unwrap();

let res = parse_schema(&doc.root_element());
assert_eq!(res.xsd_ns.unwrap().name().unwrap(), "xsd");
assert_eq!(res.xsd_ns.unwrap().name().unwrap(), "xs");
}
}
2 changes: 1 addition & 1 deletion xsd-parser/src/parser/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use crate::parser::{

pub fn target_namespace<'a, 'input>(node: &Node<'a, 'input>) -> Option<&'a Namespace<'input>> {
match node.attribute(attribute::TARGET_NAMESPACE) {
Some(tn) => node.namespaces().iter().find(|a| a.uri() == tn),
Some(tn) => node.namespaces().find(|a| a.uri() == tn),
None => None,
}
}
Expand Down

0 comments on commit 07da98f

Please sign in to comment.