polyxml 0.42.0__tar.gz → 0.43.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {polyxml-0.42.0 → polyxml-0.43.0}/Cargo.lock +6 -6
- {polyxml-0.42.0 → polyxml-0.43.0}/Cargo.toml +1 -1
- {polyxml-0.42.0 → polyxml-0.43.0}/PKG-INFO +1 -1
- {polyxml-0.42.0 → polyxml-0.43.0}/crates/polyxml-core/src/schema.rs +110 -51
- {polyxml-0.42.0 → polyxml-0.43.0}/crates/polyxml-core/tests/test_transcoder.rs +77 -0
- {polyxml-0.42.0 → polyxml-0.43.0}/pyproject.toml +1 -1
- {polyxml-0.42.0 → polyxml-0.43.0}/README.md +0 -0
- {polyxml-0.42.0 → polyxml-0.43.0}/crates/polyxml-core/Cargo.toml +0 -0
- {polyxml-0.42.0 → polyxml-0.43.0}/crates/polyxml-core/README.md +0 -0
- {polyxml-0.42.0 → polyxml-0.43.0}/crates/polyxml-core/benches/core_benchmarks.rs +0 -0
- {polyxml-0.42.0 → polyxml-0.43.0}/crates/polyxml-core/benches/support/tag_dispatch_fixtures.rs +0 -0
- {polyxml-0.42.0 → polyxml-0.43.0}/crates/polyxml-core/benches/tag_dispatch.rs +0 -0
- {polyxml-0.42.0 → polyxml-0.43.0}/crates/polyxml-core/src/codegen/cpp/codec.rs +0 -0
- {polyxml-0.42.0 → polyxml-0.43.0}/crates/polyxml-core/src/codegen/cpp/mod.rs +0 -0
- {polyxml-0.42.0 → polyxml-0.43.0}/crates/polyxml-core/src/codegen/csharp/mod.rs +0 -0
- {polyxml-0.42.0 → polyxml-0.43.0}/crates/polyxml-core/src/codegen/go/mod.rs +0 -0
- {polyxml-0.42.0 → polyxml-0.43.0}/crates/polyxml-core/src/codegen/java/codec.rs +0 -0
- {polyxml-0.42.0 → polyxml-0.43.0}/crates/polyxml-core/src/codegen/java/mod.rs +0 -0
- {polyxml-0.42.0 → polyxml-0.43.0}/crates/polyxml-core/src/codegen/java/models.rs +0 -0
- {polyxml-0.42.0 → polyxml-0.43.0}/crates/polyxml-core/src/codegen/mod.rs +0 -0
- {polyxml-0.42.0 → polyxml-0.43.0}/crates/polyxml-core/src/codegen/python/aot.rs +0 -0
- {polyxml-0.42.0 → polyxml-0.43.0}/crates/polyxml-core/src/codegen/python/mod.rs +0 -0
- {polyxml-0.42.0 → polyxml-0.43.0}/crates/polyxml-core/src/codegen/rust/mod.rs +0 -0
- {polyxml-0.42.0 → polyxml-0.43.0}/crates/polyxml-core/src/codegen/typescript/codec.rs +0 -0
- {polyxml-0.42.0 → polyxml-0.43.0}/crates/polyxml-core/src/codegen/typescript/mod.rs +0 -0
- {polyxml-0.42.0 → polyxml-0.43.0}/crates/polyxml-core/src/converters.rs +0 -0
- {polyxml-0.42.0 → polyxml-0.43.0}/crates/polyxml-core/src/error.rs +0 -0
- {polyxml-0.42.0 → polyxml-0.43.0}/crates/polyxml-core/src/integer.rs +0 -0
- {polyxml-0.42.0 → polyxml-0.43.0}/crates/polyxml-core/src/ir/chunker.rs +0 -0
- {polyxml-0.42.0 → polyxml-0.43.0}/crates/polyxml-core/src/ir/mod.rs +0 -0
- {polyxml-0.42.0 → polyxml-0.43.0}/crates/polyxml-core/src/ir/particle.rs +0 -0
- {polyxml-0.42.0 → polyxml-0.43.0}/crates/polyxml-core/src/ir/tarjan.rs +0 -0
- {polyxml-0.42.0 → polyxml-0.43.0}/crates/polyxml-core/src/json.rs +0 -0
- {polyxml-0.42.0 → polyxml-0.43.0}/crates/polyxml-core/src/lib.rs +0 -0
- {polyxml-0.42.0 → polyxml-0.43.0}/crates/polyxml-core/src/parser.rs +0 -0
- {polyxml-0.42.0 → polyxml-0.43.0}/crates/polyxml-core/src/pattern.rs +0 -0
- {polyxml-0.42.0 → polyxml-0.43.0}/crates/polyxml-core/src/schema_parser/mod.rs +0 -0
- {polyxml-0.42.0 → polyxml-0.43.0}/crates/polyxml-core/src/schema_parser/upa.rs +0 -0
- {polyxml-0.42.0 → polyxml-0.43.0}/crates/polyxml-core/src/serializer.rs +0 -0
- {polyxml-0.42.0 → polyxml-0.43.0}/crates/polyxml-core/src/transcoder.rs +0 -0
- {polyxml-0.42.0 → polyxml-0.43.0}/crates/polyxml-core/src/value.rs +0 -0
- {polyxml-0.42.0 → polyxml-0.43.0}/crates/polyxml-core/tests/fixtures/lexical_union.xsd +0 -0
- {polyxml-0.42.0 → polyxml-0.43.0}/crates/polyxml-core/tests/fixtures/mixed_content.xsd +0 -0
- {polyxml-0.42.0 → polyxml-0.43.0}/crates/polyxml-core/tests/fixtures/ts_mixed_content_inheritance.xsd +0 -0
- {polyxml-0.42.0 → polyxml-0.43.0}/crates/polyxml-core/tests/test_adversarial_identifiers.rs +0 -0
- {polyxml-0.42.0 → polyxml-0.43.0}/crates/polyxml-core/tests/test_any_attribute.rs +0 -0
- {polyxml-0.42.0 → polyxml-0.43.0}/crates/polyxml-core/tests/test_any_element.rs +0 -0
- {polyxml-0.42.0 → polyxml-0.43.0}/crates/polyxml-core/tests/test_conformance.rs +0 -0
- {polyxml-0.42.0 → polyxml-0.43.0}/crates/polyxml-core/tests/test_core.rs +0 -0
- {polyxml-0.42.0 → polyxml-0.43.0}/crates/polyxml-core/tests/test_corpus_regressions.rs +0 -0
- {polyxml-0.42.0 → polyxml-0.43.0}/crates/polyxml-core/tests/test_cpp_codegen.rs +0 -0
- {polyxml-0.42.0 → polyxml-0.43.0}/crates/polyxml-core/tests/test_csharp_codegen.rs +0 -0
- {polyxml-0.42.0 → polyxml-0.43.0}/crates/polyxml-core/tests/test_default_literal_codegen.rs +0 -0
- {polyxml-0.42.0 → polyxml-0.43.0}/crates/polyxml-core/tests/test_enum_literal_codegen.rs +0 -0
- {polyxml-0.42.0 → polyxml-0.43.0}/crates/polyxml-core/tests/test_escaped_enum_and_nil_mixed.rs +0 -0
- {polyxml-0.42.0 → polyxml-0.43.0}/crates/polyxml-core/tests/test_go_codegen.rs +0 -0
- {polyxml-0.42.0 → polyxml-0.43.0}/crates/polyxml-core/tests/test_inherited_simple_content.rs +0 -0
- {polyxml-0.42.0 → polyxml-0.43.0}/crates/polyxml-core/tests/test_inherited_text_codegen.rs +0 -0
- {polyxml-0.42.0 → polyxml-0.43.0}/crates/polyxml-core/tests/test_java_codegen.rs +0 -0
- {polyxml-0.42.0 → polyxml-0.43.0}/crates/polyxml-core/tests/test_json.rs +0 -0
- {polyxml-0.42.0 → polyxml-0.43.0}/crates/polyxml-core/tests/test_lexical_lists.rs +0 -0
- {polyxml-0.42.0 → polyxml-0.43.0}/crates/polyxml-core/tests/test_lexical_union_codegen.rs +0 -0
- {polyxml-0.42.0 → polyxml-0.43.0}/crates/polyxml-core/tests/test_mixed_branch_lookup.rs +0 -0
- {polyxml-0.42.0 → polyxml-0.43.0}/crates/polyxml-core/tests/test_mixed_content.rs +0 -0
- {polyxml-0.42.0 → polyxml-0.43.0}/crates/polyxml-core/tests/test_mixed_nil.rs +0 -0
- {polyxml-0.42.0 → polyxml-0.43.0}/crates/polyxml-core/tests/test_namespace_entities.rs +0 -0
- {polyxml-0.42.0 → polyxml-0.43.0}/crates/polyxml-core/tests/test_pattern_codegen.rs +0 -0
- {polyxml-0.42.0 → polyxml-0.43.0}/crates/polyxml-core/tests/test_python_codegen.rs +0 -0
- {polyxml-0.42.0 → polyxml-0.43.0}/crates/polyxml-core/tests/test_qualified_attributes.rs +0 -0
- {polyxml-0.42.0 → polyxml-0.43.0}/crates/polyxml-core/tests/test_runtime_fast_paths.rs +0 -0
- {polyxml-0.42.0 → polyxml-0.43.0}/crates/polyxml-core/tests/test_rust_codecs.rs +0 -0
- {polyxml-0.42.0 → polyxml-0.43.0}/crates/polyxml-core/tests/test_rust_codegen.rs +0 -0
- {polyxml-0.42.0 → polyxml-0.43.0}/crates/polyxml-core/tests/test_schema_attribute_entities.rs +0 -0
- {polyxml-0.42.0 → polyxml-0.43.0}/crates/polyxml-core/tests/test_schema_audit.rs +0 -0
- {polyxml-0.42.0 → polyxml-0.43.0}/crates/polyxml-core/tests/test_schema_ir.rs +0 -0
- {polyxml-0.42.0 → polyxml-0.43.0}/crates/polyxml-core/tests/test_schema_resolution.rs +0 -0
- {polyxml-0.42.0 → polyxml-0.43.0}/crates/polyxml-core/tests/test_security.rs +0 -0
- {polyxml-0.42.0 → polyxml-0.43.0}/crates/polyxml-core/tests/test_temporal_union.rs +0 -0
- {polyxml-0.42.0 → polyxml-0.43.0}/crates/polyxml-core/tests/test_ts_codegen.rs +0 -0
- {polyxml-0.42.0 → polyxml-0.43.0}/crates/polyxml-core/tests/test_ubl_csharp.rs +0 -0
- {polyxml-0.42.0 → polyxml-0.43.0}/crates/polyxml-core/tests/test_unbounded_choice.rs +0 -0
- {polyxml-0.42.0 → polyxml-0.43.0}/crates/polyxml-core/tests/test_upa.rs +0 -0
- {polyxml-0.42.0 → polyxml-0.43.0}/crates/polyxml-core/tests/test_value_constraints.rs +0 -0
- {polyxml-0.42.0 → polyxml-0.43.0}/crates/polyxml-core/tests/test_variant_registry.rs +0 -0
- {polyxml-0.42.0 → polyxml-0.43.0}/crates/polyxml-core/tests/test_xsi_type.rs +0 -0
- {polyxml-0.42.0 → polyxml-0.43.0}/crates/polyxml-python/Cargo.toml +0 -0
- {polyxml-0.42.0 → polyxml-0.43.0}/crates/polyxml-python/README.md +0 -0
- {polyxml-0.42.0 → polyxml-0.43.0}/crates/polyxml-python/benches/aot_vs_dataclass.py +0 -0
- {polyxml-0.42.0 → polyxml-0.43.0}/crates/polyxml-python/src/lib.rs +0 -0
- {polyxml-0.42.0 → polyxml-0.43.0}/crates/polyxml-python/tests/test_binary_fields.py +0 -0
- {polyxml-0.42.0 → polyxml-0.43.0}/crates/polyxml-python/tests/test_conformance.py +0 -0
- {polyxml-0.42.0 → polyxml-0.43.0}/crates/polyxml-python/tests/test_generated_models.py +0 -0
- {polyxml-0.42.0 → polyxml-0.43.0}/crates/polyxml-python/tests/test_json.py +0 -0
- {polyxml-0.42.0 → polyxml-0.43.0}/crates/polyxml-python/tests/test_mixed_content.py +0 -0
- {polyxml-0.42.0 → polyxml-0.43.0}/crates/polyxml-python/tests/test_polyxml.py +0 -0
- {polyxml-0.42.0 → polyxml-0.43.0}/crates/polyxml-python/tests/test_xsi_type.py +0 -0
- {polyxml-0.42.0 → polyxml-0.43.0}/python/polyxml/AGENT_GUIDE.md +0 -0
- {polyxml-0.42.0 → polyxml-0.43.0}/python/polyxml/__init__.py +0 -0
- {polyxml-0.42.0 → polyxml-0.43.0}/python/polyxml/compat/__init__.py +0 -0
- {polyxml-0.42.0 → polyxml-0.43.0}/python/polyxml/compat/xsdata.py +0 -0
- {polyxml-0.42.0 → polyxml-0.43.0}/python/polyxml/py.typed +0 -0
|
@@ -610,7 +610,7 @@ dependencies = [
|
|
|
610
610
|
|
|
611
611
|
[[package]]
|
|
612
612
|
name = "polyxml"
|
|
613
|
-
version = "0.
|
|
613
|
+
version = "0.43.0"
|
|
614
614
|
dependencies = [
|
|
615
615
|
"criterion",
|
|
616
616
|
"heck",
|
|
@@ -631,14 +631,14 @@ dependencies = [
|
|
|
631
631
|
|
|
632
632
|
[[package]]
|
|
633
633
|
name = "polyxml-c"
|
|
634
|
-
version = "0.
|
|
634
|
+
version = "0.43.0"
|
|
635
635
|
dependencies = [
|
|
636
636
|
"polyxml",
|
|
637
637
|
]
|
|
638
638
|
|
|
639
639
|
[[package]]
|
|
640
640
|
name = "polyxml-cli"
|
|
641
|
-
version = "0.
|
|
641
|
+
version = "0.43.0"
|
|
642
642
|
dependencies = [
|
|
643
643
|
"clap",
|
|
644
644
|
"glob",
|
|
@@ -652,7 +652,7 @@ dependencies = [
|
|
|
652
652
|
|
|
653
653
|
[[package]]
|
|
654
654
|
name = "polyxml-js"
|
|
655
|
-
version = "0.
|
|
655
|
+
version = "0.43.0"
|
|
656
656
|
dependencies = [
|
|
657
657
|
"napi",
|
|
658
658
|
"napi-build",
|
|
@@ -662,7 +662,7 @@ dependencies = [
|
|
|
662
662
|
|
|
663
663
|
[[package]]
|
|
664
664
|
name = "polyxml-python"
|
|
665
|
-
version = "0.
|
|
665
|
+
version = "0.43.0"
|
|
666
666
|
dependencies = [
|
|
667
667
|
"base64",
|
|
668
668
|
"hex",
|
|
@@ -674,7 +674,7 @@ dependencies = [
|
|
|
674
674
|
|
|
675
675
|
[[package]]
|
|
676
676
|
name = "polyxml-wasm"
|
|
677
|
-
version = "0.
|
|
677
|
+
version = "0.43.0"
|
|
678
678
|
dependencies = [
|
|
679
679
|
"polyxml",
|
|
680
680
|
"quick-xml",
|
|
@@ -228,19 +228,11 @@ impl ModelSchema {
|
|
|
228
228
|
use crate::ir::{PrimitiveType, TypeDef, TypeRef};
|
|
229
229
|
use std::collections::HashSet;
|
|
230
230
|
|
|
231
|
-
let (name,
|
|
232
|
-
if let Some((
|
|
233
|
-
(
|
|
234
|
-
elem.qname.local.clone(),
|
|
235
|
-
Some(qname.clone()),
|
|
236
|
-
elem.type_ref.clone(),
|
|
237
|
-
)
|
|
231
|
+
let (name, type_ref) = if let Some(target) = root_name {
|
|
232
|
+
if let Some((_, elem)) = ir.elements.iter().find(|(q, _)| q.local == target) {
|
|
233
|
+
(elem.qname.local.clone(), elem.type_ref.clone())
|
|
238
234
|
} else if let Some((qname, _)) = ir.types.iter().find(|(q, _)| q.local == target) {
|
|
239
|
-
(
|
|
240
|
-
qname.local.clone(),
|
|
241
|
-
Some(qname.clone()),
|
|
242
|
-
TypeRef::Named(qname.clone()),
|
|
243
|
-
)
|
|
235
|
+
(qname.local.clone(), TypeRef::Named(qname.clone()))
|
|
244
236
|
} else {
|
|
245
237
|
return Err(crate::error::PolyXmlError::SchemaError(format!(
|
|
246
238
|
"Root element or type '{}' not found in schema",
|
|
@@ -248,23 +240,19 @@ impl ModelSchema {
|
|
|
248
240
|
)));
|
|
249
241
|
}
|
|
250
242
|
} else if let Some((_, elem)) = ir.elements.iter().next() {
|
|
251
|
-
(
|
|
252
|
-
elem.qname.local.clone(),
|
|
253
|
-
Some(elem.qname.clone()),
|
|
254
|
-
elem.type_ref.clone(),
|
|
255
|
-
)
|
|
243
|
+
(elem.qname.local.clone(), elem.type_ref.clone())
|
|
256
244
|
} else if let Some((qname, _)) = ir.types.iter().next() {
|
|
257
|
-
(
|
|
258
|
-
qname.local.clone(),
|
|
259
|
-
Some(qname.clone()),
|
|
260
|
-
TypeRef::Named(qname.clone()),
|
|
261
|
-
)
|
|
245
|
+
(qname.local.clone(), TypeRef::Named(qname.clone()))
|
|
262
246
|
} else {
|
|
263
247
|
return Err(crate::error::PolyXmlError::SchemaError(
|
|
264
248
|
"SchemaIR contains no elements or types".into(),
|
|
265
249
|
));
|
|
266
250
|
};
|
|
267
251
|
|
|
252
|
+
const MAX_CYCLE_DEPTH: usize = 6;
|
|
253
|
+
type MemoKey = (crate::ir::QName, usize);
|
|
254
|
+
type MemoMap = HashMap<MemoKey, Arc<ModelSchema>>;
|
|
255
|
+
|
|
268
256
|
fn map_primitive(prim: PrimitiveType) -> ScalarType {
|
|
269
257
|
match prim {
|
|
270
258
|
PrimitiveType::String
|
|
@@ -315,32 +303,56 @@ impl ModelSchema {
|
|
|
315
303
|
fn build_type(
|
|
316
304
|
tr: &TypeRef,
|
|
317
305
|
ir: &crate::ir::SchemaIR,
|
|
318
|
-
|
|
306
|
+
active: &mut HashSet<crate::ir::QName>,
|
|
307
|
+
budget: usize,
|
|
308
|
+
memo: &mut MemoMap,
|
|
319
309
|
) -> ValueType {
|
|
320
310
|
match tr {
|
|
321
311
|
TypeRef::Primitive(prim) => ValueType::Scalar(map_primitive(*prim)),
|
|
322
|
-
TypeRef::List(inner) => match build_type(inner, ir,
|
|
312
|
+
TypeRef::List(inner) => match build_type(inner, ir, active, budget, memo) {
|
|
323
313
|
ValueType::Scalar(scalar) => {
|
|
324
314
|
ValueType::Scalar(ScalarType::List(Box::new(scalar)))
|
|
325
315
|
}
|
|
326
316
|
_ => ValueType::Scalar(ScalarType::Any),
|
|
327
317
|
},
|
|
328
|
-
TypeRef::Boxed(inner) => build_type(inner, ir,
|
|
318
|
+
TypeRef::Boxed(inner) => build_type(inner, ir, active, budget, memo),
|
|
329
319
|
TypeRef::Named(qname) => {
|
|
330
320
|
if let Some(type_def) = ir.types.get(qname) {
|
|
331
321
|
match type_def {
|
|
332
322
|
TypeDef::Struct(s) => {
|
|
333
|
-
if
|
|
334
|
-
|
|
323
|
+
if active.contains(&s.qname) {
|
|
324
|
+
if budget == 0 {
|
|
325
|
+
ValueType::Nested(
|
|
326
|
+
ModelSchema::builder(&s.qname.local).build(),
|
|
327
|
+
)
|
|
328
|
+
} else {
|
|
329
|
+
let next_budget = budget - 1;
|
|
330
|
+
if let Some(cached) =
|
|
331
|
+
memo.get(&(s.qname.clone(), next_budget))
|
|
332
|
+
{
|
|
333
|
+
return ValueType::Nested(Arc::clone(cached));
|
|
334
|
+
}
|
|
335
|
+
let mut fresh_active = HashSet::new();
|
|
336
|
+
let child_schema = build_struct(
|
|
337
|
+
s,
|
|
338
|
+
ir,
|
|
339
|
+
&mut fresh_active,
|
|
340
|
+
next_budget,
|
|
341
|
+
memo,
|
|
342
|
+
);
|
|
343
|
+
memo.insert(
|
|
344
|
+
(s.qname.clone(), next_budget),
|
|
345
|
+
Arc::clone(&child_schema),
|
|
346
|
+
);
|
|
347
|
+
ValueType::Nested(child_schema)
|
|
348
|
+
}
|
|
335
349
|
} else {
|
|
336
|
-
|
|
337
|
-
let child_schema = build_struct(s, ir, visited);
|
|
338
|
-
visited.remove(&s.qname);
|
|
350
|
+
let child_schema = build_struct(s, ir, active, budget, memo);
|
|
339
351
|
ValueType::Nested(child_schema)
|
|
340
352
|
}
|
|
341
353
|
}
|
|
342
354
|
TypeDef::Simple(sim) => {
|
|
343
|
-
let base = build_type(&sim.base_type, ir,
|
|
355
|
+
let base = build_type(&sim.base_type, ir, active, budget, memo);
|
|
344
356
|
if sim.facets.is_empty() {
|
|
345
357
|
base
|
|
346
358
|
} else if let ValueType::Scalar(scalar) = base {
|
|
@@ -359,9 +371,12 @@ impl ModelSchema {
|
|
|
359
371
|
ValueType::Scalar(ScalarType::Union(
|
|
360
372
|
u.branches
|
|
361
373
|
.iter()
|
|
362
|
-
.map(|b|
|
|
363
|
-
|
|
364
|
-
|
|
374
|
+
.map(|b| {
|
|
375
|
+
match build_type(&b.type_ref, ir, active, budget, memo)
|
|
376
|
+
{
|
|
377
|
+
ValueType::Scalar(scalar) => scalar,
|
|
378
|
+
_ => ScalarType::Any,
|
|
379
|
+
}
|
|
365
380
|
})
|
|
366
381
|
.collect(),
|
|
367
382
|
))
|
|
@@ -378,7 +393,9 @@ impl ModelSchema {
|
|
|
378
393
|
fn build_field(
|
|
379
394
|
f: &crate::ir::FieldDef,
|
|
380
395
|
ir: &crate::ir::SchemaIR,
|
|
381
|
-
|
|
396
|
+
active: &mut HashSet<crate::ir::QName>,
|
|
397
|
+
budget: usize,
|
|
398
|
+
memo: &mut MemoMap,
|
|
382
399
|
) -> FieldSchema {
|
|
383
400
|
let kind = match f.kind {
|
|
384
401
|
crate::ir::FieldKind::Attribute => FieldKind::Attribute,
|
|
@@ -388,7 +405,7 @@ impl ModelSchema {
|
|
|
388
405
|
crate::ir::FieldKind::Any => FieldKind::Any,
|
|
389
406
|
};
|
|
390
407
|
|
|
391
|
-
let mut val_type = build_type(&f.type_ref, ir,
|
|
408
|
+
let mut val_type = build_type(&f.type_ref, ir, active, budget, memo);
|
|
392
409
|
if f.cardinality.is_list() && !matches!(val_type, ValueType::List(_)) {
|
|
393
410
|
val_type = ValueType::List(Box::new(val_type));
|
|
394
411
|
}
|
|
@@ -405,6 +422,48 @@ impl ModelSchema {
|
|
|
405
422
|
field_schema
|
|
406
423
|
}
|
|
407
424
|
|
|
425
|
+
fn add_field_or_choice_branches(
|
|
426
|
+
mut builder: ModelSchemaBuilder,
|
|
427
|
+
f: &crate::ir::FieldDef,
|
|
428
|
+
ir: &crate::ir::SchemaIR,
|
|
429
|
+
active: &mut HashSet<crate::ir::QName>,
|
|
430
|
+
budget: usize,
|
|
431
|
+
memo: &mut MemoMap,
|
|
432
|
+
) -> ModelSchemaBuilder {
|
|
433
|
+
if f.xml_name.is_empty() && f.kind == crate::ir::FieldKind::Element {
|
|
434
|
+
if let TypeRef::Named(qname) = &f.type_ref {
|
|
435
|
+
if let Some(TypeDef::Union(union)) = ir.types.get(qname) {
|
|
436
|
+
if !union.is_lexical() && !union.is_mixed_content() {
|
|
437
|
+
for branch in &union.branches {
|
|
438
|
+
if branch.xml_name.is_empty() || branch.xml_name == "#text" {
|
|
439
|
+
continue;
|
|
440
|
+
}
|
|
441
|
+
let mut val_type =
|
|
442
|
+
build_type(&branch.type_ref, ir, active, budget, memo);
|
|
443
|
+
if f.cardinality.is_list()
|
|
444
|
+
&& !matches!(val_type, ValueType::List(_))
|
|
445
|
+
{
|
|
446
|
+
val_type = ValueType::List(Box::new(val_type));
|
|
447
|
+
}
|
|
448
|
+
let mut fs = FieldSchema::new(
|
|
449
|
+
&branch.xml_name,
|
|
450
|
+
branch.xml_name.as_bytes(),
|
|
451
|
+
FieldKind::Element,
|
|
452
|
+
val_type,
|
|
453
|
+
);
|
|
454
|
+
if let Some(ref ns) = branch.namespace {
|
|
455
|
+
fs = fs.namespace(ns);
|
|
456
|
+
}
|
|
457
|
+
builder = builder.field(fs);
|
|
458
|
+
}
|
|
459
|
+
return builder;
|
|
460
|
+
}
|
|
461
|
+
}
|
|
462
|
+
}
|
|
463
|
+
}
|
|
464
|
+
builder.field(build_field(f, ir, active, budget, memo))
|
|
465
|
+
}
|
|
466
|
+
|
|
408
467
|
/// Whether `d` transitively extends `base` via `xs:extension`.
|
|
409
468
|
fn derives_from(
|
|
410
469
|
ir: &crate::ir::SchemaIR,
|
|
@@ -431,8 +490,11 @@ impl ModelSchema {
|
|
|
431
490
|
fn build_struct(
|
|
432
491
|
s: &crate::ir::StructDef,
|
|
433
492
|
ir: &crate::ir::SchemaIR,
|
|
434
|
-
|
|
493
|
+
active: &mut HashSet<crate::ir::QName>,
|
|
494
|
+
budget: usize,
|
|
495
|
+
memo: &mut MemoMap,
|
|
435
496
|
) -> Arc<ModelSchema> {
|
|
497
|
+
active.insert(s.qname.clone());
|
|
436
498
|
let mut builder = ModelSchema::builder(&s.qname.local);
|
|
437
499
|
if let Some(ref ns) = s.qname.namespace {
|
|
438
500
|
builder = builder.namespace(ns);
|
|
@@ -474,11 +536,11 @@ impl ModelSchema {
|
|
|
474
536
|
if has_own_text && f.kind == crate::ir::FieldKind::Text {
|
|
475
537
|
continue;
|
|
476
538
|
}
|
|
477
|
-
builder = builder
|
|
539
|
+
builder = add_field_or_choice_branches(builder, f, ir, active, budget, memo);
|
|
478
540
|
}
|
|
479
541
|
}
|
|
480
542
|
for f in &s.fields {
|
|
481
|
-
builder = builder
|
|
543
|
+
builder = add_field_or_choice_branches(builder, f, ir, active, budget, memo);
|
|
482
544
|
}
|
|
483
545
|
|
|
484
546
|
let mut schema = builder.build();
|
|
@@ -508,7 +570,7 @@ impl ModelSchema {
|
|
|
508
570
|
variant_name: branch.variant_name.clone(),
|
|
509
571
|
xml_name: branch.xml_name.as_bytes().to_vec(),
|
|
510
572
|
namespace: branch.namespace.clone(),
|
|
511
|
-
val_type: build_type(&branch.type_ref, ir,
|
|
573
|
+
val_type: build_type(&branch.type_ref, ir, active, budget, memo),
|
|
512
574
|
})
|
|
513
575
|
.collect();
|
|
514
576
|
Arc::get_mut(&mut schema).expect("new schema").mixed_content =
|
|
@@ -534,38 +596,35 @@ impl ModelSchema {
|
|
|
534
596
|
.collect();
|
|
535
597
|
let mut variants = Vec::with_capacity(derived.len());
|
|
536
598
|
for dq in derived {
|
|
537
|
-
if
|
|
599
|
+
if active.contains(&dq) {
|
|
538
600
|
continue;
|
|
539
601
|
}
|
|
540
|
-
visited.insert(dq.clone());
|
|
541
602
|
if let Some(TypeDef::Struct(d)) = ir.types.get(&dq) {
|
|
542
|
-
variants.push(build_struct(d, ir,
|
|
603
|
+
variants.push(build_struct(d, ir, active, budget, memo));
|
|
543
604
|
}
|
|
544
|
-
visited.remove(&dq);
|
|
545
605
|
}
|
|
546
606
|
if !variants.is_empty() {
|
|
547
607
|
schema.set_variants(variants);
|
|
548
608
|
}
|
|
549
609
|
|
|
610
|
+
active.remove(&s.qname);
|
|
550
611
|
schema
|
|
551
612
|
}
|
|
552
613
|
|
|
553
|
-
let mut
|
|
554
|
-
|
|
555
|
-
visited.insert(qn.clone());
|
|
556
|
-
}
|
|
614
|
+
let mut active = HashSet::new();
|
|
615
|
+
let mut memo = HashMap::new();
|
|
557
616
|
|
|
558
617
|
match type_ref {
|
|
559
618
|
TypeRef::Named(ref qname) if ir.types.contains_key(qname) => {
|
|
560
619
|
if let Some(TypeDef::Struct(s)) = ir.types.get(qname) {
|
|
561
|
-
Ok(build_struct(s, ir, &mut
|
|
620
|
+
Ok(build_struct(s, ir, &mut active, MAX_CYCLE_DEPTH, &mut memo))
|
|
562
621
|
} else {
|
|
563
622
|
let mut b = ModelSchema::builder(name);
|
|
564
623
|
b = b.field(FieldSchema::new(
|
|
565
624
|
"value",
|
|
566
625
|
b"value",
|
|
567
626
|
FieldKind::Text,
|
|
568
|
-
build_type(&type_ref, ir, &mut
|
|
627
|
+
build_type(&type_ref, ir, &mut active, MAX_CYCLE_DEPTH, &mut memo),
|
|
569
628
|
));
|
|
570
629
|
Ok(b.build())
|
|
571
630
|
}
|
|
@@ -576,7 +635,7 @@ impl ModelSchema {
|
|
|
576
635
|
"value",
|
|
577
636
|
b"value",
|
|
578
637
|
FieldKind::Text,
|
|
579
|
-
build_type(&type_ref, ir, &mut
|
|
638
|
+
build_type(&type_ref, ir, &mut active, MAX_CYCLE_DEPTH, &mut memo),
|
|
580
639
|
));
|
|
581
640
|
Ok(b.build())
|
|
582
641
|
}
|
|
@@ -298,3 +298,80 @@ fn test_polymorphic_xsi_type_xml_json_xml_roundtrip() {
|
|
|
298
298
|
"unexpected error: {err}"
|
|
299
299
|
);
|
|
300
300
|
}
|
|
301
|
+
|
|
302
|
+
#[test]
|
|
303
|
+
fn test_ir_schema_recursive_extension_and_choice_roundtrip() {
|
|
304
|
+
let xsd = r#"<?xml version="1.0" encoding="UTF-8"?>
|
|
305
|
+
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
|
|
306
|
+
targetNamespace="urn:example:telemetry"
|
|
307
|
+
xmlns:tns="urn:example:telemetry"
|
|
308
|
+
elementFormDefault="qualified">
|
|
309
|
+
<xs:complexType name="TelemetryHeader">
|
|
310
|
+
<xs:sequence>
|
|
311
|
+
<xs:element name="PlatformId" type="xs:string"/>
|
|
312
|
+
<xs:element name="Seq" type="xs:unsignedLong"/>
|
|
313
|
+
</xs:sequence>
|
|
314
|
+
</xs:complexType>
|
|
315
|
+
<xs:complexType name="TrackNode">
|
|
316
|
+
<xs:complexContent>
|
|
317
|
+
<xs:extension base="tns:TelemetryHeader">
|
|
318
|
+
<xs:sequence>
|
|
319
|
+
<xs:choice>
|
|
320
|
+
<xs:element name="BearingDeg" type="xs:double"/>
|
|
321
|
+
<xs:element name="LostSignal" type="xs:boolean"/>
|
|
322
|
+
</xs:choice>
|
|
323
|
+
<xs:element name="Child" type="tns:TrackNode" minOccurs="0" maxOccurs="unbounded"/>
|
|
324
|
+
</xs:sequence>
|
|
325
|
+
</xs:extension>
|
|
326
|
+
</xs:complexContent>
|
|
327
|
+
</xs:complexType>
|
|
328
|
+
<xs:element name="TrackNode" type="tns:TrackNode"/>
|
|
329
|
+
</xs:schema>"#;
|
|
330
|
+
|
|
331
|
+
let xml = br#"<TrackNode xmlns="urn:example:telemetry">
|
|
332
|
+
<PlatformId>UAV-ALPHA</PlatformId>
|
|
333
|
+
<Seq>9012</Seq>
|
|
334
|
+
<BearingDeg>137.5</BearingDeg>
|
|
335
|
+
<Child>
|
|
336
|
+
<PlatformId>RELAY-02</PlatformId>
|
|
337
|
+
<Seq>9013</Seq>
|
|
338
|
+
<LostSignal>false</LostSignal>
|
|
339
|
+
</Child>
|
|
340
|
+
</TrackNode>"#;
|
|
341
|
+
|
|
342
|
+
let ir = polyxml::schema_parser::XsdParser::new()
|
|
343
|
+
.parse_str(xsd)
|
|
344
|
+
.expect("parse telemetry xsd");
|
|
345
|
+
let schema = ModelSchema::from_ir(&ir, Some("TrackNode")).expect("ModelSchema::from_ir");
|
|
346
|
+
|
|
347
|
+
let json_bytes =
|
|
348
|
+
xml_to_json(xml, Some(Arc::clone(&schema)), Some(2), true).expect("xml_to_json");
|
|
349
|
+
let parsed: serde_json::Value = serde_json::from_slice(&json_bytes).expect("valid json");
|
|
350
|
+
assert_eq!(parsed["PlatformId"], "UAV-ALPHA");
|
|
351
|
+
assert_eq!(parsed["Seq"], 9012);
|
|
352
|
+
assert_eq!(parsed["BearingDeg"], 137.5);
|
|
353
|
+
assert_eq!(parsed["Child"][0]["PlatformId"], "RELAY-02");
|
|
354
|
+
assert_eq!(parsed["Child"][0]["Seq"], 9013);
|
|
355
|
+
assert_eq!(parsed["Child"][0]["LostSignal"], false);
|
|
356
|
+
|
|
357
|
+
let rt_xml = json_to_xml(
|
|
358
|
+
&json_bytes,
|
|
359
|
+
Some(Arc::clone(&schema)),
|
|
360
|
+
Some("TrackNode"),
|
|
361
|
+
Some(2),
|
|
362
|
+
None,
|
|
363
|
+
None,
|
|
364
|
+
)
|
|
365
|
+
.expect("json_to_xml");
|
|
366
|
+
let rt_str = String::from_utf8(rt_xml).expect("utf8");
|
|
367
|
+
for snippet in [
|
|
368
|
+
"<ns0:PlatformId>UAV-ALPHA</ns0:PlatformId>",
|
|
369
|
+
"<ns0:Seq>9012</ns0:Seq>",
|
|
370
|
+
"<ns0:BearingDeg>137.5</ns0:BearingDeg>",
|
|
371
|
+
"<ns0:PlatformId>RELAY-02</ns0:PlatformId>",
|
|
372
|
+
"<ns0:Seq>9013</ns0:Seq>",
|
|
373
|
+
"<ns0:LostSignal>false</ns0:LostSignal>",
|
|
374
|
+
] {
|
|
375
|
+
assert!(rt_str.contains(snippet), "missing {snippet} in:\n{rt_str}");
|
|
376
|
+
}
|
|
377
|
+
}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{polyxml-0.42.0 → polyxml-0.43.0}/crates/polyxml-core/benches/support/tag_dispatch_fixtures.rs
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{polyxml-0.42.0 → polyxml-0.43.0}/crates/polyxml-core/tests/test_escaped_enum_and_nil_mixed.rs
RENAMED
|
File without changes
|
|
File without changes
|
{polyxml-0.42.0 → polyxml-0.43.0}/crates/polyxml-core/tests/test_inherited_simple_content.rs
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{polyxml-0.42.0 → polyxml-0.43.0}/crates/polyxml-core/tests/test_schema_attribute_entities.rs
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|