polyxml 0.30.2__tar.gz → 0.30.4__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.30.2 → polyxml-0.30.4}/Cargo.lock +6 -6
- {polyxml-0.30.2 → polyxml-0.30.4}/Cargo.toml +1 -1
- {polyxml-0.30.2 → polyxml-0.30.4}/PKG-INFO +1 -1
- {polyxml-0.30.2 → polyxml-0.30.4}/crates/polyxml-core/src/codegen/cpp/mod.rs +7 -5
- {polyxml-0.30.2 → polyxml-0.30.4}/crates/polyxml-core/src/codegen/csharp/mod.rs +49 -12
- {polyxml-0.30.2 → polyxml-0.30.4}/crates/polyxml-core/src/codegen/go/mod.rs +22 -3
- {polyxml-0.30.2 → polyxml-0.30.4}/crates/polyxml-core/src/codegen/mod.rs +10 -0
- {polyxml-0.30.2 → polyxml-0.30.4}/crates/polyxml-core/src/codegen/python/mod.rs +16 -6
- {polyxml-0.30.2 → polyxml-0.30.4}/crates/polyxml-core/src/codegen/rust/mod.rs +12 -9
- {polyxml-0.30.2 → polyxml-0.30.4}/crates/polyxml-core/src/codegen/typescript/mod.rs +45 -10
- {polyxml-0.30.2 → polyxml-0.30.4}/crates/polyxml-core/src/ir/mod.rs +3 -0
- {polyxml-0.30.2 → polyxml-0.30.4}/crates/polyxml-core/src/schema_parser/mod.rs +113 -0
- polyxml-0.30.4/crates/polyxml-core/tests/fixtures/ts_mixed_content_inheritance.xsd +17 -0
- {polyxml-0.30.2 → polyxml-0.30.4}/crates/polyxml-core/tests/test_cpp_codegen.rs +22 -0
- {polyxml-0.30.2 → polyxml-0.30.4}/crates/polyxml-core/tests/test_csharp_codegen.rs +62 -0
- {polyxml-0.30.2 → polyxml-0.30.4}/crates/polyxml-core/tests/test_go_codegen.rs +93 -0
- {polyxml-0.30.2 → polyxml-0.30.4}/crates/polyxml-core/tests/test_python_codegen.rs +12 -0
- {polyxml-0.30.2 → polyxml-0.30.4}/crates/polyxml-core/tests/test_rust_codegen.rs +16 -0
- {polyxml-0.30.2 → polyxml-0.30.4}/crates/polyxml-core/tests/test_schema_ir.rs +61 -0
- {polyxml-0.30.2 → polyxml-0.30.4}/crates/polyxml-core/tests/test_ts_codegen.rs +29 -0
- {polyxml-0.30.2 → polyxml-0.30.4}/pyproject.toml +1 -1
- {polyxml-0.30.2 → polyxml-0.30.4}/README.md +0 -0
- {polyxml-0.30.2 → polyxml-0.30.4}/crates/polyxml-core/Cargo.toml +0 -0
- {polyxml-0.30.2 → polyxml-0.30.4}/crates/polyxml-core/README.md +0 -0
- {polyxml-0.30.2 → polyxml-0.30.4}/crates/polyxml-core/benches/core_benchmarks.rs +0 -0
- {polyxml-0.30.2 → polyxml-0.30.4}/crates/polyxml-core/benches/support/tag_dispatch_fixtures.rs +0 -0
- {polyxml-0.30.2 → polyxml-0.30.4}/crates/polyxml-core/benches/tag_dispatch.rs +0 -0
- {polyxml-0.30.2 → polyxml-0.30.4}/crates/polyxml-core/src/codegen/java/codec.rs +0 -0
- {polyxml-0.30.2 → polyxml-0.30.4}/crates/polyxml-core/src/codegen/java/mod.rs +0 -0
- {polyxml-0.30.2 → polyxml-0.30.4}/crates/polyxml-core/src/codegen/java/models.rs +0 -0
- {polyxml-0.30.2 → polyxml-0.30.4}/crates/polyxml-core/src/codegen/python/aot.rs +0 -0
- {polyxml-0.30.2 → polyxml-0.30.4}/crates/polyxml-core/src/converters.rs +0 -0
- {polyxml-0.30.2 → polyxml-0.30.4}/crates/polyxml-core/src/error.rs +0 -0
- {polyxml-0.30.2 → polyxml-0.30.4}/crates/polyxml-core/src/ir/tarjan.rs +0 -0
- {polyxml-0.30.2 → polyxml-0.30.4}/crates/polyxml-core/src/json.rs +0 -0
- {polyxml-0.30.2 → polyxml-0.30.4}/crates/polyxml-core/src/lib.rs +0 -0
- {polyxml-0.30.2 → polyxml-0.30.4}/crates/polyxml-core/src/parser.rs +0 -0
- {polyxml-0.30.2 → polyxml-0.30.4}/crates/polyxml-core/src/schema.rs +0 -0
- {polyxml-0.30.2 → polyxml-0.30.4}/crates/polyxml-core/src/serializer.rs +0 -0
- {polyxml-0.30.2 → polyxml-0.30.4}/crates/polyxml-core/src/transcoder.rs +0 -0
- {polyxml-0.30.2 → polyxml-0.30.4}/crates/polyxml-core/src/value.rs +0 -0
- {polyxml-0.30.2 → polyxml-0.30.4}/crates/polyxml-core/tests/fixtures/lexical_union.xsd +0 -0
- {polyxml-0.30.2 → polyxml-0.30.4}/crates/polyxml-core/tests/fixtures/mixed_content.xsd +0 -0
- {polyxml-0.30.2 → polyxml-0.30.4}/crates/polyxml-core/tests/test_adversarial_identifiers.rs +0 -0
- {polyxml-0.30.2 → polyxml-0.30.4}/crates/polyxml-core/tests/test_conformance.rs +0 -0
- {polyxml-0.30.2 → polyxml-0.30.4}/crates/polyxml-core/tests/test_core.rs +0 -0
- {polyxml-0.30.2 → polyxml-0.30.4}/crates/polyxml-core/tests/test_java_codegen.rs +0 -0
- {polyxml-0.30.2 → polyxml-0.30.4}/crates/polyxml-core/tests/test_json.rs +0 -0
- {polyxml-0.30.2 → polyxml-0.30.4}/crates/polyxml-core/tests/test_lexical_union_codegen.rs +0 -0
- {polyxml-0.30.2 → polyxml-0.30.4}/crates/polyxml-core/tests/test_mixed_content.rs +0 -0
- {polyxml-0.30.2 → polyxml-0.30.4}/crates/polyxml-core/tests/test_pattern_codegen.rs +0 -0
- {polyxml-0.30.2 → polyxml-0.30.4}/crates/polyxml-core/tests/test_rust_codecs.rs +0 -0
- {polyxml-0.30.2 → polyxml-0.30.4}/crates/polyxml-core/tests/test_schema_audit.rs +0 -0
- {polyxml-0.30.2 → polyxml-0.30.4}/crates/polyxml-core/tests/test_security.rs +0 -0
- {polyxml-0.30.2 → polyxml-0.30.4}/crates/polyxml-core/tests/test_transcoder.rs +0 -0
- {polyxml-0.30.2 → polyxml-0.30.4}/crates/polyxml-core/tests/test_unbounded_choice.rs +0 -0
- {polyxml-0.30.2 → polyxml-0.30.4}/crates/polyxml-core/tests/test_xsi_type.rs +0 -0
- {polyxml-0.30.2 → polyxml-0.30.4}/crates/polyxml-python/Cargo.toml +0 -0
- {polyxml-0.30.2 → polyxml-0.30.4}/crates/polyxml-python/README.md +0 -0
- {polyxml-0.30.2 → polyxml-0.30.4}/crates/polyxml-python/benches/aot_vs_dataclass.py +0 -0
- {polyxml-0.30.2 → polyxml-0.30.4}/crates/polyxml-python/src/lib.rs +0 -0
- {polyxml-0.30.2 → polyxml-0.30.4}/crates/polyxml-python/tests/test_conformance.py +0 -0
- {polyxml-0.30.2 → polyxml-0.30.4}/crates/polyxml-python/tests/test_generated_models.py +0 -0
- {polyxml-0.30.2 → polyxml-0.30.4}/crates/polyxml-python/tests/test_json.py +0 -0
- {polyxml-0.30.2 → polyxml-0.30.4}/crates/polyxml-python/tests/test_mixed_content.py +0 -0
- {polyxml-0.30.2 → polyxml-0.30.4}/crates/polyxml-python/tests/test_polyxml.py +0 -0
- {polyxml-0.30.2 → polyxml-0.30.4}/crates/polyxml-python/tests/test_xsi_type.py +0 -0
- {polyxml-0.30.2 → polyxml-0.30.4}/python/polyxml/AGENT_GUIDE.md +0 -0
- {polyxml-0.30.2 → polyxml-0.30.4}/python/polyxml/__init__.py +0 -0
- {polyxml-0.30.2 → polyxml-0.30.4}/python/polyxml/compat/__init__.py +0 -0
- {polyxml-0.30.2 → polyxml-0.30.4}/python/polyxml/compat/xsdata.py +0 -0
- {polyxml-0.30.2 → polyxml-0.30.4}/python/polyxml/py.typed +0 -0
|
@@ -608,7 +608,7 @@ dependencies = [
|
|
|
608
608
|
|
|
609
609
|
[[package]]
|
|
610
610
|
name = "polyxml"
|
|
611
|
-
version = "0.30.
|
|
611
|
+
version = "0.30.4"
|
|
612
612
|
dependencies = [
|
|
613
613
|
"criterion",
|
|
614
614
|
"heck",
|
|
@@ -629,14 +629,14 @@ dependencies = [
|
|
|
629
629
|
|
|
630
630
|
[[package]]
|
|
631
631
|
name = "polyxml-c"
|
|
632
|
-
version = "0.30.
|
|
632
|
+
version = "0.30.4"
|
|
633
633
|
dependencies = [
|
|
634
634
|
"polyxml",
|
|
635
635
|
]
|
|
636
636
|
|
|
637
637
|
[[package]]
|
|
638
638
|
name = "polyxml-cli"
|
|
639
|
-
version = "0.30.
|
|
639
|
+
version = "0.30.4"
|
|
640
640
|
dependencies = [
|
|
641
641
|
"clap",
|
|
642
642
|
"glob",
|
|
@@ -650,7 +650,7 @@ dependencies = [
|
|
|
650
650
|
|
|
651
651
|
[[package]]
|
|
652
652
|
name = "polyxml-js"
|
|
653
|
-
version = "0.30.
|
|
653
|
+
version = "0.30.4"
|
|
654
654
|
dependencies = [
|
|
655
655
|
"napi",
|
|
656
656
|
"napi-build",
|
|
@@ -660,7 +660,7 @@ dependencies = [
|
|
|
660
660
|
|
|
661
661
|
[[package]]
|
|
662
662
|
name = "polyxml-python"
|
|
663
|
-
version = "0.30.
|
|
663
|
+
version = "0.30.4"
|
|
664
664
|
dependencies = [
|
|
665
665
|
"lexical-core",
|
|
666
666
|
"polyxml",
|
|
@@ -670,7 +670,7 @@ dependencies = [
|
|
|
670
670
|
|
|
671
671
|
[[package]]
|
|
672
672
|
name = "polyxml-wasm"
|
|
673
|
-
version = "0.30.
|
|
673
|
+
version = "0.30.4"
|
|
674
674
|
dependencies = [
|
|
675
675
|
"polyxml",
|
|
676
676
|
"quick-xml",
|
|
@@ -656,9 +656,13 @@ concept XmlModel = requires(T a) {{
|
|
|
656
656
|
}
|
|
657
657
|
|
|
658
658
|
fn emit_types(&self, out: &mut String, ir: &SchemaIR) {
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
659
|
+
let sorted_qnames = self.topological_sort_types(ir);
|
|
660
|
+
|
|
661
|
+
// Aliases must follow their base aliases, which may sort later by name.
|
|
662
|
+
for qname in &sorted_qnames {
|
|
663
|
+
if let Some(TypeDef::Simple(simple)) =
|
|
664
|
+
ir.types.get(qname).filter(|_| !ir.is_external_type(qname))
|
|
665
|
+
{
|
|
662
666
|
self.emit_simple_type(out, simple, ir);
|
|
663
667
|
}
|
|
664
668
|
}
|
|
@@ -671,8 +675,6 @@ concept XmlModel = requires(T a) {{
|
|
|
671
675
|
}
|
|
672
676
|
|
|
673
677
|
// Topologically sort structs and unions (DAG order)
|
|
674
|
-
let sorted_qnames = self.topological_sort_types(ir);
|
|
675
|
-
|
|
676
678
|
for qname in sorted_qnames {
|
|
677
679
|
if ir.is_external_type(&qname) {
|
|
678
680
|
continue;
|
|
@@ -244,13 +244,34 @@ fn type_ident(q: &QName) -> String {
|
|
|
244
244
|
|
|
245
245
|
fn choice_variant_name(branch: &UnionBranch) -> String {
|
|
246
246
|
let name = to_csharp_type_name(&branch.variant_name);
|
|
247
|
-
if matches!(
|
|
247
|
+
if matches!(
|
|
248
|
+
name.as_str(),
|
|
249
|
+
"Value" | "Equals" | "GetHashCode" | "ToString"
|
|
250
|
+
) || matches!(&branch.type_ref, TypeRef::Named(qname) if type_ident(qname) == name)
|
|
251
|
+
{
|
|
248
252
|
format!("{name}Branch")
|
|
249
253
|
} else {
|
|
250
254
|
name
|
|
251
255
|
}
|
|
252
256
|
}
|
|
253
257
|
|
|
258
|
+
fn simple_value_target(base: &TypeRef, ir: &SchemaIR) -> String {
|
|
259
|
+
let mut target = "Value".to_string();
|
|
260
|
+
let mut current = base;
|
|
261
|
+
let mut seen = HashSet::new();
|
|
262
|
+
while let TypeRef::Named(qname) = current {
|
|
263
|
+
if !seen.insert(qname.clone()) {
|
|
264
|
+
break;
|
|
265
|
+
}
|
|
266
|
+
let Some(TypeDef::Simple(simple)) = ir.types.get(qname) else {
|
|
267
|
+
break;
|
|
268
|
+
};
|
|
269
|
+
target.push_str(".Value");
|
|
270
|
+
current = &simple.base_type;
|
|
271
|
+
}
|
|
272
|
+
target
|
|
273
|
+
}
|
|
274
|
+
|
|
254
275
|
impl CSharpCodegen {
|
|
255
276
|
/// Creates a new C# code generator with the given configuration options.
|
|
256
277
|
pub fn new(options: CSharpOptions) -> Self {
|
|
@@ -315,7 +336,7 @@ impl CSharpCodegen {
|
|
|
315
336
|
if !simple.facets.patterns.is_empty() {
|
|
316
337
|
simple.base_type = super::primitive_base(&simple.base_type, ir).clone();
|
|
317
338
|
}
|
|
318
|
-
self.emit_simple(&mut out, &simple, indent);
|
|
339
|
+
self.emit_simple(&mut out, &simple, ir, indent);
|
|
319
340
|
}
|
|
320
341
|
}
|
|
321
342
|
|
|
@@ -510,8 +531,10 @@ impl CSharpCodegen {
|
|
|
510
531
|
writeln!(out, "{}}}\n", indent).unwrap();
|
|
511
532
|
}
|
|
512
533
|
|
|
513
|
-
fn emit_simple(&self, out: &mut String, s: &SimpleTypeDef, indent: &str) {
|
|
514
|
-
|
|
534
|
+
fn emit_simple(&self, out: &mut String, s: &SimpleTypeDef, ir: &SchemaIR, indent: &str) {
|
|
535
|
+
// Named simple types may be referenced by structs and choices even
|
|
536
|
+
// when they have no facets, so every one needs a declaration.
|
|
537
|
+
{
|
|
515
538
|
let type_name = type_ident(&s.qname);
|
|
516
539
|
let base_type = self.context.map_type_ref(&s.base_type);
|
|
517
540
|
|
|
@@ -550,7 +573,8 @@ impl CSharpCodegen {
|
|
|
550
573
|
.unwrap();
|
|
551
574
|
if self.options.emit_validation {
|
|
552
575
|
writeln!(out, "{} public IEnumerable<ValidationResult> Validate(ValidationContext validationContext)\n{} {{", indent, indent).unwrap();
|
|
553
|
-
|
|
576
|
+
let value = simple_value_target(&s.base_type, ir);
|
|
577
|
+
self.emit_facet_checks(out, &s.facets, &value, &format!("{} ", indent));
|
|
554
578
|
writeln!(out, "{} yield break;\n{} }}", indent, indent).unwrap();
|
|
555
579
|
}
|
|
556
580
|
writeln!(out, "{}}}\n", indent).unwrap();
|
|
@@ -579,7 +603,8 @@ impl CSharpCodegen {
|
|
|
579
603
|
)
|
|
580
604
|
.unwrap();
|
|
581
605
|
writeln!(out, "{} {{", indent).unwrap();
|
|
582
|
-
|
|
606
|
+
let value = simple_value_target(&s.base_type, ir);
|
|
607
|
+
self.emit_facet_checks(out, &s.facets, &value, &format!("{} ", indent));
|
|
583
608
|
writeln!(out, "{} yield break;", indent).unwrap();
|
|
584
609
|
writeln!(out, "{} }}", indent).unwrap();
|
|
585
610
|
writeln!(out, "{}}}\n", indent).unwrap();
|
|
@@ -1076,12 +1101,24 @@ impl CSharpCodegen {
|
|
|
1076
1101
|
|
|
1077
1102
|
// Collect fields and parameters
|
|
1078
1103
|
if s.fields.is_empty() {
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1104
|
+
if self.options.emit_validation {
|
|
1105
|
+
writeln!(
|
|
1106
|
+
out,
|
|
1107
|
+
"{}public {} {}{}",
|
|
1108
|
+
indent, record_keyword, struct_name, implements_str
|
|
1109
|
+
)
|
|
1110
|
+
.unwrap();
|
|
1111
|
+
writeln!(out, "{}{{", indent).unwrap();
|
|
1112
|
+
self.emit_struct_validator(out, s, &prop_names, indent);
|
|
1113
|
+
writeln!(out, "{}}}", indent).unwrap();
|
|
1114
|
+
} else {
|
|
1115
|
+
writeln!(
|
|
1116
|
+
out,
|
|
1117
|
+
"{}public {} {}{};",
|
|
1118
|
+
indent, record_keyword, struct_name, implements_str
|
|
1119
|
+
)
|
|
1120
|
+
.unwrap();
|
|
1121
|
+
}
|
|
1085
1122
|
writeln!(out).unwrap();
|
|
1086
1123
|
return;
|
|
1087
1124
|
}
|
|
@@ -379,8 +379,12 @@ impl GoCodegen {
|
|
|
379
379
|
.values()
|
|
380
380
|
.any(|def| matches!(def, TypeDef::Union(u) if u.is_lexical()))
|
|
381
381
|
{
|
|
382
|
-
|
|
383
|
-
|
|
382
|
+
if body.contains("strconv.") {
|
|
383
|
+
imports.push("\"strconv\"");
|
|
384
|
+
}
|
|
385
|
+
if body.contains("strings.") {
|
|
386
|
+
imports.push("\"strings\"");
|
|
387
|
+
}
|
|
384
388
|
}
|
|
385
389
|
if has_time {
|
|
386
390
|
imports.push("\"time\"");
|
|
@@ -765,6 +769,11 @@ impl GoCodegen {
|
|
|
765
769
|
for (branch, field) in u.branches.iter().zip(&fields) {
|
|
766
770
|
let mapped = self.context.map_type_ref(&branch.type_ref);
|
|
767
771
|
if let TypeRef::Named(qname) = &branch.type_ref {
|
|
772
|
+
if matches!(ir.types.get(qname), Some(TypeDef::Union(inner)) if inner.is_lexical())
|
|
773
|
+
{
|
|
774
|
+
let _ = writeln!(out, " {{ var escaped strings.Builder; if err := xml.EscapeText(&escaped, []byte(value)); err != nil {{ return err }}; var v {mapped}; if err := xml.Unmarshal([]byte(\"<v>\"+escaped.String()+\"</v>\"), &v); err == nil {{ c.{field} = &v; return nil }} }}");
|
|
775
|
+
continue;
|
|
776
|
+
}
|
|
768
777
|
if let Some(TypeDef::Enum(def)) = ir.types.get(qname) {
|
|
769
778
|
let comparisons = def
|
|
770
779
|
.variants
|
|
@@ -861,6 +870,11 @@ impl GoCodegen {
|
|
|
861
870
|
);
|
|
862
871
|
out.push_str(" count := 0\n var value string\n");
|
|
863
872
|
for (branch, field) in u.branches.iter().zip(&fields) {
|
|
873
|
+
if matches!(&branch.type_ref, TypeRef::Named(qname) if matches!(ir.types.get(qname), Some(TypeDef::Union(inner)) if inner.is_lexical()))
|
|
874
|
+
{
|
|
875
|
+
let _ = writeln!(out, " if c.{field} != nil {{ data, err := xml.Marshal(c.{field}); if err != nil {{ return err }}; if err := xml.Unmarshal(data, &value); err != nil {{ return err }}; count++ }}");
|
|
876
|
+
continue;
|
|
877
|
+
}
|
|
864
878
|
let expr = if matches!(
|
|
865
879
|
super::primitive_base(&branch.type_ref, ir),
|
|
866
880
|
TypeRef::Primitive(PrimitiveType::Date)
|
|
@@ -1264,10 +1278,15 @@ impl GoCodegen {
|
|
|
1264
1278
|
}
|
|
1265
1279
|
|
|
1266
1280
|
writeln!(out, "// Root XML Element Type Aliases").unwrap();
|
|
1281
|
+
let mut declared: HashSet<String> = ir
|
|
1282
|
+
.types
|
|
1283
|
+
.values()
|
|
1284
|
+
.map(|def| type_ident(def.qname()))
|
|
1285
|
+
.collect();
|
|
1267
1286
|
for elem in ir.elements.values() {
|
|
1268
1287
|
let elem_alias = to_go_type_name(&elem.qname.local);
|
|
1269
1288
|
let target_type = self.context.map_type_ref(&elem.type_ref);
|
|
1270
|
-
if elem_alias != target_type {
|
|
1289
|
+
if elem_alias != target_type && declared.insert(elem_alias.clone()) {
|
|
1271
1290
|
if let Some(ref doc) = elem.documentation {
|
|
1272
1291
|
for line in doc.lines() {
|
|
1273
1292
|
let trimmed = line.trim();
|
|
@@ -24,6 +24,16 @@ pub use python::{
|
|
|
24
24
|
pub use rust::{RustCodegen, RustOptions};
|
|
25
25
|
pub use typescript::{TypeScriptBackend, TypeScriptCodegen, TypeScriptOptions};
|
|
26
26
|
|
|
27
|
+
/// Prefix every physical XSD documentation line so embedded newlines cannot
|
|
28
|
+
/// escape a generated source comment.
|
|
29
|
+
pub(crate) fn write_documentation_lines(out: &mut String, prefix: &str, doc: &str) {
|
|
30
|
+
for line in doc.trim().lines() {
|
|
31
|
+
out.push_str(prefix);
|
|
32
|
+
out.push_str(line.trim_end_matches('\r'));
|
|
33
|
+
out.push('\n');
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
27
37
|
use crate::ir::{FieldDef, PrimitiveType, QName, SchemaIR, StructDef, TypeRef};
|
|
28
38
|
|
|
29
39
|
#[derive(Debug, Error)]
|
|
@@ -6,7 +6,7 @@ use serde::{Deserialize, Serialize};
|
|
|
6
6
|
|
|
7
7
|
use crate::codegen::{
|
|
8
8
|
build_type_name_map, lookup_type_name, normalize_symbol_name, sanitize_keyword,
|
|
9
|
-
set_type_name_map, LanguageContext,
|
|
9
|
+
set_type_name_map, write_documentation_lines, LanguageContext,
|
|
10
10
|
};
|
|
11
11
|
use crate::ir::{
|
|
12
12
|
EnumDef, FieldDef, FieldKind, PrimitiveType, QName, RestrictionFacets, SchemaIR, SimpleTypeDef,
|
|
@@ -32,6 +32,15 @@ const PATTERN_VALIDATOR_HELPER: &str = r#"def _polyxml_patterns(*patterns: str):
|
|
|
32
32
|
pub mod aot;
|
|
33
33
|
pub use aot::{PythonAotCodegen, PythonAotCrate, PythonAotOptions};
|
|
34
34
|
|
|
35
|
+
fn write_python_docstring(out: &mut String, indent: &str, doc: &str) {
|
|
36
|
+
let escaped = doc
|
|
37
|
+
.trim()
|
|
38
|
+
.replace('\\', "\\\\")
|
|
39
|
+
.replace("\"\"\"", "\\\"\\\"\\\"")
|
|
40
|
+
.replace('\r', "");
|
|
41
|
+
let _ = writeln!(out, "{indent}\"\"\"{escaped}\"\"\"");
|
|
42
|
+
}
|
|
43
|
+
|
|
35
44
|
/// Target backend for Python code emission.
|
|
36
45
|
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default, Serialize, Deserialize)]
|
|
37
46
|
pub enum PythonBackend {
|
|
@@ -444,7 +453,7 @@ impl PythonCodegen {
|
|
|
444
453
|
let base_type = self.context.map_type_ref(&s.base_type);
|
|
445
454
|
|
|
446
455
|
if let Some(ref doc) = s.documentation {
|
|
447
|
-
|
|
456
|
+
write_documentation_lines(out, "# ", doc);
|
|
448
457
|
}
|
|
449
458
|
|
|
450
459
|
if self.options.backend == PythonBackend::Pydantic && !s.facets.is_empty() {
|
|
@@ -492,7 +501,7 @@ impl PythonCodegen {
|
|
|
492
501
|
let _ = writeln!(out, "class {}(StrEnum):", enum_name);
|
|
493
502
|
|
|
494
503
|
if let Some(ref doc) = e.documentation {
|
|
495
|
-
|
|
504
|
+
write_python_docstring(out, " ", doc);
|
|
496
505
|
}
|
|
497
506
|
|
|
498
507
|
if e.variants.is_empty() {
|
|
@@ -549,7 +558,7 @@ impl PythonCodegen {
|
|
|
549
558
|
}
|
|
550
559
|
|
|
551
560
|
if let Some(ref doc) = u.documentation {
|
|
552
|
-
|
|
561
|
+
write_documentation_lines(out, "# ", doc);
|
|
553
562
|
}
|
|
554
563
|
|
|
555
564
|
if u.branches.is_empty() {
|
|
@@ -613,7 +622,8 @@ impl PythonCodegen {
|
|
|
613
622
|
let mut has_body = false;
|
|
614
623
|
|
|
615
624
|
if let Some(ref doc) = s.documentation {
|
|
616
|
-
|
|
625
|
+
write_python_docstring(out, " ", doc);
|
|
626
|
+
out.push('\n');
|
|
617
627
|
has_body = true;
|
|
618
628
|
}
|
|
619
629
|
|
|
@@ -763,7 +773,7 @@ impl PythonCodegen {
|
|
|
763
773
|
};
|
|
764
774
|
|
|
765
775
|
if let Some(ref doc) = field.documentation {
|
|
766
|
-
|
|
776
|
+
write_documentation_lines(out, " # ", doc);
|
|
767
777
|
}
|
|
768
778
|
|
|
769
779
|
let _ = writeln!(out, " {}: {} = {}", py_name, field_type, field_call);
|
|
@@ -6,7 +6,7 @@ use serde::{Deserialize, Serialize};
|
|
|
6
6
|
|
|
7
7
|
use crate::codegen::{
|
|
8
8
|
build_type_name_map, flatten_fields, lookup_type_name, primitive_base, sanitize_keyword,
|
|
9
|
-
set_type_name_map, LanguageContext,
|
|
9
|
+
set_type_name_map, write_documentation_lines, LanguageContext,
|
|
10
10
|
};
|
|
11
11
|
use crate::ir::{
|
|
12
12
|
EnumDef, FieldDef, FieldKind, PrimitiveType, QName, SchemaIR, SimpleTypeDef, StructDef,
|
|
@@ -279,7 +279,10 @@ impl RustCodegen {
|
|
|
279
279
|
self.emit_pymodule(&mut out, ir, &sorted_types);
|
|
280
280
|
}
|
|
281
281
|
|
|
282
|
-
|
|
282
|
+
// A field may use a raw identifier such as `r#type`. Local codec
|
|
283
|
+
// variables have a `var_` prefix, so the raw marker is neither needed
|
|
284
|
+
// nor valid there (`var_r#type` is not a Rust identifier).
|
|
285
|
+
out.replace("var_r#", "var_")
|
|
283
286
|
}
|
|
284
287
|
|
|
285
288
|
/// Fixed-point analysis determining which types in SchemaIR require a lifetime parameter `<'a>`.
|
|
@@ -456,7 +459,7 @@ impl RustCodegen {
|
|
|
456
459
|
let needs_lifetime = types_with_lifetime.contains(&s.qname);
|
|
457
460
|
|
|
458
461
|
if let Some(ref doc) = s.documentation {
|
|
459
|
-
|
|
462
|
+
write_documentation_lines(out, "/// ", doc);
|
|
460
463
|
}
|
|
461
464
|
|
|
462
465
|
let base_type = self.format_rust_type_ref(&s.base_type, types_with_lifetime);
|
|
@@ -482,7 +485,7 @@ impl RustCodegen {
|
|
|
482
485
|
let enum_name = type_ident(&e.qname);
|
|
483
486
|
|
|
484
487
|
if let Some(ref doc) = e.documentation {
|
|
485
|
-
|
|
488
|
+
write_documentation_lines(out, "/// ", doc);
|
|
486
489
|
}
|
|
487
490
|
|
|
488
491
|
let mut derives = vec!["Debug", "Clone", "Copy", "PartialEq", "Eq", "Hash"];
|
|
@@ -520,7 +523,7 @@ impl RustCodegen {
|
|
|
520
523
|
seen_variants.insert(var_id.clone());
|
|
521
524
|
|
|
522
525
|
if let Some(ref doc) = variant.documentation {
|
|
523
|
-
|
|
526
|
+
write_documentation_lines(out, " /// ", doc);
|
|
524
527
|
}
|
|
525
528
|
if self.options.derive_serde {
|
|
526
529
|
let _ = writeln!(out, " #[serde(rename = \"{}\")]", variant.value);
|
|
@@ -595,7 +598,7 @@ impl RustCodegen {
|
|
|
595
598
|
let needs_lifetime = types_with_lifetime.contains(&u.qname);
|
|
596
599
|
|
|
597
600
|
if let Some(ref doc) = u.documentation {
|
|
598
|
-
|
|
601
|
+
write_documentation_lines(out, "/// ", doc);
|
|
599
602
|
}
|
|
600
603
|
|
|
601
604
|
let mut derives = vec!["Debug", "Clone", "PartialEq"];
|
|
@@ -640,7 +643,7 @@ impl RustCodegen {
|
|
|
640
643
|
let branch_type = self.format_rust_type_ref(&branch.type_ref, types_with_lifetime);
|
|
641
644
|
|
|
642
645
|
if let Some(ref doc) = branch.documentation {
|
|
643
|
-
|
|
646
|
+
write_documentation_lines(out, " /// ", doc);
|
|
644
647
|
}
|
|
645
648
|
if self.options.derive_serde && !u.is_lexical() {
|
|
646
649
|
let _ = writeln!(out, " #[serde(rename = \"{}\")]", branch.xml_name);
|
|
@@ -685,7 +688,7 @@ impl RustCodegen {
|
|
|
685
688
|
let needs_lifetime = types_with_lifetime.contains(&s.qname);
|
|
686
689
|
|
|
687
690
|
if let Some(ref doc) = s.documentation {
|
|
688
|
-
|
|
691
|
+
write_documentation_lines(out, "/// ", doc);
|
|
689
692
|
}
|
|
690
693
|
|
|
691
694
|
let mut derives = vec!["Debug", "Clone", "PartialEq"];
|
|
@@ -763,7 +766,7 @@ impl RustCodegen {
|
|
|
763
766
|
has_boxed: bool,
|
|
764
767
|
) {
|
|
765
768
|
if let Some(ref doc) = field.documentation {
|
|
766
|
-
|
|
769
|
+
write_documentation_lines(out, " /// ", doc);
|
|
767
770
|
}
|
|
768
771
|
|
|
769
772
|
let is_list = field.cardinality.is_list() || field.type_ref.is_list();
|
|
@@ -599,11 +599,30 @@ impl TypeScriptCodegen {
|
|
|
599
599
|
self.emit_docstring(out, doc, "");
|
|
600
600
|
}
|
|
601
601
|
|
|
602
|
-
let
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
602
|
+
let base_name = s.base_type.as_ref().map(type_ident);
|
|
603
|
+
let mut inherited_fields = HashSet::new();
|
|
604
|
+
let mut current_base = s.base_type.as_ref();
|
|
605
|
+
let mut visited_bases = HashSet::new();
|
|
606
|
+
while let Some(base_qname) = current_base {
|
|
607
|
+
if !visited_bases.insert(base_qname.clone()) {
|
|
608
|
+
break;
|
|
609
|
+
}
|
|
610
|
+
let Some(TypeDef::Struct(base)) = ir.types.get(base_qname) else {
|
|
611
|
+
break;
|
|
612
|
+
};
|
|
613
|
+
let mut seen = HashSet::new();
|
|
614
|
+
for field in &base.fields {
|
|
615
|
+
inherited_fields.insert(self.unique_field_name(&field.name, &mut seen));
|
|
616
|
+
}
|
|
617
|
+
current_base = base.base_type.as_ref();
|
|
606
618
|
}
|
|
619
|
+
let mut own_seen = HashSet::new();
|
|
620
|
+
let overridden = s
|
|
621
|
+
.fields
|
|
622
|
+
.iter()
|
|
623
|
+
.map(|field| self.unique_field_name(&field.name, &mut own_seen))
|
|
624
|
+
.filter(|name| inherited_fields.contains(name))
|
|
625
|
+
.collect::<Vec<_>>();
|
|
607
626
|
|
|
608
627
|
let readonly_prefix = if self.options.readonly_fields {
|
|
609
628
|
"readonly "
|
|
@@ -611,13 +630,29 @@ impl TypeScriptCodegen {
|
|
|
611
630
|
""
|
|
612
631
|
};
|
|
613
632
|
|
|
614
|
-
if
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
633
|
+
if let Some(base_name) = &base_name {
|
|
634
|
+
if overridden.is_empty() {
|
|
635
|
+
if self.options.use_interface {
|
|
636
|
+
let _ = writeln!(out, "export interface {} extends {} {{", ts_name, base_name);
|
|
637
|
+
} else {
|
|
638
|
+
let _ = writeln!(out, "export type {} = {} & {{", ts_name, base_name);
|
|
639
|
+
}
|
|
640
|
+
} else {
|
|
641
|
+
let keys = overridden
|
|
642
|
+
.iter()
|
|
643
|
+
.map(|name| format!("{name:?}"))
|
|
644
|
+
.collect::<Vec<_>>()
|
|
645
|
+
.join(" | ");
|
|
646
|
+
let _ = writeln!(
|
|
647
|
+
out,
|
|
648
|
+
"export type {} = Omit<{}, {}> & {{",
|
|
649
|
+
ts_name, base_name, keys
|
|
650
|
+
);
|
|
651
|
+
}
|
|
652
|
+
} else if self.options.use_interface {
|
|
653
|
+
let _ = writeln!(out, "export interface {} {{", ts_name);
|
|
618
654
|
} else {
|
|
619
|
-
let
|
|
620
|
-
let _ = writeln!(out, "export type {} = {} & {{", ts_name, base_name);
|
|
655
|
+
let _ = writeln!(out, "export type {} = {{", ts_name);
|
|
621
656
|
}
|
|
622
657
|
|
|
623
658
|
let mut seen_fields = HashSet::new();
|
|
@@ -456,6 +456,9 @@ pub struct SchemaIR {
|
|
|
456
456
|
pub namespaces: Vec<NamespaceDeclaration>,
|
|
457
457
|
pub types: BTreeMap<QName, TypeDef>,
|
|
458
458
|
pub elements: BTreeMap<QName, ElementDef>,
|
|
459
|
+
/// Declared types of global attributes, used to resolve `<xs:attribute ref>`.
|
|
460
|
+
#[serde(default)]
|
|
461
|
+
pub attributes: BTreeMap<QName, TypeRef>,
|
|
459
462
|
pub substitution_groups: HashMap<QName, Vec<QName>>,
|
|
460
463
|
/// Type owners outside the module currently being emitted. Definitions
|
|
461
464
|
/// remain in `types` so generators can resolve their field semantics.
|