polyxml 0.19.2__tar.gz → 0.20.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.19.2 → polyxml-0.20.0}/Cargo.lock +5 -5
- {polyxml-0.19.2 → polyxml-0.20.0}/Cargo.toml +1 -1
- {polyxml-0.19.2 → polyxml-0.20.0}/PKG-INFO +1 -1
- {polyxml-0.19.2 → polyxml-0.20.0}/crates/polyxml-core/src/codegen/csharp/mod.rs +182 -5
- polyxml-0.20.0/crates/polyxml-core/src/codegen/java/codec.rs +484 -0
- {polyxml-0.19.2 → polyxml-0.20.0}/crates/polyxml-core/src/codegen/java/mod.rs +91 -28
- polyxml-0.20.0/crates/polyxml-core/src/codegen/java/models.rs +335 -0
- {polyxml-0.19.2 → polyxml-0.20.0}/crates/polyxml-core/tests/test_csharp_codegen.rs +108 -0
- {polyxml-0.19.2 → polyxml-0.20.0}/crates/polyxml-core/tests/test_java_codegen.rs +270 -0
- {polyxml-0.19.2 → polyxml-0.20.0}/pyproject.toml +1 -1
- {polyxml-0.19.2 → polyxml-0.20.0}/README.md +0 -0
- {polyxml-0.19.2 → polyxml-0.20.0}/crates/polyxml-core/Cargo.toml +0 -0
- {polyxml-0.19.2 → polyxml-0.20.0}/crates/polyxml-core/README.md +0 -0
- {polyxml-0.19.2 → polyxml-0.20.0}/crates/polyxml-core/benches/core_benchmarks.rs +0 -0
- {polyxml-0.19.2 → polyxml-0.20.0}/crates/polyxml-core/src/codegen/cpp/mod.rs +0 -0
- {polyxml-0.19.2 → polyxml-0.20.0}/crates/polyxml-core/src/codegen/go/mod.rs +0 -0
- {polyxml-0.19.2 → polyxml-0.20.0}/crates/polyxml-core/src/codegen/mod.rs +0 -0
- {polyxml-0.19.2 → polyxml-0.20.0}/crates/polyxml-core/src/codegen/python/mod.rs +0 -0
- {polyxml-0.19.2 → polyxml-0.20.0}/crates/polyxml-core/src/codegen/rust/mod.rs +0 -0
- {polyxml-0.19.2 → polyxml-0.20.0}/crates/polyxml-core/src/codegen/typescript/mod.rs +0 -0
- {polyxml-0.19.2 → polyxml-0.20.0}/crates/polyxml-core/src/converters.rs +0 -0
- {polyxml-0.19.2 → polyxml-0.20.0}/crates/polyxml-core/src/error.rs +0 -0
- {polyxml-0.19.2 → polyxml-0.20.0}/crates/polyxml-core/src/ir/mod.rs +0 -0
- {polyxml-0.19.2 → polyxml-0.20.0}/crates/polyxml-core/src/ir/tarjan.rs +0 -0
- {polyxml-0.19.2 → polyxml-0.20.0}/crates/polyxml-core/src/json.rs +0 -0
- {polyxml-0.19.2 → polyxml-0.20.0}/crates/polyxml-core/src/lib.rs +0 -0
- {polyxml-0.19.2 → polyxml-0.20.0}/crates/polyxml-core/src/parser.rs +0 -0
- {polyxml-0.19.2 → polyxml-0.20.0}/crates/polyxml-core/src/schema.rs +0 -0
- {polyxml-0.19.2 → polyxml-0.20.0}/crates/polyxml-core/src/schema_parser/mod.rs +0 -0
- {polyxml-0.19.2 → polyxml-0.20.0}/crates/polyxml-core/src/serializer.rs +0 -0
- {polyxml-0.19.2 → polyxml-0.20.0}/crates/polyxml-core/src/transcoder.rs +0 -0
- {polyxml-0.19.2 → polyxml-0.20.0}/crates/polyxml-core/src/value.rs +0 -0
- {polyxml-0.19.2 → polyxml-0.20.0}/crates/polyxml-core/tests/test_conformance.rs +0 -0
- {polyxml-0.19.2 → polyxml-0.20.0}/crates/polyxml-core/tests/test_core.rs +0 -0
- {polyxml-0.19.2 → polyxml-0.20.0}/crates/polyxml-core/tests/test_cpp_codegen.rs +0 -0
- {polyxml-0.19.2 → polyxml-0.20.0}/crates/polyxml-core/tests/test_go_codegen.rs +0 -0
- {polyxml-0.19.2 → polyxml-0.20.0}/crates/polyxml-core/tests/test_json.rs +0 -0
- {polyxml-0.19.2 → polyxml-0.20.0}/crates/polyxml-core/tests/test_python_codegen.rs +0 -0
- {polyxml-0.19.2 → polyxml-0.20.0}/crates/polyxml-core/tests/test_rust_codecs.rs +0 -0
- {polyxml-0.19.2 → polyxml-0.20.0}/crates/polyxml-core/tests/test_rust_codegen.rs +0 -0
- {polyxml-0.19.2 → polyxml-0.20.0}/crates/polyxml-core/tests/test_schema_ir.rs +0 -0
- {polyxml-0.19.2 → polyxml-0.20.0}/crates/polyxml-core/tests/test_security.rs +0 -0
- {polyxml-0.19.2 → polyxml-0.20.0}/crates/polyxml-core/tests/test_transcoder.rs +0 -0
- {polyxml-0.19.2 → polyxml-0.20.0}/crates/polyxml-core/tests/test_ts_codegen.rs +0 -0
- {polyxml-0.19.2 → polyxml-0.20.0}/crates/polyxml-python/Cargo.toml +0 -0
- {polyxml-0.19.2 → polyxml-0.20.0}/crates/polyxml-python/README.md +0 -0
- {polyxml-0.19.2 → polyxml-0.20.0}/crates/polyxml-python/src/lib.rs +0 -0
- {polyxml-0.19.2 → polyxml-0.20.0}/crates/polyxml-python/tests/test_conformance.py +0 -0
- {polyxml-0.19.2 → polyxml-0.20.0}/crates/polyxml-python/tests/test_generated_models.py +0 -0
- {polyxml-0.19.2 → polyxml-0.20.0}/crates/polyxml-python/tests/test_json.py +0 -0
- {polyxml-0.19.2 → polyxml-0.20.0}/crates/polyxml-python/tests/test_polyxml.py +0 -0
- {polyxml-0.19.2 → polyxml-0.20.0}/python/polyxml/AGENT_GUIDE.md +0 -0
- {polyxml-0.19.2 → polyxml-0.20.0}/python/polyxml/__init__.py +0 -0
- {polyxml-0.19.2 → polyxml-0.20.0}/python/polyxml/compat/__init__.py +0 -0
- {polyxml-0.19.2 → polyxml-0.20.0}/python/polyxml/compat/xsdata.py +0 -0
- {polyxml-0.19.2 → polyxml-0.20.0}/python/polyxml/py.typed +0 -0
|
@@ -549,7 +549,7 @@ dependencies = [
|
|
|
549
549
|
|
|
550
550
|
[[package]]
|
|
551
551
|
name = "polyxml"
|
|
552
|
-
version = "0.
|
|
552
|
+
version = "0.20.0"
|
|
553
553
|
dependencies = [
|
|
554
554
|
"criterion",
|
|
555
555
|
"heck",
|
|
@@ -567,14 +567,14 @@ dependencies = [
|
|
|
567
567
|
|
|
568
568
|
[[package]]
|
|
569
569
|
name = "polyxml-c"
|
|
570
|
-
version = "0.
|
|
570
|
+
version = "0.20.0"
|
|
571
571
|
dependencies = [
|
|
572
572
|
"polyxml",
|
|
573
573
|
]
|
|
574
574
|
|
|
575
575
|
[[package]]
|
|
576
576
|
name = "polyxml-cli"
|
|
577
|
-
version = "0.
|
|
577
|
+
version = "0.20.0"
|
|
578
578
|
dependencies = [
|
|
579
579
|
"clap",
|
|
580
580
|
"glob",
|
|
@@ -588,7 +588,7 @@ dependencies = [
|
|
|
588
588
|
|
|
589
589
|
[[package]]
|
|
590
590
|
name = "polyxml-js"
|
|
591
|
-
version = "0.
|
|
591
|
+
version = "0.20.0"
|
|
592
592
|
dependencies = [
|
|
593
593
|
"napi",
|
|
594
594
|
"napi-build",
|
|
@@ -598,7 +598,7 @@ dependencies = [
|
|
|
598
598
|
|
|
599
599
|
[[package]]
|
|
600
600
|
name = "polyxml-python"
|
|
601
|
-
version = "0.
|
|
601
|
+
version = "0.20.0"
|
|
602
602
|
dependencies = [
|
|
603
603
|
"lexical-core",
|
|
604
604
|
"polyxml",
|
|
@@ -51,6 +51,9 @@ pub struct CSharpOptions {
|
|
|
51
51
|
pub emit_validation: bool,
|
|
52
52
|
/// Record emission kind (record class vs record struct)
|
|
53
53
|
pub record_kind: CSharpRecordKind,
|
|
54
|
+
/// Emit immutable records (default) instead of mutable classes.
|
|
55
|
+
#[serde(default = "default_use_records")]
|
|
56
|
+
pub use_records: bool,
|
|
54
57
|
/// Use modern C# 10+ file-scoped namespaces (`namespace Foo;`)
|
|
55
58
|
pub use_file_scoped_namespaces: bool,
|
|
56
59
|
/// Emit root element wrapper records or aliases
|
|
@@ -59,6 +62,10 @@ pub struct CSharpOptions {
|
|
|
59
62
|
pub custom_header: Option<String>,
|
|
60
63
|
}
|
|
61
64
|
|
|
65
|
+
fn default_use_records() -> bool {
|
|
66
|
+
true
|
|
67
|
+
}
|
|
68
|
+
|
|
62
69
|
impl Default for CSharpOptions {
|
|
63
70
|
fn default() -> Self {
|
|
64
71
|
Self {
|
|
@@ -69,6 +76,7 @@ impl Default for CSharpOptions {
|
|
|
69
76
|
source_gen_context_name: "PolyXmlJsonContext".to_string(),
|
|
70
77
|
emit_validation: true,
|
|
71
78
|
record_kind: CSharpRecordKind::Class,
|
|
79
|
+
use_records: true,
|
|
72
80
|
use_file_scoped_namespaces: true,
|
|
73
81
|
emit_root_records: true,
|
|
74
82
|
custom_header: None,
|
|
@@ -372,6 +380,14 @@ impl CSharpCodegen {
|
|
|
372
380
|
}
|
|
373
381
|
}
|
|
374
382
|
|
|
383
|
+
if !self.options.use_records && self.options.emit_root_records {
|
|
384
|
+
for elem in ir.elements.values() {
|
|
385
|
+
let name = to_csharp_type_name(&elem.qname.local);
|
|
386
|
+
if name != self.context.map_type_ref(&elem.type_ref) {
|
|
387
|
+
writeln!(out, "{}[JsonSerializable(typeof({}))]", indent, name).unwrap();
|
|
388
|
+
}
|
|
389
|
+
}
|
|
390
|
+
}
|
|
375
391
|
let ctx_name = &self.options.source_gen_context_name;
|
|
376
392
|
writeln!(
|
|
377
393
|
out,
|
|
@@ -465,7 +481,7 @@ impl CSharpCodegen {
|
|
|
465
481
|
}
|
|
466
482
|
|
|
467
483
|
fn emit_simple(&self, out: &mut String, s: &SimpleTypeDef, indent: &str) {
|
|
468
|
-
if !s.facets.is_empty() {
|
|
484
|
+
if !s.facets.is_empty() || !self.options.use_records {
|
|
469
485
|
let type_name = to_csharp_type_name(&s.qname.local);
|
|
470
486
|
let base_type = self.context.map_type_ref(&s.base_type);
|
|
471
487
|
|
|
@@ -473,6 +489,43 @@ impl CSharpCodegen {
|
|
|
473
489
|
self.emit_docstring(out, doc, indent);
|
|
474
490
|
}
|
|
475
491
|
|
|
492
|
+
if !self.options.use_records {
|
|
493
|
+
writeln!(
|
|
494
|
+
out,
|
|
495
|
+
"{}public class {}{}\n{}{{",
|
|
496
|
+
indent,
|
|
497
|
+
type_name,
|
|
498
|
+
if self.options.emit_validation {
|
|
499
|
+
" : IValidatableObject"
|
|
500
|
+
} else {
|
|
501
|
+
""
|
|
502
|
+
},
|
|
503
|
+
indent
|
|
504
|
+
)
|
|
505
|
+
.unwrap();
|
|
506
|
+
if self.options.emit_xml_attributes {
|
|
507
|
+
writeln!(out, "{} [XmlText]", indent).unwrap();
|
|
508
|
+
}
|
|
509
|
+
writeln!(
|
|
510
|
+
out,
|
|
511
|
+
"{} public {} Value {{ get; set; }} = default!;",
|
|
512
|
+
indent, base_type
|
|
513
|
+
)
|
|
514
|
+
.unwrap();
|
|
515
|
+
writeln!(
|
|
516
|
+
out,
|
|
517
|
+
"{} public {}() {{ }}\n{} public {}({} value) {{ Value = value; }}",
|
|
518
|
+
indent, type_name, indent, type_name, base_type
|
|
519
|
+
)
|
|
520
|
+
.unwrap();
|
|
521
|
+
if self.options.emit_validation {
|
|
522
|
+
writeln!(out, "{} public IEnumerable<ValidationResult> Validate(ValidationContext validationContext)\n{} {{", indent, indent).unwrap();
|
|
523
|
+
self.emit_facet_checks(out, &s.facets, "Value", &format!("{} ", indent));
|
|
524
|
+
writeln!(out, "{} yield break;\n{} }}", indent, indent).unwrap();
|
|
525
|
+
}
|
|
526
|
+
writeln!(out, "{}}}\n", indent).unwrap();
|
|
527
|
+
return;
|
|
528
|
+
}
|
|
476
529
|
writeln!(
|
|
477
530
|
out,
|
|
478
531
|
"{}public sealed record {}([property: XmlText] {} Value) : IValidatableObject",
|
|
@@ -522,7 +575,31 @@ impl CSharpCodegen {
|
|
|
522
575
|
}
|
|
523
576
|
}
|
|
524
577
|
|
|
525
|
-
|
|
578
|
+
if !self.options.use_records && self.options.emit_json_attributes {
|
|
579
|
+
for branch in &u.branches {
|
|
580
|
+
writeln!(
|
|
581
|
+
out,
|
|
582
|
+
"{}[JsonDerivedType(typeof({}.{}), {:?})]",
|
|
583
|
+
indent,
|
|
584
|
+
choice_name,
|
|
585
|
+
to_csharp_type_name(&branch.variant_name),
|
|
586
|
+
branch.xml_name
|
|
587
|
+
)
|
|
588
|
+
.unwrap();
|
|
589
|
+
}
|
|
590
|
+
}
|
|
591
|
+
writeln!(
|
|
592
|
+
out,
|
|
593
|
+
"{}public abstract {} {}",
|
|
594
|
+
indent,
|
|
595
|
+
if self.options.use_records {
|
|
596
|
+
"record"
|
|
597
|
+
} else {
|
|
598
|
+
"class"
|
|
599
|
+
},
|
|
600
|
+
choice_name
|
|
601
|
+
)
|
|
602
|
+
.unwrap();
|
|
526
603
|
writeln!(out, "{}{{", indent).unwrap();
|
|
527
604
|
|
|
528
605
|
for branch in &u.branches {
|
|
@@ -546,6 +623,24 @@ impl CSharpCodegen {
|
|
|
546
623
|
format!("[property: {}] ", branch_attrs.join(", "))
|
|
547
624
|
};
|
|
548
625
|
|
|
626
|
+
if !self.options.use_records {
|
|
627
|
+
writeln!(
|
|
628
|
+
out,
|
|
629
|
+
"{} public sealed class {} : {}\n{} {{",
|
|
630
|
+
indent, variant_name, choice_name, indent
|
|
631
|
+
)
|
|
632
|
+
.unwrap();
|
|
633
|
+
writeln!(
|
|
634
|
+
out,
|
|
635
|
+
"{} {}public {} Value {{ get; set; }} = default!;",
|
|
636
|
+
indent,
|
|
637
|
+
xml_attr.replace("[property: ", "["),
|
|
638
|
+
branch_type
|
|
639
|
+
)
|
|
640
|
+
.unwrap();
|
|
641
|
+
writeln!(out, "{} public {}() {{ }}\n{} public {}({} value) {{ Value = value; }}\n{} }}", indent, variant_name, indent, variant_name, branch_type, indent).unwrap();
|
|
642
|
+
continue;
|
|
643
|
+
}
|
|
549
644
|
writeln!(
|
|
550
645
|
out,
|
|
551
646
|
"{} public sealed record {}({}{} Value) : {}",
|
|
@@ -609,6 +704,39 @@ impl CSharpCodegen {
|
|
|
609
704
|
format!(" : {}", base_clause.join(", "))
|
|
610
705
|
};
|
|
611
706
|
|
|
707
|
+
if !self.options.use_records {
|
|
708
|
+
writeln!(
|
|
709
|
+
out,
|
|
710
|
+
"{}public class {}{}\n{}{{",
|
|
711
|
+
indent, struct_name, implements_str, indent
|
|
712
|
+
)
|
|
713
|
+
.unwrap();
|
|
714
|
+
writeln!(out, "{} public {}() {{ }}", indent, struct_name).unwrap();
|
|
715
|
+
for f in &s.fields {
|
|
716
|
+
let name = to_csharp_property_name(&f.name, Some(&struct_name));
|
|
717
|
+
let ty = self.map_field_type(f, ir);
|
|
718
|
+
let attrs = self
|
|
719
|
+
.build_field_attributes(f, ir)
|
|
720
|
+
.replace("[property: ", "[");
|
|
721
|
+
let initial = if f.cardinality.is_list() || f.type_ref.is_list() {
|
|
722
|
+
"new()"
|
|
723
|
+
} else {
|
|
724
|
+
"default!"
|
|
725
|
+
};
|
|
726
|
+
writeln!(
|
|
727
|
+
out,
|
|
728
|
+
"{} {}public {} {} {{ get; set; }} = {};",
|
|
729
|
+
indent, attrs, ty, name, initial
|
|
730
|
+
)
|
|
731
|
+
.unwrap();
|
|
732
|
+
}
|
|
733
|
+
if self.options.emit_validation {
|
|
734
|
+
self.emit_struct_validator(out, s, indent);
|
|
735
|
+
}
|
|
736
|
+
writeln!(out, "{}}}\n", indent).unwrap();
|
|
737
|
+
return;
|
|
738
|
+
}
|
|
739
|
+
|
|
612
740
|
// Collect fields and parameters
|
|
613
741
|
if s.fields.is_empty() {
|
|
614
742
|
writeln!(
|
|
@@ -689,7 +817,17 @@ impl CSharpCodegen {
|
|
|
689
817
|
|
|
690
818
|
fn emit_struct_validator(&self, out: &mut String, s: &StructDef, indent: &str) {
|
|
691
819
|
let struct_name = to_csharp_type_name(&s.qname.local);
|
|
692
|
-
let new_kw = if
|
|
820
|
+
let new_kw = if !self.options.use_records {
|
|
821
|
+
if s.base_type.is_some() {
|
|
822
|
+
"override "
|
|
823
|
+
} else {
|
|
824
|
+
"virtual "
|
|
825
|
+
}
|
|
826
|
+
} else if s.base_type.is_some() {
|
|
827
|
+
"new "
|
|
828
|
+
} else {
|
|
829
|
+
""
|
|
830
|
+
};
|
|
693
831
|
writeln!(
|
|
694
832
|
out,
|
|
695
833
|
"{} public {}IEnumerable<ValidationResult> Validate(ValidationContext validationContext)",
|
|
@@ -698,6 +836,9 @@ impl CSharpCodegen {
|
|
|
698
836
|
.unwrap();
|
|
699
837
|
writeln!(out, "{} {{", indent).unwrap();
|
|
700
838
|
|
|
839
|
+
if !self.options.use_records && s.base_type.is_some() {
|
|
840
|
+
writeln!(out, "{} foreach (var result in base.Validate(validationContext)) yield return result;", indent).unwrap();
|
|
841
|
+
}
|
|
701
842
|
let mut has_checks = false;
|
|
702
843
|
for f in &s.fields {
|
|
703
844
|
let prop_name = to_csharp_property_name(&f.name, Some(&struct_name));
|
|
@@ -888,10 +1029,46 @@ impl CSharpCodegen {
|
|
|
888
1029
|
writeln!(out, "{}[XmlRoot(\"{}\")]", indent, elem.qname.local).unwrap();
|
|
889
1030
|
}
|
|
890
1031
|
}
|
|
1032
|
+
if !self.options.use_records {
|
|
1033
|
+
let can_extend = matches!(&elem.type_ref, TypeRef::Named(q) if matches!(ir.types.get(q), Some(TypeDef::Struct(_) | TypeDef::Simple(_))));
|
|
1034
|
+
if !can_extend {
|
|
1035
|
+
writeln!(
|
|
1036
|
+
out,
|
|
1037
|
+
"{}public sealed class {}\n{}{{",
|
|
1038
|
+
indent, elem_name, indent
|
|
1039
|
+
)
|
|
1040
|
+
.unwrap();
|
|
1041
|
+
if self.options.emit_xml_attributes {
|
|
1042
|
+
let attribute = if matches!(&elem.type_ref, TypeRef::Named(q)
|
|
1043
|
+
if matches!(ir.types.get(q), Some(TypeDef::Union(_))))
|
|
1044
|
+
{
|
|
1045
|
+
"XmlElement"
|
|
1046
|
+
} else {
|
|
1047
|
+
"XmlText"
|
|
1048
|
+
};
|
|
1049
|
+
writeln!(out, "{} [{}]", indent, attribute).unwrap();
|
|
1050
|
+
}
|
|
1051
|
+
writeln!(
|
|
1052
|
+
out,
|
|
1053
|
+
"{} public {} Value {{ get; set; }} = default!;\n{}}}\n",
|
|
1054
|
+
indent, target_type, indent
|
|
1055
|
+
)
|
|
1056
|
+
.unwrap();
|
|
1057
|
+
continue;
|
|
1058
|
+
}
|
|
1059
|
+
}
|
|
891
1060
|
writeln!(
|
|
892
1061
|
out,
|
|
893
|
-
"{}public sealed
|
|
894
|
-
indent,
|
|
1062
|
+
"{}public sealed {} {} : {}\n{}{{",
|
|
1063
|
+
indent,
|
|
1064
|
+
if self.options.use_records {
|
|
1065
|
+
"record"
|
|
1066
|
+
} else {
|
|
1067
|
+
"class"
|
|
1068
|
+
},
|
|
1069
|
+
elem_name,
|
|
1070
|
+
target_type,
|
|
1071
|
+
indent
|
|
895
1072
|
)
|
|
896
1073
|
.unwrap();
|
|
897
1074
|
writeln!(out, "{} public {}() : base() {{ }}", indent, elem_name).unwrap();
|