structurize 2.20.2__py3-none-any.whl → 2.20.4__py3-none-any.whl
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.
- avrotize/__init__.py +2 -0
- avrotize/_version.py +3 -3
- avrotize/avrotocsharp.py +121 -16
- avrotize/avrotots.py +2 -2
- avrotize/commands.json +168 -9
- avrotize/constants.py +15 -0
- avrotize/jsonstostructure.py +234 -12
- avrotize/openapitostructure.py +717 -0
- avrotize/structuretojs.py +657 -0
- avrotize/structuretots.py +26 -2
- {structurize-2.20.2.dist-info → structurize-2.20.4.dist-info}/METADATA +1 -1
- {structurize-2.20.2.dist-info → structurize-2.20.4.dist-info}/RECORD +16 -14
- {structurize-2.20.2.dist-info → structurize-2.20.4.dist-info}/WHEEL +0 -0
- {structurize-2.20.2.dist-info → structurize-2.20.4.dist-info}/entry_points.txt +0 -0
- {structurize-2.20.2.dist-info → structurize-2.20.4.dist-info}/licenses/LICENSE +0 -0
- {structurize-2.20.2.dist-info → structurize-2.20.4.dist-info}/top_level.txt +0 -0
avrotize/__init__.py
CHANGED
|
@@ -56,6 +56,8 @@ _mappings = {
|
|
|
56
56
|
"convert_avro_to_rust": (f"{mod}.avrotorust", "convert_avro_to_rust"),
|
|
57
57
|
"convert_avro_schema_to_rust": (f"{mod}.avrotorust", "convert_avro_schema_to_rust"),
|
|
58
58
|
"convert_avro_to_datapackage": (f"{mod}.avrotodatapackage", "convert_avro_to_datapackage"),
|
|
59
|
+
"convert_structure_to_javascript": (f"{mod}.structuretojs", "convert_structure_to_javascript"),
|
|
60
|
+
"convert_structure_schema_to_javascript": (f"{mod}.structuretojs", "convert_structure_schema_to_javascript"),
|
|
59
61
|
}
|
|
60
62
|
|
|
61
63
|
_lazy_loader = LazyLoader(_mappings)
|
avrotize/_version.py
CHANGED
|
@@ -28,7 +28,7 @@ version_tuple: VERSION_TUPLE
|
|
|
28
28
|
commit_id: COMMIT_ID
|
|
29
29
|
__commit_id__: COMMIT_ID
|
|
30
30
|
|
|
31
|
-
__version__ = version = '2.20.
|
|
32
|
-
__version_tuple__ = version_tuple = (2, 20,
|
|
31
|
+
__version__ = version = '2.20.4'
|
|
32
|
+
__version_tuple__ = version_tuple = (2, 20, 4)
|
|
33
33
|
|
|
34
|
-
__commit_id__ = commit_id = '
|
|
34
|
+
__commit_id__ = commit_id = 'gadd3e447a'
|
avrotize/avrotocsharp.py
CHANGED
|
@@ -14,9 +14,12 @@ from avrotize.constants import (
|
|
|
14
14
|
NEWTONSOFT_JSON_VERSION,
|
|
15
15
|
SYSTEM_TEXT_JSON_VERSION,
|
|
16
16
|
SYSTEM_MEMORY_DATA_VERSION,
|
|
17
|
+
PROTOBUF_NET_VERSION,
|
|
18
|
+
MSGPACK_VERSION,
|
|
17
19
|
NUNIT_VERSION,
|
|
18
20
|
NUNIT_ADAPTER_VERSION,
|
|
19
21
|
MSTEST_SDK_VERSION,
|
|
22
|
+
COVERLET_VERSION,
|
|
20
23
|
)
|
|
21
24
|
import glob
|
|
22
25
|
|
|
@@ -49,7 +52,9 @@ class AvroToCSharp:
|
|
|
49
52
|
self.system_text_json_annotation = False
|
|
50
53
|
self.newtonsoft_json_annotation = False
|
|
51
54
|
self.system_xml_annotation = False
|
|
55
|
+
self.msgpack_annotation = False
|
|
52
56
|
self.avro_annotation = False
|
|
57
|
+
self.protobuf_net_annotation = False
|
|
53
58
|
self.generated_types: Dict[str,str] = {}
|
|
54
59
|
self.generated_avro_types: Dict[str, Dict[str, Union[str, Dict, List]]] = {}
|
|
55
60
|
self.type_dict: Dict[str, Dict] = {}
|
|
@@ -177,7 +182,14 @@ class AvroToCSharp:
|
|
|
177
182
|
else:
|
|
178
183
|
class_definition += f"[XmlRoot(\"{class_name}\")]\n"
|
|
179
184
|
|
|
180
|
-
|
|
185
|
+
if self.protobuf_net_annotation:
|
|
186
|
+
class_definition += "[ProtoContract]\n"
|
|
187
|
+
|
|
188
|
+
# Add MessagePack serialization attribute for the class if enabled
|
|
189
|
+
if self.msgpack_annotation:
|
|
190
|
+
class_definition += "[MessagePackObject]\n"
|
|
191
|
+
|
|
192
|
+
fields_str = [self.generate_property(index + 1, field, class_name, avro_namespace) for index, field in enumerate(avro_schema.get('fields', []))]
|
|
181
193
|
class_body = "\n".join(fields_str)
|
|
182
194
|
class_definition += f"public partial class {class_name}"
|
|
183
195
|
if self.avro_annotation:
|
|
@@ -250,9 +262,11 @@ class AvroToCSharp:
|
|
|
250
262
|
"avrotocsharp/dataclass_core.jinja",
|
|
251
263
|
class_name=class_name,
|
|
252
264
|
avro_annotation=self.avro_annotation,
|
|
265
|
+
protobuf_net_annotation=self.protobuf_net_annotation,
|
|
253
266
|
system_text_json_annotation=self.system_text_json_annotation,
|
|
254
267
|
newtonsoft_json_annotation=self.newtonsoft_json_annotation,
|
|
255
|
-
system_xml_annotation=self.system_xml_annotation,
|
|
268
|
+
system_xml_annotation=self.system_xml_annotation,
|
|
269
|
+
msgpack_annotation=self.msgpack_annotation,
|
|
256
270
|
json_match_clauses=self.create_is_json_match_clauses(avro_schema, avro_namespace, class_name)
|
|
257
271
|
)
|
|
258
272
|
|
|
@@ -516,14 +530,19 @@ class AvroToCSharp:
|
|
|
516
530
|
union_type_name = union_type.rsplit('.', 1)[-1]
|
|
517
531
|
if self.is_csharp_reserved_word(union_type_name):
|
|
518
532
|
union_type_name = f"@{union_type_name}"
|
|
533
|
+
proto_member_name = union_type_name[1:] if union_type_name.startswith("@") else union_type_name
|
|
519
534
|
class_definition_objctr += f"{INDENT*3}if (obj is {union_type})\n{INDENT*3}{{\n{INDENT*4}self.{union_type_name} = ({union_type})obj;\n{INDENT*4}return self;\n{INDENT*3}}}\n"
|
|
520
535
|
if union_type in self.generated_types and self.generated_types[union_type] == "class":
|
|
521
536
|
class_definition_genericrecordctor += f"{INDENT*3}if (obj.Schema.Fullname == {union_type}.AvroSchema.Fullname)\n{INDENT*3}{{\n{INDENT*4}this.{union_type_name} = new {union_type}(obj);\n{INDENT*4}return;\n{INDENT*3}}}\n"
|
|
522
537
|
class_definition_ctors += \
|
|
523
538
|
f"{INDENT*2}/// <summary>\n{INDENT*2}/// Constructor for {union_type_name} values\n{INDENT*2}/// </summary>\n" + \
|
|
524
539
|
f"{INDENT*2}public {union_class_name}({union_type}? {union_type_name})\n{INDENT*2}{{\n{INDENT*3}this.{union_type_name} = {union_type_name};\n{INDENT*2}}}\n"
|
|
540
|
+
# Add Key attribute for MessagePack serialization if enabled
|
|
541
|
+
msgpack_key_attr = f"{INDENT*2}[Key({i})]\n" if self.msgpack_annotation else ""
|
|
525
542
|
class_definition_decls += \
|
|
526
543
|
f"{INDENT*2}/// <summary>\n{INDENT*2}/// Gets the {union_type_name} value\n{INDENT*2}/// </summary>\n" + \
|
|
544
|
+
(f"{INDENT*2}[ProtoMember({i+1}, Name=\"{proto_member_name}\")]\n" if self.protobuf_net_annotation else "") + \
|
|
545
|
+
msgpack_key_attr + \
|
|
527
546
|
f"{INDENT*2}public {union_type}? {union_type_name} {{ get; set; }} = null;\n"
|
|
528
547
|
class_definition_toobject += f"{INDENT*3}if ({union_type_name} != null) {{\n{INDENT*4}return {union_type_name};\n{INDENT*3}}}\n"
|
|
529
548
|
|
|
@@ -570,9 +589,14 @@ class AvroToCSharp:
|
|
|
570
589
|
if self.system_xml_annotation:
|
|
571
590
|
class_definition += \
|
|
572
591
|
f"{INDENT}[XmlRoot(\"{union_class_name}\")]\n"
|
|
592
|
+
if self.msgpack_annotation:
|
|
593
|
+
class_definition += \
|
|
594
|
+
f"{INDENT}[MessagePackObject]\n"
|
|
573
595
|
if self.system_text_json_annotation:
|
|
574
596
|
class_definition += \
|
|
575
597
|
f"{INDENT}[System.Text.Json.Serialization.JsonConverter(typeof({union_class_name}))]\n"
|
|
598
|
+
if self.protobuf_net_annotation:
|
|
599
|
+
class_definition += f"{INDENT}[ProtoContract]\n"
|
|
576
600
|
class_definition += \
|
|
577
601
|
f"{INDENT}public sealed class {union_class_name}"
|
|
578
602
|
if self.system_text_json_annotation:
|
|
@@ -697,6 +721,8 @@ class AvroToCSharp:
|
|
|
697
721
|
def is_enum_type(self, avro_type: Union[str, Dict, List]) -> bool:
|
|
698
722
|
""" Checks if a type is an enum (including nullable enums) """
|
|
699
723
|
if isinstance(avro_type, str):
|
|
724
|
+
if avro_type in ('null', 'boolean', 'int', 'long', 'float', 'double', 'bytes', 'string'):
|
|
725
|
+
return False
|
|
700
726
|
schema = self.schema_doc
|
|
701
727
|
name = avro_type.split('.')[-1]
|
|
702
728
|
namespace = ".".join(avro_type.split('.')[:-1])
|
|
@@ -711,7 +737,7 @@ class AvroToCSharp:
|
|
|
711
737
|
return avro_type.get('type') == 'enum'
|
|
712
738
|
return False
|
|
713
739
|
|
|
714
|
-
def generate_property(self, field: Dict, class_name: str, parent_namespace: str) -> str:
|
|
740
|
+
def generate_property(self, field_index: int, field: Dict, class_name: str, parent_namespace: str) -> str:
|
|
715
741
|
""" Generates a property """
|
|
716
742
|
is_enum_type = self.is_enum_type(field['type'])
|
|
717
743
|
field_type = self.convert_avro_type_to_csharp(
|
|
@@ -727,6 +753,9 @@ class AvroToCSharp:
|
|
|
727
753
|
prop = ''
|
|
728
754
|
prop += f"{INDENT}/// <summary>\n{INDENT}/// { field.get('doc', field_name) }\n{INDENT}/// </summary>\n"
|
|
729
755
|
|
|
756
|
+
if self.protobuf_net_annotation:
|
|
757
|
+
prop += f"{INDENT}[ProtoMember({field_index}, Name=\"{annotation_name}\")]\n"
|
|
758
|
+
|
|
730
759
|
# Add XML serialization attribute if enabled
|
|
731
760
|
if self.system_xml_annotation:
|
|
732
761
|
xmlkind = field.get('xmlkind', 'element')
|
|
@@ -735,6 +764,10 @@ class AvroToCSharp:
|
|
|
735
764
|
elif xmlkind == 'attribute':
|
|
736
765
|
prop += f"{INDENT}[XmlAttribute(\"{annotation_name}\")]\n"
|
|
737
766
|
|
|
767
|
+
# Add MessagePack serialization attribute if enabled
|
|
768
|
+
if self.msgpack_annotation:
|
|
769
|
+
prop += f"{INDENT}[Key({field_index})]\n"
|
|
770
|
+
|
|
738
771
|
if self.system_text_json_annotation:
|
|
739
772
|
prop += f"{INDENT}[System.Text.Json.Serialization.JsonPropertyName(\"{annotation_name}\")]\n"
|
|
740
773
|
if is_enum_type:
|
|
@@ -743,6 +776,8 @@ class AvroToCSharp:
|
|
|
743
776
|
prop += f"{INDENT}[System.Text.Json.Serialization.JsonConverter(typeof({field_type}))]\n"
|
|
744
777
|
if self.newtonsoft_json_annotation:
|
|
745
778
|
prop += f"{INDENT}[Newtonsoft.Json.JsonProperty(\"{annotation_name}\")]\n"
|
|
779
|
+
if is_enum_type:
|
|
780
|
+
prop += f"{INDENT}[Newtonsoft.Json.JsonConverter(typeof(Newtonsoft.Json.Converters.StringEnumConverter))]\n"
|
|
746
781
|
|
|
747
782
|
# Determine initialization value
|
|
748
783
|
initialization = ""
|
|
@@ -785,6 +820,8 @@ class AvroToCSharp:
|
|
|
785
820
|
# Common using statements (add more as needed)
|
|
786
821
|
file_content = "using System;\nusing System.Collections.Generic;\n"
|
|
787
822
|
file_content += "using System.Linq;\n"
|
|
823
|
+
if self.protobuf_net_annotation:
|
|
824
|
+
file_content += "using ProtoBuf;\n"
|
|
788
825
|
if self.system_text_json_annotation:
|
|
789
826
|
file_content += "using System.Text.Json;\n"
|
|
790
827
|
file_content += "using System.Text.Json.Serialization;\n"
|
|
@@ -792,6 +829,8 @@ class AvroToCSharp:
|
|
|
792
829
|
file_content += "using Newtonsoft.Json;\n"
|
|
793
830
|
if self.system_xml_annotation: # Add XML serialization using directive
|
|
794
831
|
file_content += "using System.Xml.Serialization;\n"
|
|
832
|
+
if self.msgpack_annotation: # Add MessagePack serialization using directive
|
|
833
|
+
file_content += "using MessagePack;\n"
|
|
795
834
|
|
|
796
835
|
if namespace:
|
|
797
836
|
# Namespace declaration with correct indentation for the definition
|
|
@@ -833,7 +872,9 @@ class AvroToCSharp:
|
|
|
833
872
|
avro_annotation=self.avro_annotation,
|
|
834
873
|
system_xml_annotation=self.system_xml_annotation,
|
|
835
874
|
system_text_json_annotation=self.system_text_json_annotation,
|
|
836
|
-
newtonsoft_json_annotation=self.newtonsoft_json_annotation
|
|
875
|
+
newtonsoft_json_annotation=self.newtonsoft_json_annotation,
|
|
876
|
+
protobuf_net_annotation=self.protobuf_net_annotation,
|
|
877
|
+
msgpack_annotation=self.msgpack_annotation
|
|
837
878
|
)
|
|
838
879
|
elif type_kind == "enum":
|
|
839
880
|
test_class_definition = process_template(
|
|
@@ -845,7 +886,8 @@ class AvroToCSharp:
|
|
|
845
886
|
avro_annotation=self.avro_annotation,
|
|
846
887
|
system_xml_annotation=self.system_xml_annotation,
|
|
847
888
|
system_text_json_annotation=self.system_text_json_annotation,
|
|
848
|
-
newtonsoft_json_annotation=self.newtonsoft_json_annotation
|
|
889
|
+
newtonsoft_json_annotation=self.newtonsoft_json_annotation,
|
|
890
|
+
protobuf_net_annotation=self.protobuf_net_annotation
|
|
849
891
|
)
|
|
850
892
|
|
|
851
893
|
test_file_path = os.path.join(test_directory_path, f"{test_class_name}.cs")
|
|
@@ -856,13 +898,14 @@ class AvroToCSharp:
|
|
|
856
898
|
""" Retrieves fields for a given class name """
|
|
857
899
|
|
|
858
900
|
class Field:
|
|
859
|
-
def __init__(self, fn: str, ft:str, tv:Any, ct: bool, pm: bool, ie: bool):
|
|
901
|
+
def __init__(self, fn: str, ft:str, tv:Any, ct: bool, pm: bool, ie: bool, iu: bool):
|
|
860
902
|
self.field_name = fn
|
|
861
903
|
self.field_type = ft
|
|
862
904
|
self.test_value = tv
|
|
863
905
|
self.is_const = ct
|
|
864
906
|
self.is_primitive = pm
|
|
865
907
|
self.is_enum = ie
|
|
908
|
+
self.is_union = iu
|
|
866
909
|
|
|
867
910
|
fields: List[Field] = []
|
|
868
911
|
if avro_schema and 'fields' in avro_schema:
|
|
@@ -877,16 +920,19 @@ class AvroToCSharp:
|
|
|
877
920
|
field_type = self.convert_avro_type_to_csharp(class_name, field_name, field['type'], str(avro_schema.get('namespace', '')))
|
|
878
921
|
is_class = field_type in self.generated_types and self.generated_types[field_type] == "class"
|
|
879
922
|
is_enum = self.is_enum_type(field['type'])
|
|
923
|
+
is_union = field_type in self.generated_types and self.generated_types[field_type] == "union"
|
|
924
|
+
test_value = self.get_test_value(field_type, field['type'], str(avro_schema.get('namespace', ''))) if not "const" in field else '\"'+str(field["const"])+'\"'
|
|
880
925
|
f = Field(field_name,
|
|
881
926
|
field_type,
|
|
882
|
-
|
|
927
|
+
test_value,
|
|
883
928
|
"const" in field and field["const"] is not None,
|
|
884
929
|
not is_class,
|
|
885
|
-
is_enum
|
|
930
|
+
is_enum,
|
|
931
|
+
is_union)
|
|
886
932
|
fields.append(f)
|
|
887
933
|
return cast(List[Any], fields)
|
|
888
934
|
|
|
889
|
-
def get_test_value(self, csharp_type: str) -> str:
|
|
935
|
+
def get_test_value(self, csharp_type: str, avro_type: JsonNode = None, parent_namespace: str = '') -> str:
|
|
890
936
|
"""Returns a default test value based on the Avro type"""
|
|
891
937
|
# For nullable object types, return typed null to avoid var issues
|
|
892
938
|
if csharp_type == "object?":
|
|
@@ -908,6 +954,19 @@ class AvroToCSharp:
|
|
|
908
954
|
}
|
|
909
955
|
if csharp_type.endswith('?'):
|
|
910
956
|
csharp_type = csharp_type[:-1]
|
|
957
|
+
|
|
958
|
+
# Check if this is a union type (either by generated_types lookup or by type structure)
|
|
959
|
+
if csharp_type in self.generated_types and self.generated_types[csharp_type] == "union":
|
|
960
|
+
# For union types, we need to initialize with one of the valid options
|
|
961
|
+
# Find the first non-null type in the union and create a value for it
|
|
962
|
+
if isinstance(avro_type, list):
|
|
963
|
+
non_null_types = [t for t in avro_type if t != 'null']
|
|
964
|
+
if non_null_types:
|
|
965
|
+
first_option = non_null_types[0]
|
|
966
|
+
first_option_csharp = self.convert_avro_type_to_csharp('', 'Option0', first_option, parent_namespace)
|
|
967
|
+
first_option_value = self.get_test_value(first_option_csharp, first_option, parent_namespace)
|
|
968
|
+
return f'new {csharp_type}({first_option_value})'
|
|
969
|
+
|
|
911
970
|
return test_values.get(csharp_type, f'new {csharp_type}()')
|
|
912
971
|
|
|
913
972
|
def convert_schema(self, schema: JsonNode, output_dir: str):
|
|
@@ -967,10 +1026,14 @@ class AvroToCSharp:
|
|
|
967
1026
|
system_xml_annotation=self.system_xml_annotation,
|
|
968
1027
|
system_text_json_annotation=self.system_text_json_annotation,
|
|
969
1028
|
newtonsoft_json_annotation=self.newtonsoft_json_annotation,
|
|
1029
|
+
protobuf_net_annotation=self.protobuf_net_annotation,
|
|
1030
|
+
msgpack_annotation=self.msgpack_annotation,
|
|
970
1031
|
CSHARP_AVRO_VERSION=CSHARP_AVRO_VERSION,
|
|
971
1032
|
NEWTONSOFT_JSON_VERSION=NEWTONSOFT_JSON_VERSION,
|
|
972
1033
|
SYSTEM_TEXT_JSON_VERSION=SYSTEM_TEXT_JSON_VERSION,
|
|
973
1034
|
SYSTEM_MEMORY_DATA_VERSION=SYSTEM_MEMORY_DATA_VERSION,
|
|
1035
|
+
PROTOBUF_NET_VERSION=PROTOBUF_NET_VERSION,
|
|
1036
|
+
MSGPACK_VERSION=MSGPACK_VERSION,
|
|
974
1037
|
NUNIT_VERSION=NUNIT_VERSION,
|
|
975
1038
|
NUNIT_ADAPTER_VERSION=NUNIT_ADAPTER_VERSION,
|
|
976
1039
|
MSTEST_SDK_VERSION=MSTEST_SDK_VERSION))
|
|
@@ -988,9 +1051,39 @@ class AvroToCSharp:
|
|
|
988
1051
|
system_xml_annotation=self.system_xml_annotation,
|
|
989
1052
|
system_text_json_annotation=self.system_text_json_annotation,
|
|
990
1053
|
newtonsoft_json_annotation=self.newtonsoft_json_annotation,
|
|
1054
|
+
protobuf_net_annotation=self.protobuf_net_annotation,
|
|
991
1055
|
NUNIT_VERSION=NUNIT_VERSION,
|
|
992
1056
|
NUNIT_ADAPTER_VERSION=NUNIT_ADAPTER_VERSION,
|
|
993
|
-
MSTEST_SDK_VERSION=MSTEST_SDK_VERSION
|
|
1057
|
+
MSTEST_SDK_VERSION=MSTEST_SDK_VERSION,
|
|
1058
|
+
COVERLET_VERSION=COVERLET_VERSION))
|
|
1059
|
+
|
|
1060
|
+
# Generate coverage scripts
|
|
1061
|
+
if not os.path.exists(os.path.join(output_dir, "run_coverage.ps1")):
|
|
1062
|
+
coverage_ps1_file = os.path.join(output_dir, "run_coverage.ps1")
|
|
1063
|
+
with open(coverage_ps1_file, 'w', encoding='utf-8') as file:
|
|
1064
|
+
file.write(process_template(
|
|
1065
|
+
"avrotocsharp/run_coverage.ps1.jinja",
|
|
1066
|
+
project_name=project_name))
|
|
1067
|
+
|
|
1068
|
+
if not os.path.exists(os.path.join(output_dir, "run_coverage.sh")):
|
|
1069
|
+
coverage_sh_file = os.path.join(output_dir, "run_coverage.sh")
|
|
1070
|
+
with open(coverage_sh_file, 'w', encoding='utf-8') as file:
|
|
1071
|
+
file.write(process_template(
|
|
1072
|
+
"avrotocsharp/run_coverage.sh.jinja",
|
|
1073
|
+
project_name=project_name))
|
|
1074
|
+
# Make the shell script executable on Unix-like systems
|
|
1075
|
+
try:
|
|
1076
|
+
os.chmod(coverage_sh_file, 0o755)
|
|
1077
|
+
except:
|
|
1078
|
+
pass # Ignore on Windows
|
|
1079
|
+
|
|
1080
|
+
# Generate README with coverage documentation
|
|
1081
|
+
if not os.path.exists(os.path.join(output_dir, "README.md")):
|
|
1082
|
+
readme_file = os.path.join(output_dir, "README.md")
|
|
1083
|
+
with open(readme_file, 'w', encoding='utf-8') as file:
|
|
1084
|
+
file.write(process_template(
|
|
1085
|
+
"avrotocsharp/README.md.jinja",
|
|
1086
|
+
project_name=project_name))
|
|
994
1087
|
|
|
995
1088
|
self.output_dir = output_dir
|
|
996
1089
|
for avro_schema in (avs for avs in schema if isinstance(avs, dict)):
|
|
@@ -1012,8 +1105,10 @@ def convert_avro_to_csharp(
|
|
|
1012
1105
|
pascal_properties=False,
|
|
1013
1106
|
system_text_json_annotation=False,
|
|
1014
1107
|
newtonsoft_json_annotation=False,
|
|
1015
|
-
system_xml_annotation=False,
|
|
1016
|
-
|
|
1108
|
+
system_xml_annotation=False,
|
|
1109
|
+
msgpack_annotation=False,
|
|
1110
|
+
avro_annotation=False,
|
|
1111
|
+
protobuf_net_annotation=False
|
|
1017
1112
|
):
|
|
1018
1113
|
"""Converts Avro schema to C# classes
|
|
1019
1114
|
|
|
@@ -1026,7 +1121,9 @@ def convert_avro_to_csharp(
|
|
|
1026
1121
|
system_text_json_annotation (bool, optional): Use System.Text.Json annotations. Defaults to False.
|
|
1027
1122
|
newtonsoft_json_annotation (bool, optional): Use Newtonsoft.Json annotations. Defaults to False.
|
|
1028
1123
|
system_xml_annotation (bool, optional): Use System.Xml.Serialization annotations. Defaults to False.
|
|
1124
|
+
msgpack_annotation (bool, optional): Use MessagePack annotations. Defaults to False.
|
|
1029
1125
|
avro_annotation (bool, optional): Use Avro annotations. Defaults to False.
|
|
1126
|
+
protobuf_net_annotation (bool, optional): Use protobuf-net annotations. Defaults to False.
|
|
1030
1127
|
"""
|
|
1031
1128
|
|
|
1032
1129
|
if not base_namespace:
|
|
@@ -1036,8 +1133,10 @@ def convert_avro_to_csharp(
|
|
|
1036
1133
|
avrotocs.pascal_properties = pascal_properties
|
|
1037
1134
|
avrotocs.system_text_json_annotation = system_text_json_annotation
|
|
1038
1135
|
avrotocs.newtonsoft_json_annotation = newtonsoft_json_annotation
|
|
1039
|
-
avrotocs.system_xml_annotation = system_xml_annotation
|
|
1136
|
+
avrotocs.system_xml_annotation = system_xml_annotation
|
|
1137
|
+
avrotocs.msgpack_annotation = msgpack_annotation
|
|
1040
1138
|
avrotocs.avro_annotation = avro_annotation
|
|
1139
|
+
avrotocs.protobuf_net_annotation = protobuf_net_annotation
|
|
1041
1140
|
avrotocs.convert(avro_schema_path, cs_file_path)
|
|
1042
1141
|
|
|
1043
1142
|
|
|
@@ -1049,8 +1148,10 @@ def convert_avro_schema_to_csharp(
|
|
|
1049
1148
|
pascal_properties: bool = False,
|
|
1050
1149
|
system_text_json_annotation: bool = False,
|
|
1051
1150
|
newtonsoft_json_annotation: bool = False,
|
|
1052
|
-
system_xml_annotation: bool = False,
|
|
1053
|
-
|
|
1151
|
+
system_xml_annotation: bool = False,
|
|
1152
|
+
msgpack_annotation: bool = False,
|
|
1153
|
+
avro_annotation: bool = False,
|
|
1154
|
+
protobuf_net_annotation: bool = False
|
|
1054
1155
|
):
|
|
1055
1156
|
"""Converts Avro schema to C# classes
|
|
1056
1157
|
|
|
@@ -1063,13 +1164,17 @@ def convert_avro_schema_to_csharp(
|
|
|
1063
1164
|
system_text_json_annotation (bool, optional): Use System.Text.Json annotations. Defaults to False.
|
|
1064
1165
|
newtonsoft_json_annotation (bool, optional): Use Newtonsoft.Json annotations. Defaults to False.
|
|
1065
1166
|
system_xml_annotation (bool, optional): Use System.Xml.Serialization annotations. Defaults to False.
|
|
1167
|
+
msgpack_annotation (bool, optional): Use MessagePack annotations. Defaults to False.
|
|
1066
1168
|
avro_annotation (bool, optional): Use Avro annotations. Defaults to False.
|
|
1169
|
+
protobuf_net_annotation (bool, optional): Use protobuf-net annotations. Defaults to False.
|
|
1067
1170
|
"""
|
|
1068
1171
|
avrotocs = AvroToCSharp(base_namespace)
|
|
1069
1172
|
avrotocs.project_name = project_name
|
|
1070
1173
|
avrotocs.pascal_properties = pascal_properties
|
|
1071
1174
|
avrotocs.system_text_json_annotation = system_text_json_annotation
|
|
1072
1175
|
avrotocs.newtonsoft_json_annotation = newtonsoft_json_annotation
|
|
1073
|
-
avrotocs.system_xml_annotation = system_xml_annotation
|
|
1176
|
+
avrotocs.system_xml_annotation = system_xml_annotation
|
|
1177
|
+
avrotocs.msgpack_annotation = msgpack_annotation
|
|
1074
1178
|
avrotocs.avro_annotation = avro_annotation
|
|
1179
|
+
avrotocs.protobuf_net_annotation = protobuf_net_annotation
|
|
1075
1180
|
avrotocs.convert_schema(avro_schema, output_dir)
|
avrotize/avrotots.py
CHANGED
|
@@ -266,9 +266,9 @@ class AvroToTypeScript:
|
|
|
266
266
|
first_type = field_type.split('|')[0].strip()
|
|
267
267
|
return self.generate_test_value(first_type, is_enum)
|
|
268
268
|
|
|
269
|
-
# Handle enums - use first value (
|
|
269
|
+
# Handle enums - use first value with Object.values()
|
|
270
270
|
if is_enum:
|
|
271
|
-
return f'{field_type}
|
|
271
|
+
return f'Object.values({field_type})[0] as {field_type}'
|
|
272
272
|
|
|
273
273
|
# Handle primitive types
|
|
274
274
|
primitive_values = {
|
avrotize/commands.json
CHANGED
|
@@ -1070,7 +1070,10 @@
|
|
|
1070
1070
|
"emit_cloudevents_columns": "args.emit_cloudevents_columns"
|
|
1071
1071
|
}
|
|
1072
1072
|
},
|
|
1073
|
-
"extensions": [
|
|
1073
|
+
"extensions": [
|
|
1074
|
+
".struct.json",
|
|
1075
|
+
".json"
|
|
1076
|
+
],
|
|
1074
1077
|
"args": [
|
|
1075
1078
|
{
|
|
1076
1079
|
"name": "input",
|
|
@@ -1248,6 +1251,7 @@
|
|
|
1248
1251
|
"avro_schema_path": "input_file_path",
|
|
1249
1252
|
"cs_file_path": "output_file_path",
|
|
1250
1253
|
"avro_annotation": "args.avro_annotation",
|
|
1254
|
+
"protobuf_net_annotation": "args.protobuf_net_annotation",
|
|
1251
1255
|
"system_text_json_annotation": "args.system_text_json_annotation",
|
|
1252
1256
|
"newtonsoft_json_annotation": "args.newtonsoft_json_annotation",
|
|
1253
1257
|
"system_xml_annotation": "args.system_xml_annotation",
|
|
@@ -1291,6 +1295,13 @@
|
|
|
1291
1295
|
"default": false,
|
|
1292
1296
|
"required": false
|
|
1293
1297
|
},
|
|
1298
|
+
{
|
|
1299
|
+
"name": "--protobuf-net-annotation",
|
|
1300
|
+
"type": "bool",
|
|
1301
|
+
"help": "Use protobuf-net annotations",
|
|
1302
|
+
"default": false,
|
|
1303
|
+
"required": false
|
|
1304
|
+
},
|
|
1294
1305
|
{
|
|
1295
1306
|
"name": "--system_text_json_annotation",
|
|
1296
1307
|
"type": "bool",
|
|
@@ -1704,7 +1715,10 @@
|
|
|
1704
1715
|
"json_annotation": "args.json_annotation"
|
|
1705
1716
|
}
|
|
1706
1717
|
},
|
|
1707
|
-
"extensions": [
|
|
1718
|
+
"extensions": [
|
|
1719
|
+
".struct.json",
|
|
1720
|
+
".json"
|
|
1721
|
+
],
|
|
1708
1722
|
"args": [
|
|
1709
1723
|
{
|
|
1710
1724
|
"name": "input",
|
|
@@ -1754,7 +1768,10 @@
|
|
|
1754
1768
|
"csv_schema_path": "output_file_path"
|
|
1755
1769
|
}
|
|
1756
1770
|
},
|
|
1757
|
-
"extensions": [
|
|
1771
|
+
"extensions": [
|
|
1772
|
+
".struct.json",
|
|
1773
|
+
".json"
|
|
1774
|
+
],
|
|
1758
1775
|
"args": [
|
|
1759
1776
|
{
|
|
1760
1777
|
"name": "input",
|
|
@@ -1786,7 +1803,10 @@
|
|
|
1786
1803
|
"serde_annotation": "args.json_annotation"
|
|
1787
1804
|
}
|
|
1788
1805
|
},
|
|
1789
|
-
"extensions": [
|
|
1806
|
+
"extensions": [
|
|
1807
|
+
".struct.json",
|
|
1808
|
+
".json"
|
|
1809
|
+
],
|
|
1790
1810
|
"args": [
|
|
1791
1811
|
{
|
|
1792
1812
|
"name": "input",
|
|
@@ -1845,7 +1865,10 @@
|
|
|
1845
1865
|
"avro_annotation": "args.avro_annotation"
|
|
1846
1866
|
}
|
|
1847
1867
|
},
|
|
1848
|
-
"extensions": [
|
|
1868
|
+
"extensions": [
|
|
1869
|
+
".struct.json",
|
|
1870
|
+
".json"
|
|
1871
|
+
],
|
|
1849
1872
|
"args": [
|
|
1850
1873
|
{
|
|
1851
1874
|
"name": "input",
|
|
@@ -1905,7 +1928,10 @@
|
|
|
1905
1928
|
"jackson_annotation": "args.jackson_annotation"
|
|
1906
1929
|
}
|
|
1907
1930
|
},
|
|
1908
|
-
"extensions": [
|
|
1931
|
+
"extensions": [
|
|
1932
|
+
".struct.json",
|
|
1933
|
+
".json"
|
|
1934
|
+
],
|
|
1909
1935
|
"args": [
|
|
1910
1936
|
{
|
|
1911
1937
|
"name": "input",
|
|
@@ -1958,6 +1984,51 @@
|
|
|
1958
1984
|
}
|
|
1959
1985
|
]
|
|
1960
1986
|
},
|
|
1987
|
+
{
|
|
1988
|
+
"command": "s2js",
|
|
1989
|
+
"description": "Convert JSON Structure to JavaScript classes",
|
|
1990
|
+
"group": "2_ProgLanguages",
|
|
1991
|
+
"function": {
|
|
1992
|
+
"name": "avrotize.structuretojs.convert_structure_to_javascript",
|
|
1993
|
+
"args": {
|
|
1994
|
+
"structure_schema_path": "input_file_path",
|
|
1995
|
+
"js_file_path": "output_file_path",
|
|
1996
|
+
"package_name": "args.package",
|
|
1997
|
+
"avro_annotation": "args.avro_annotation"
|
|
1998
|
+
}
|
|
1999
|
+
},
|
|
2000
|
+
"extensions": [".struct.json", ".json"],
|
|
2001
|
+
"args": [
|
|
2002
|
+
{
|
|
2003
|
+
"name": "input",
|
|
2004
|
+
"type": "str",
|
|
2005
|
+
"nargs": "?",
|
|
2006
|
+
"help": "Path to the JSON Structure schema file (or read from stdin if omitted)",
|
|
2007
|
+
"required": false
|
|
2008
|
+
},
|
|
2009
|
+
{
|
|
2010
|
+
"name": "--out",
|
|
2011
|
+
"type": "str",
|
|
2012
|
+
"help": "Output path for the JavaScript classes",
|
|
2013
|
+
"required": true
|
|
2014
|
+
},
|
|
2015
|
+
{
|
|
2016
|
+
"name": "--package",
|
|
2017
|
+
"type": "str",
|
|
2018
|
+
"help": "JavaScript package name",
|
|
2019
|
+
"required": false
|
|
2020
|
+
},
|
|
2021
|
+
{
|
|
2022
|
+
"name": "--avro-annotation",
|
|
2023
|
+
"type": "bool",
|
|
2024
|
+
"help": "Add Avro binary serialization support",
|
|
2025
|
+
"default": false,
|
|
2026
|
+
"required": false
|
|
2027
|
+
}
|
|
2028
|
+
],
|
|
2029
|
+
"suggested_output_file_path": "{input_file_name}-js",
|
|
2030
|
+
"prompts": []
|
|
2031
|
+
},
|
|
1961
2032
|
{
|
|
1962
2033
|
"command": "s2go",
|
|
1963
2034
|
"description": "Convert JSON Structure to Go structs",
|
|
@@ -1974,7 +2045,10 @@
|
|
|
1974
2045
|
"package_username": "args.package_username"
|
|
1975
2046
|
}
|
|
1976
2047
|
},
|
|
1977
|
-
"extensions": [
|
|
2048
|
+
"extensions": [
|
|
2049
|
+
".struct.json",
|
|
2050
|
+
".json"
|
|
2051
|
+
],
|
|
1978
2052
|
"args": [
|
|
1979
2053
|
{
|
|
1980
2054
|
"name": "input",
|
|
@@ -3195,7 +3269,10 @@
|
|
|
3195
3269
|
"target_namespace": "args.namespace"
|
|
3196
3270
|
}
|
|
3197
3271
|
},
|
|
3198
|
-
"extensions": [
|
|
3272
|
+
"extensions": [
|
|
3273
|
+
".struct.json",
|
|
3274
|
+
".json"
|
|
3275
|
+
],
|
|
3199
3276
|
"args": [
|
|
3200
3277
|
{
|
|
3201
3278
|
"name": "input",
|
|
@@ -3237,7 +3314,10 @@
|
|
|
3237
3314
|
"cddl_file_path": "output_file_path"
|
|
3238
3315
|
}
|
|
3239
3316
|
},
|
|
3240
|
-
"extensions": [
|
|
3317
|
+
"extensions": [
|
|
3318
|
+
".struct.json",
|
|
3319
|
+
".json"
|
|
3320
|
+
],
|
|
3241
3321
|
"args": [
|
|
3242
3322
|
{
|
|
3243
3323
|
"name": "input",
|
|
@@ -3333,5 +3413,84 @@
|
|
|
3333
3413
|
"required": false
|
|
3334
3414
|
}
|
|
3335
3415
|
]
|
|
3416
|
+
},
|
|
3417
|
+
{
|
|
3418
|
+
"command": "oas2s",
|
|
3419
|
+
"description": "Convert OpenAPI 3.x document to JSON Structure",
|
|
3420
|
+
"group": "1_Schemas",
|
|
3421
|
+
"function": {
|
|
3422
|
+
"name": "avrotize.openapitostructure.convert_openapi_to_structure_files",
|
|
3423
|
+
"args": {
|
|
3424
|
+
"openapi_file_path": "input_file_path",
|
|
3425
|
+
"structure_schema_path": "output_file_path",
|
|
3426
|
+
"root_namespace": "args.namespace",
|
|
3427
|
+
"preserve_composition": "args.preserve_composition",
|
|
3428
|
+
"detect_discriminators": "args.detect_discriminators",
|
|
3429
|
+
"lift_inline_schemas": "args.lift_inline_schemas"
|
|
3430
|
+
}
|
|
3431
|
+
},
|
|
3432
|
+
"extensions": [
|
|
3433
|
+
".yaml",
|
|
3434
|
+
".yml",
|
|
3435
|
+
".json"
|
|
3436
|
+
],
|
|
3437
|
+
"args": [
|
|
3438
|
+
{
|
|
3439
|
+
"name": "input",
|
|
3440
|
+
"type": "str",
|
|
3441
|
+
"nargs": "?",
|
|
3442
|
+
"help": "Path to the OpenAPI document (or read from stdin if omitted)",
|
|
3443
|
+
"required": false
|
|
3444
|
+
},
|
|
3445
|
+
{
|
|
3446
|
+
"name": "--out",
|
|
3447
|
+
"type": "str",
|
|
3448
|
+
"help": "Path to the JSON Structure output file",
|
|
3449
|
+
"required": false
|
|
3450
|
+
},
|
|
3451
|
+
{
|
|
3452
|
+
"name": "--namespace",
|
|
3453
|
+
"type": "str",
|
|
3454
|
+
"help": "Namespace for the JSON Structure schema",
|
|
3455
|
+
"required": false
|
|
3456
|
+
},
|
|
3457
|
+
{
|
|
3458
|
+
"name": "--preserve-composition",
|
|
3459
|
+
"type": "bool",
|
|
3460
|
+
"help": "Preserve composition keywords (allOf, oneOf, anyOf) - requires Conditional Composition extension",
|
|
3461
|
+
"default": false,
|
|
3462
|
+
"required": false
|
|
3463
|
+
},
|
|
3464
|
+
{
|
|
3465
|
+
"name": "--detect-discriminators",
|
|
3466
|
+
"type": "bool",
|
|
3467
|
+
"help": "Detect OpenAPI discriminator patterns",
|
|
3468
|
+
"default": true,
|
|
3469
|
+
"required": false
|
|
3470
|
+
},
|
|
3471
|
+
{
|
|
3472
|
+
"name": "--lift-inline-schemas",
|
|
3473
|
+
"type": "bool",
|
|
3474
|
+
"help": "Lift inline schemas from paths to named definitions",
|
|
3475
|
+
"default": false,
|
|
3476
|
+
"required": false
|
|
3477
|
+
}
|
|
3478
|
+
],
|
|
3479
|
+
"suggested_output_file_path": "{input_file_name}.struct.json",
|
|
3480
|
+
"prompts": [
|
|
3481
|
+
{
|
|
3482
|
+
"name": "--namespace",
|
|
3483
|
+
"message": "Enter the namespace for the JSON Structure schema",
|
|
3484
|
+
"type": "str",
|
|
3485
|
+
"required": false
|
|
3486
|
+
},
|
|
3487
|
+
{
|
|
3488
|
+
"name": "--lift-inline-schemas",
|
|
3489
|
+
"message": "Lift inline schemas from paths to definitions?",
|
|
3490
|
+
"type": "bool",
|
|
3491
|
+
"default": false,
|
|
3492
|
+
"required": false
|
|
3493
|
+
}
|
|
3494
|
+
]
|
|
3336
3495
|
}
|
|
3337
3496
|
]
|
avrotize/constants.py
CHANGED
|
@@ -40,6 +40,11 @@ try:
|
|
|
40
40
|
except ValueError:
|
|
41
41
|
SYSTEM_MEMORY_DATA_VERSION = '9.0.3'
|
|
42
42
|
|
|
43
|
+
try:
|
|
44
|
+
PROTOBUF_NET_VERSION = get_dependency_version('cs', 'net90', 'protobuf-net')
|
|
45
|
+
except ValueError:
|
|
46
|
+
PROTOBUF_NET_VERSION = '3.2.30'
|
|
47
|
+
|
|
43
48
|
try:
|
|
44
49
|
NUNIT_VERSION = get_dependency_version('cs', 'net90', 'NUnit')
|
|
45
50
|
except ValueError:
|
|
@@ -55,6 +60,16 @@ try:
|
|
|
55
60
|
except ValueError:
|
|
56
61
|
MSTEST_SDK_VERSION = '17.13.0'
|
|
57
62
|
|
|
63
|
+
try:
|
|
64
|
+
COVERLET_VERSION = get_dependency_version('cs', 'net90', 'coverlet.collector')
|
|
65
|
+
except ValueError:
|
|
66
|
+
COVERLET_VERSION = '6.0.4'
|
|
67
|
+
|
|
68
|
+
try:
|
|
69
|
+
MSGPACK_VERSION = get_dependency_version('cs', 'net90', 'MessagePack')
|
|
70
|
+
except ValueError:
|
|
71
|
+
MSGPACK_VERSION = '2.5.187'
|
|
72
|
+
|
|
58
73
|
# Java test dependencies
|
|
59
74
|
try:
|
|
60
75
|
JUNIT_VERSION = get_dependency_version('java', 'jdk21', 'org.junit.jupiter:junit-jupiter-api')
|