structurize 2.22.0__py3-none-any.whl → 2.22.2__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/_version.py +3 -3
- avrotize/avrotocsharp.py +19 -1
- avrotize/avrotojsons.py +25 -3
- avrotize/commands.json +31 -0
- avrotize/constants.py +5 -0
- avrotize/structuretocsharp.py +108 -28
- avrotize/structuretots.py +2 -2
- {structurize-2.22.0.dist-info → structurize-2.22.2.dist-info}/METADATA +1 -1
- {structurize-2.22.0.dist-info → structurize-2.22.2.dist-info}/RECORD +13 -13
- {structurize-2.22.0.dist-info → structurize-2.22.2.dist-info}/WHEEL +0 -0
- {structurize-2.22.0.dist-info → structurize-2.22.2.dist-info}/entry_points.txt +0 -0
- {structurize-2.22.0.dist-info → structurize-2.22.2.dist-info}/licenses/LICENSE +0 -0
- {structurize-2.22.0.dist-info → structurize-2.22.2.dist-info}/top_level.txt +0 -0
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.22.
|
|
32
|
-
__version_tuple__ = version_tuple = (2, 22,
|
|
31
|
+
__version__ = version = '2.22.2'
|
|
32
|
+
__version_tuple__ = version_tuple = (2, 22, 2)
|
|
33
33
|
|
|
34
|
-
__commit_id__ = commit_id = '
|
|
34
|
+
__commit_id__ = commit_id = 'g25efcf5da'
|
avrotize/avrotocsharp.py
CHANGED
|
@@ -16,6 +16,7 @@ from avrotize.constants import (
|
|
|
16
16
|
SYSTEM_MEMORY_DATA_VERSION,
|
|
17
17
|
PROTOBUF_NET_VERSION,
|
|
18
18
|
MSGPACK_VERSION,
|
|
19
|
+
CBOR_VERSION,
|
|
19
20
|
NUNIT_VERSION,
|
|
20
21
|
NUNIT_ADAPTER_VERSION,
|
|
21
22
|
MSTEST_SDK_VERSION,
|
|
@@ -53,6 +54,7 @@ class AvroToCSharp:
|
|
|
53
54
|
self.newtonsoft_json_annotation = False
|
|
54
55
|
self.system_xml_annotation = False
|
|
55
56
|
self.msgpack_annotation = False
|
|
57
|
+
self.cbor_annotation = False
|
|
56
58
|
self.avro_annotation = False
|
|
57
59
|
self.protobuf_net_annotation = False
|
|
58
60
|
self.generated_types: Dict[str,str] = {}
|
|
@@ -267,6 +269,7 @@ class AvroToCSharp:
|
|
|
267
269
|
newtonsoft_json_annotation=self.newtonsoft_json_annotation,
|
|
268
270
|
system_xml_annotation=self.system_xml_annotation,
|
|
269
271
|
msgpack_annotation=self.msgpack_annotation,
|
|
272
|
+
cbor_annotation=self.cbor_annotation,
|
|
270
273
|
json_match_clauses=self.create_is_json_match_clauses(avro_schema, avro_namespace, class_name)
|
|
271
274
|
)
|
|
272
275
|
|
|
@@ -768,6 +771,10 @@ class AvroToCSharp:
|
|
|
768
771
|
if self.msgpack_annotation:
|
|
769
772
|
prop += f"{INDENT}[Key({field_index})]\n"
|
|
770
773
|
|
|
774
|
+
# Add CBOR serialization attribute if enabled
|
|
775
|
+
if self.cbor_annotation:
|
|
776
|
+
prop += f"{INDENT}[Dahomey.Cbor.Attributes.CborProperty(\"{annotation_name}\")]\n"
|
|
777
|
+
|
|
771
778
|
if self.system_text_json_annotation:
|
|
772
779
|
prop += f"{INDENT}[System.Text.Json.Serialization.JsonPropertyName(\"{annotation_name}\")]\n"
|
|
773
780
|
if is_enum_type:
|
|
@@ -831,6 +838,8 @@ class AvroToCSharp:
|
|
|
831
838
|
file_content += "using System.Xml.Serialization;\n"
|
|
832
839
|
if self.msgpack_annotation: # Add MessagePack serialization using directive
|
|
833
840
|
file_content += "using MessagePack;\n"
|
|
841
|
+
if self.cbor_annotation: # Add CBOR serialization using directive
|
|
842
|
+
file_content += "using Dahomey.Cbor.Attributes;\n"
|
|
834
843
|
|
|
835
844
|
if namespace:
|
|
836
845
|
# Namespace declaration with correct indentation for the definition
|
|
@@ -874,7 +883,8 @@ class AvroToCSharp:
|
|
|
874
883
|
system_text_json_annotation=self.system_text_json_annotation,
|
|
875
884
|
newtonsoft_json_annotation=self.newtonsoft_json_annotation,
|
|
876
885
|
protobuf_net_annotation=self.protobuf_net_annotation,
|
|
877
|
-
msgpack_annotation=self.msgpack_annotation
|
|
886
|
+
msgpack_annotation=self.msgpack_annotation,
|
|
887
|
+
cbor_annotation=self.cbor_annotation
|
|
878
888
|
)
|
|
879
889
|
elif type_kind == "enum":
|
|
880
890
|
test_class_definition = process_template(
|
|
@@ -1028,12 +1038,14 @@ class AvroToCSharp:
|
|
|
1028
1038
|
newtonsoft_json_annotation=self.newtonsoft_json_annotation,
|
|
1029
1039
|
protobuf_net_annotation=self.protobuf_net_annotation,
|
|
1030
1040
|
msgpack_annotation=self.msgpack_annotation,
|
|
1041
|
+
cbor_annotation=self.cbor_annotation,
|
|
1031
1042
|
CSHARP_AVRO_VERSION=CSHARP_AVRO_VERSION,
|
|
1032
1043
|
NEWTONSOFT_JSON_VERSION=NEWTONSOFT_JSON_VERSION,
|
|
1033
1044
|
SYSTEM_TEXT_JSON_VERSION=SYSTEM_TEXT_JSON_VERSION,
|
|
1034
1045
|
SYSTEM_MEMORY_DATA_VERSION=SYSTEM_MEMORY_DATA_VERSION,
|
|
1035
1046
|
PROTOBUF_NET_VERSION=PROTOBUF_NET_VERSION,
|
|
1036
1047
|
MSGPACK_VERSION=MSGPACK_VERSION,
|
|
1048
|
+
CBOR_VERSION=CBOR_VERSION,
|
|
1037
1049
|
NUNIT_VERSION=NUNIT_VERSION,
|
|
1038
1050
|
NUNIT_ADAPTER_VERSION=NUNIT_ADAPTER_VERSION,
|
|
1039
1051
|
MSTEST_SDK_VERSION=MSTEST_SDK_VERSION))
|
|
@@ -1107,6 +1119,7 @@ def convert_avro_to_csharp(
|
|
|
1107
1119
|
newtonsoft_json_annotation=False,
|
|
1108
1120
|
system_xml_annotation=False,
|
|
1109
1121
|
msgpack_annotation=False,
|
|
1122
|
+
cbor_annotation=False,
|
|
1110
1123
|
avro_annotation=False,
|
|
1111
1124
|
protobuf_net_annotation=False
|
|
1112
1125
|
):
|
|
@@ -1122,6 +1135,7 @@ def convert_avro_to_csharp(
|
|
|
1122
1135
|
newtonsoft_json_annotation (bool, optional): Use Newtonsoft.Json annotations. Defaults to False.
|
|
1123
1136
|
system_xml_annotation (bool, optional): Use System.Xml.Serialization annotations. Defaults to False.
|
|
1124
1137
|
msgpack_annotation (bool, optional): Use MessagePack annotations. Defaults to False.
|
|
1138
|
+
cbor_annotation (bool, optional): Use Dahomey.Cbor annotations. Defaults to False.
|
|
1125
1139
|
avro_annotation (bool, optional): Use Avro annotations. Defaults to False.
|
|
1126
1140
|
protobuf_net_annotation (bool, optional): Use protobuf-net annotations. Defaults to False.
|
|
1127
1141
|
"""
|
|
@@ -1135,6 +1149,7 @@ def convert_avro_to_csharp(
|
|
|
1135
1149
|
avrotocs.newtonsoft_json_annotation = newtonsoft_json_annotation
|
|
1136
1150
|
avrotocs.system_xml_annotation = system_xml_annotation
|
|
1137
1151
|
avrotocs.msgpack_annotation = msgpack_annotation
|
|
1152
|
+
avrotocs.cbor_annotation = cbor_annotation
|
|
1138
1153
|
avrotocs.avro_annotation = avro_annotation
|
|
1139
1154
|
avrotocs.protobuf_net_annotation = protobuf_net_annotation
|
|
1140
1155
|
avrotocs.convert(avro_schema_path, cs_file_path)
|
|
@@ -1150,6 +1165,7 @@ def convert_avro_schema_to_csharp(
|
|
|
1150
1165
|
newtonsoft_json_annotation: bool = False,
|
|
1151
1166
|
system_xml_annotation: bool = False,
|
|
1152
1167
|
msgpack_annotation: bool = False,
|
|
1168
|
+
cbor_annotation: bool = False,
|
|
1153
1169
|
avro_annotation: bool = False,
|
|
1154
1170
|
protobuf_net_annotation: bool = False
|
|
1155
1171
|
):
|
|
@@ -1165,6 +1181,7 @@ def convert_avro_schema_to_csharp(
|
|
|
1165
1181
|
newtonsoft_json_annotation (bool, optional): Use Newtonsoft.Json annotations. Defaults to False.
|
|
1166
1182
|
system_xml_annotation (bool, optional): Use System.Xml.Serialization annotations. Defaults to False.
|
|
1167
1183
|
msgpack_annotation (bool, optional): Use MessagePack annotations. Defaults to False.
|
|
1184
|
+
cbor_annotation (bool, optional): Use Dahomey.Cbor annotations. Defaults to False.
|
|
1168
1185
|
avro_annotation (bool, optional): Use Avro annotations. Defaults to False.
|
|
1169
1186
|
protobuf_net_annotation (bool, optional): Use protobuf-net annotations. Defaults to False.
|
|
1170
1187
|
"""
|
|
@@ -1175,6 +1192,7 @@ def convert_avro_schema_to_csharp(
|
|
|
1175
1192
|
avrotocs.newtonsoft_json_annotation = newtonsoft_json_annotation
|
|
1176
1193
|
avrotocs.system_xml_annotation = system_xml_annotation
|
|
1177
1194
|
avrotocs.msgpack_annotation = msgpack_annotation
|
|
1195
|
+
avrotocs.cbor_annotation = cbor_annotation
|
|
1178
1196
|
avrotocs.avro_annotation = avro_annotation
|
|
1179
1197
|
avrotocs.protobuf_net_annotation = protobuf_net_annotation
|
|
1180
1198
|
avrotocs.convert_schema(avro_schema, output_dir)
|
avrotize/avrotojsons.py
CHANGED
|
@@ -184,16 +184,38 @@ class AvroToJsonSchemaConverter:
|
|
|
184
184
|
def handle_type_union(self, types: List[Union[str, Dict[str, Any]]]) -> Dict[str, Any] | List[Dict[str, Any]| str] | str:
|
|
185
185
|
"""
|
|
186
186
|
Handle Avro type unions, returning a JSON schema that validates against any of the types.
|
|
187
|
+
Preserves nullability from Avro unions containing 'null'.
|
|
187
188
|
"""
|
|
189
|
+
is_nullable = 'null' in types
|
|
188
190
|
non_null_types = [t for t in types if t != 'null']
|
|
191
|
+
|
|
189
192
|
if len(non_null_types) == 1:
|
|
190
|
-
# Single non-null type
|
|
191
|
-
|
|
193
|
+
# Single non-null type - check if it's a primitive that can use type array
|
|
194
|
+
single_type = non_null_types[0]
|
|
195
|
+
json_schema = self.parse_avro_schema(single_type)
|
|
196
|
+
|
|
197
|
+
if is_nullable and isinstance(json_schema, dict):
|
|
198
|
+
# For primitives with a simple 'type' field, we can use type array notation
|
|
199
|
+
if 'type' in json_schema and isinstance(json_schema['type'], str) and '$ref' not in json_schema:
|
|
200
|
+
# Primitive type - add null to type array
|
|
201
|
+
json_schema = copy.deepcopy(json_schema)
|
|
202
|
+
json_schema['type'] = [json_schema['type'], 'null']
|
|
203
|
+
elif '$ref' in json_schema:
|
|
204
|
+
# Reference type - use oneOf with null
|
|
205
|
+
json_schema = {
|
|
206
|
+
'oneOf': [
|
|
207
|
+
{'type': 'null'},
|
|
208
|
+
json_schema
|
|
209
|
+
]
|
|
210
|
+
}
|
|
211
|
+
return json_schema
|
|
192
212
|
else:
|
|
193
213
|
# Multiple non-null types
|
|
194
|
-
union_types = [self.convert_reference(t) if isinstance(t,str) and t in self.defined_types else self.avro_primitive_to_json_type(t)
|
|
214
|
+
union_types = [self.convert_reference(t) if isinstance(t, str) and t in self.defined_types else self.avro_primitive_to_json_type(t)
|
|
195
215
|
if isinstance(t, str) else self.parse_avro_schema(t)
|
|
196
216
|
for t in non_null_types]
|
|
217
|
+
if is_nullable:
|
|
218
|
+
union_types.insert(0, {'type': 'null'})
|
|
197
219
|
return {
|
|
198
220
|
'oneOf': union_types
|
|
199
221
|
}
|
avrotize/commands.json
CHANGED
|
@@ -1255,6 +1255,8 @@
|
|
|
1255
1255
|
"system_text_json_annotation": "args.system_text_json_annotation",
|
|
1256
1256
|
"newtonsoft_json_annotation": "args.newtonsoft_json_annotation",
|
|
1257
1257
|
"system_xml_annotation": "args.system_xml_annotation",
|
|
1258
|
+
"msgpack_annotation": "args.msgpack_annotation",
|
|
1259
|
+
"cbor_annotation": "args.cbor_annotation",
|
|
1258
1260
|
"pascal_properties": "args.pascal_properties",
|
|
1259
1261
|
"base_namespace": "args.namespace"
|
|
1260
1262
|
}
|
|
@@ -1323,6 +1325,20 @@
|
|
|
1323
1325
|
"default": false,
|
|
1324
1326
|
"required": false
|
|
1325
1327
|
},
|
|
1328
|
+
{
|
|
1329
|
+
"name": "--msgpack-annotation",
|
|
1330
|
+
"type": "bool",
|
|
1331
|
+
"help": "Use MessagePack annotations",
|
|
1332
|
+
"default": false,
|
|
1333
|
+
"required": false
|
|
1334
|
+
},
|
|
1335
|
+
{
|
|
1336
|
+
"name": "--cbor-annotation",
|
|
1337
|
+
"type": "bool",
|
|
1338
|
+
"help": "Use Dahomey.Cbor annotations",
|
|
1339
|
+
"default": false,
|
|
1340
|
+
"required": false
|
|
1341
|
+
},
|
|
1326
1342
|
{
|
|
1327
1343
|
"name": "--pascal-properties",
|
|
1328
1344
|
"type": "bool",
|
|
@@ -1375,6 +1391,7 @@
|
|
|
1375
1391
|
"system_text_json_annotation": "args.system_text_json_annotation",
|
|
1376
1392
|
"newtonsoft_json_annotation": "args.newtonsoft_json_annotation",
|
|
1377
1393
|
"system_xml_annotation": "args.system_xml_annotation",
|
|
1394
|
+
"avro_annotation": "args.avro_annotation",
|
|
1378
1395
|
"pascal_properties": "args.pascal_properties",
|
|
1379
1396
|
"base_namespace": "args.namespace",
|
|
1380
1397
|
"project_name": "args.project_name"
|
|
@@ -1437,6 +1454,13 @@
|
|
|
1437
1454
|
"default": false,
|
|
1438
1455
|
"required": false
|
|
1439
1456
|
},
|
|
1457
|
+
{
|
|
1458
|
+
"name": "--avro-annotation",
|
|
1459
|
+
"type": "bool",
|
|
1460
|
+
"help": "Use Avro annotations",
|
|
1461
|
+
"default": false,
|
|
1462
|
+
"required": false
|
|
1463
|
+
},
|
|
1440
1464
|
{
|
|
1441
1465
|
"name": "--pascal-properties",
|
|
1442
1466
|
"type": "bool",
|
|
@@ -1468,6 +1492,13 @@
|
|
|
1468
1492
|
"default": false,
|
|
1469
1493
|
"required": false
|
|
1470
1494
|
},
|
|
1495
|
+
{
|
|
1496
|
+
"name": "--avro-annotation",
|
|
1497
|
+
"message": "Use Avro annotations?",
|
|
1498
|
+
"type": "bool",
|
|
1499
|
+
"default": false,
|
|
1500
|
+
"required": false
|
|
1501
|
+
},
|
|
1471
1502
|
{
|
|
1472
1503
|
"name": "--pascal-properties",
|
|
1473
1504
|
"message": "Use PascalCase properties?",
|
avrotize/constants.py
CHANGED
|
@@ -70,6 +70,11 @@ try:
|
|
|
70
70
|
except ValueError:
|
|
71
71
|
MSGPACK_VERSION = '2.5.187'
|
|
72
72
|
|
|
73
|
+
try:
|
|
74
|
+
CBOR_VERSION = get_dependency_version('cs', 'net90', 'Dahomey.Cbor')
|
|
75
|
+
except ValueError:
|
|
76
|
+
CBOR_VERSION = '1.25.1'
|
|
77
|
+
|
|
73
78
|
# Java test dependencies
|
|
74
79
|
try:
|
|
75
80
|
JUNIT_VERSION = get_dependency_version('java', 'jdk21', 'org.junit.jupiter:junit-jupiter-api')
|
avrotize/structuretocsharp.py
CHANGED
|
@@ -9,10 +9,12 @@ from typing import Any, Dict, List, Tuple, Union, cast, Optional
|
|
|
9
9
|
import uuid
|
|
10
10
|
|
|
11
11
|
from avrotize.common import pascal, process_template
|
|
12
|
+
from avrotize.jstructtoavro import JsonStructureToAvro
|
|
12
13
|
from avrotize.constants import (
|
|
13
14
|
NEWTONSOFT_JSON_VERSION,
|
|
14
15
|
SYSTEM_TEXT_JSON_VERSION,
|
|
15
16
|
SYSTEM_MEMORY_DATA_VERSION,
|
|
17
|
+
CSHARP_AVRO_VERSION,
|
|
16
18
|
NUNIT_VERSION,
|
|
17
19
|
NUNIT_ADAPTER_VERSION,
|
|
18
20
|
MSTEST_SDK_VERSION,
|
|
@@ -37,6 +39,7 @@ class StructureToCSharp:
|
|
|
37
39
|
self.system_text_json_annotation = False
|
|
38
40
|
self.newtonsoft_json_annotation = False
|
|
39
41
|
self.system_xml_annotation = False
|
|
42
|
+
self.avro_annotation = False
|
|
40
43
|
self.generated_types: Dict[str,str] = {}
|
|
41
44
|
self.generated_structure_types: Dict[str, Dict[str, Union[str, Dict, List]]] = {}
|
|
42
45
|
self.type_dict: Dict[str, Dict] = {}
|
|
@@ -419,14 +422,30 @@ class StructureToCSharp:
|
|
|
419
422
|
constructor_modifier = "protected" if is_abstract else "public"
|
|
420
423
|
class_definition += f"{INDENT}{constructor_modifier} {class_name}()\n{INDENT}{{\n{INDENT}}}"
|
|
421
424
|
|
|
425
|
+
# Convert JSON Structure schema to Avro schema if avro_annotation is enabled
|
|
426
|
+
avro_schema_json = ''
|
|
427
|
+
if self.avro_annotation:
|
|
428
|
+
# Use JsonStructureToAvro to convert the schema
|
|
429
|
+
converter = JsonStructureToAvro()
|
|
430
|
+
schema_copy = structure_schema.copy()
|
|
431
|
+
avro_schema = converter.convert(schema_copy)
|
|
432
|
+
# Escape the JSON for C# string literal
|
|
433
|
+
# json.dumps produces compact JSON that only needs backslash and quote escaping
|
|
434
|
+
avro_schema_json = json.dumps(avro_schema, separators=(',', ':')).replace('\\', '\\\\').replace('"', '\\"')
|
|
435
|
+
# Also enable system_text_json_annotation internally for Avro serialization helpers
|
|
436
|
+
# since ToAvroRecord and FromAvroRecord use System.Text.Json
|
|
437
|
+
needs_json_for_avro = not self.system_text_json_annotation and not self.newtonsoft_json_annotation
|
|
438
|
+
|
|
422
439
|
# Add helper methods from template if any annotations are enabled
|
|
423
|
-
if self.system_text_json_annotation or self.newtonsoft_json_annotation or self.system_xml_annotation:
|
|
440
|
+
if self.system_text_json_annotation or self.newtonsoft_json_annotation or self.system_xml_annotation or self.avro_annotation:
|
|
424
441
|
class_definition += process_template(
|
|
425
442
|
"structuretocsharp/dataclass_core.jinja",
|
|
426
443
|
class_name=class_name,
|
|
427
|
-
system_text_json_annotation=self.system_text_json_annotation,
|
|
444
|
+
system_text_json_annotation=self.system_text_json_annotation or (self.avro_annotation and needs_json_for_avro),
|
|
428
445
|
newtonsoft_json_annotation=self.newtonsoft_json_annotation,
|
|
429
|
-
system_xml_annotation=self.system_xml_annotation
|
|
446
|
+
system_xml_annotation=self.system_xml_annotation,
|
|
447
|
+
avro_annotation=self.avro_annotation,
|
|
448
|
+
avro_schema_json=avro_schema_json
|
|
430
449
|
)
|
|
431
450
|
|
|
432
451
|
# Generate Equals and GetHashCode
|
|
@@ -522,18 +541,39 @@ class StructureToCSharp:
|
|
|
522
541
|
self.needs_json_structure_converters = True
|
|
523
542
|
|
|
524
543
|
# Add validation attributes based on schema constraints
|
|
525
|
-
#
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
544
|
+
# Get the property type to determine which attributes to apply
|
|
545
|
+
prop_type_base = prop_schema.get('type', '')
|
|
546
|
+
if isinstance(prop_type_base, list):
|
|
547
|
+
# Handle type unions - use the first non-null type
|
|
548
|
+
non_null_types = [t for t in prop_type_base if t != 'null']
|
|
549
|
+
prop_type_base = non_null_types[0] if non_null_types else ''
|
|
550
|
+
|
|
551
|
+
# EmailAddress attribute for format: "email"
|
|
552
|
+
if prop_schema.get('format') == 'email':
|
|
553
|
+
property_definition += f'{INDENT}[System.ComponentModel.DataAnnotations.EmailAddress]\n'
|
|
554
|
+
|
|
555
|
+
# String length constraints (for string types)
|
|
556
|
+
if prop_type_base == 'string' or (not prop_type_base and ('minLength' in prop_schema or 'maxLength' in prop_schema)):
|
|
557
|
+
if 'maxLength' in prop_schema:
|
|
558
|
+
max_length = prop_schema['maxLength']
|
|
559
|
+
if 'minLength' in prop_schema:
|
|
560
|
+
min_length = prop_schema['minLength']
|
|
561
|
+
property_definition += f'{INDENT}[System.ComponentModel.DataAnnotations.StringLength({max_length}, MinimumLength = {min_length})]\n'
|
|
562
|
+
else:
|
|
563
|
+
property_definition += f'{INDENT}[System.ComponentModel.DataAnnotations.StringLength({max_length})]\n'
|
|
564
|
+
elif 'minLength' in prop_schema:
|
|
565
|
+
# MinLength only (no max)
|
|
529
566
|
min_length = prop_schema['minLength']
|
|
530
|
-
property_definition += f'{INDENT}[System.ComponentModel.DataAnnotations.
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
567
|
+
property_definition += f'{INDENT}[System.ComponentModel.DataAnnotations.MinLength({min_length})]\n'
|
|
568
|
+
|
|
569
|
+
# Array length constraints (for array types)
|
|
570
|
+
if prop_type_base == 'array':
|
|
571
|
+
if 'minItems' in prop_schema:
|
|
572
|
+
min_items = prop_schema['minItems']
|
|
573
|
+
property_definition += f'{INDENT}[System.ComponentModel.DataAnnotations.MinLength({min_items})]\n'
|
|
574
|
+
if 'maxItems' in prop_schema:
|
|
575
|
+
max_items = prop_schema['maxItems']
|
|
576
|
+
property_definition += f'{INDENT}[System.ComponentModel.DataAnnotations.MaxLength({max_items})]\n'
|
|
537
577
|
|
|
538
578
|
# RegularExpression attribute for pattern
|
|
539
579
|
if 'pattern' in prop_schema:
|
|
@@ -541,22 +581,49 @@ class StructureToCSharp:
|
|
|
541
581
|
property_definition += f'{INDENT}[System.ComponentModel.DataAnnotations.RegularExpression(@"{pattern}")]\n'
|
|
542
582
|
|
|
543
583
|
# Range attribute for minimum/maximum on numeric types
|
|
544
|
-
if 'minimum' in prop_schema or 'maximum' in prop_schema:
|
|
545
|
-
|
|
546
|
-
|
|
584
|
+
if 'minimum' in prop_schema or 'maximum' in prop_schema or 'exclusiveMinimum' in prop_schema or 'exclusiveMaximum' in prop_schema:
|
|
585
|
+
# Determine the minimum and maximum values
|
|
586
|
+
has_min = 'minimum' in prop_schema
|
|
587
|
+
has_max = 'maximum' in prop_schema
|
|
588
|
+
has_exclusive_min = 'exclusiveMinimum' in prop_schema
|
|
589
|
+
has_exclusive_max = 'exclusiveMaximum' in prop_schema
|
|
547
590
|
|
|
548
|
-
#
|
|
549
|
-
if
|
|
550
|
-
|
|
591
|
+
# Use minimum/maximum if present, otherwise use exclusiveMinimum/exclusiveMaximum
|
|
592
|
+
if has_min:
|
|
593
|
+
min_val = prop_schema['minimum']
|
|
594
|
+
min_is_exclusive = False
|
|
595
|
+
elif has_exclusive_min:
|
|
596
|
+
min_val = prop_schema['exclusiveMinimum']
|
|
597
|
+
min_is_exclusive = True
|
|
551
598
|
else:
|
|
552
|
-
|
|
599
|
+
min_val = 'double.MinValue'
|
|
600
|
+
min_is_exclusive = False
|
|
553
601
|
|
|
554
|
-
if
|
|
555
|
-
|
|
602
|
+
if has_max:
|
|
603
|
+
max_val = prop_schema['maximum']
|
|
604
|
+
max_is_exclusive = False
|
|
605
|
+
elif has_exclusive_max:
|
|
606
|
+
max_val = prop_schema['exclusiveMaximum']
|
|
607
|
+
max_is_exclusive = True
|
|
556
608
|
else:
|
|
557
|
-
|
|
609
|
+
max_val = 'double.MaxValue'
|
|
610
|
+
max_is_exclusive = False
|
|
611
|
+
|
|
612
|
+
# Convert to appropriate format
|
|
613
|
+
min_str = str(min_val)
|
|
614
|
+
max_str = str(max_val)
|
|
558
615
|
|
|
559
|
-
|
|
616
|
+
# Build the Range attribute with exclusive parameters if needed
|
|
617
|
+
range_params = f'{min_str}, {max_str}'
|
|
618
|
+
if min_is_exclusive or max_is_exclusive:
|
|
619
|
+
extra_params = []
|
|
620
|
+
if min_is_exclusive:
|
|
621
|
+
extra_params.append('MinimumIsExclusive = true')
|
|
622
|
+
if max_is_exclusive:
|
|
623
|
+
extra_params.append('MaximumIsExclusive = true')
|
|
624
|
+
range_params += ', ' + ', '.join(extra_params)
|
|
625
|
+
|
|
626
|
+
property_definition += f'{INDENT}[System.ComponentModel.DataAnnotations.Range({range_params})]\n'
|
|
560
627
|
|
|
561
628
|
# Add Obsolete attribute if deprecated
|
|
562
629
|
if prop_schema.get('deprecated', False):
|
|
@@ -1486,6 +1553,10 @@ class StructureToCSharp:
|
|
|
1486
1553
|
file_content += "using Newtonsoft.Json;\n"
|
|
1487
1554
|
if self.system_xml_annotation: # Add XML serialization using directive
|
|
1488
1555
|
file_content += "using System.Xml.Serialization;\n"
|
|
1556
|
+
if self.avro_annotation: # Add Avro using directives
|
|
1557
|
+
file_content += "using Avro;\n"
|
|
1558
|
+
file_content += "using Avro.Generic;\n"
|
|
1559
|
+
file_content += "using Avro.IO;\n"
|
|
1489
1560
|
|
|
1490
1561
|
if namespace:
|
|
1491
1562
|
# Namespace declaration with correct indentation for the definition
|
|
@@ -1560,11 +1631,14 @@ class StructureToCSharp:
|
|
|
1560
1631
|
"structuretocsharp/project.csproj.jinja",
|
|
1561
1632
|
project_name=project_name,
|
|
1562
1633
|
system_xml_annotation=self.system_xml_annotation,
|
|
1563
|
-
|
|
1634
|
+
# Avro annotation requires System.Text.Json for intermediate conversions
|
|
1635
|
+
system_text_json_annotation=self.system_text_json_annotation or self.avro_annotation,
|
|
1564
1636
|
newtonsoft_json_annotation=self.newtonsoft_json_annotation,
|
|
1637
|
+
avro_annotation=self.avro_annotation,
|
|
1565
1638
|
NEWTONSOFT_JSON_VERSION=NEWTONSOFT_JSON_VERSION,
|
|
1566
1639
|
SYSTEM_TEXT_JSON_VERSION=SYSTEM_TEXT_JSON_VERSION,
|
|
1567
1640
|
SYSTEM_MEMORY_DATA_VERSION=SYSTEM_MEMORY_DATA_VERSION,
|
|
1641
|
+
CSHARP_AVRO_VERSION=CSHARP_AVRO_VERSION,
|
|
1568
1642
|
NUNIT_VERSION=NUNIT_VERSION,
|
|
1569
1643
|
NUNIT_ADAPTER_VERSION=NUNIT_ADAPTER_VERSION,
|
|
1570
1644
|
MSTEST_SDK_VERSION=MSTEST_SDK_VERSION))
|
|
@@ -2268,7 +2342,8 @@ def convert_structure_to_csharp(
|
|
|
2268
2342
|
pascal_properties: bool = False,
|
|
2269
2343
|
system_text_json_annotation: bool = False,
|
|
2270
2344
|
newtonsoft_json_annotation: bool = False,
|
|
2271
|
-
system_xml_annotation: bool = False
|
|
2345
|
+
system_xml_annotation: bool = False,
|
|
2346
|
+
avro_annotation: bool = False
|
|
2272
2347
|
):
|
|
2273
2348
|
"""Converts JSON Structure schema to C# classes
|
|
2274
2349
|
|
|
@@ -2281,6 +2356,7 @@ def convert_structure_to_csharp(
|
|
|
2281
2356
|
system_text_json_annotation (bool, optional): Use System.Text.Json annotations. Defaults to False.
|
|
2282
2357
|
newtonsoft_json_annotation (bool, optional): Use Newtonsoft.Json annotations. Defaults to False.
|
|
2283
2358
|
system_xml_annotation (bool, optional): Use System.Xml.Serialization annotations. Defaults to False.
|
|
2359
|
+
avro_annotation (bool, optional): Use Avro annotations. Defaults to False.
|
|
2284
2360
|
"""
|
|
2285
2361
|
|
|
2286
2362
|
if not base_namespace:
|
|
@@ -2292,6 +2368,7 @@ def convert_structure_to_csharp(
|
|
|
2292
2368
|
structtocs.system_text_json_annotation = system_text_json_annotation
|
|
2293
2369
|
structtocs.newtonsoft_json_annotation = newtonsoft_json_annotation
|
|
2294
2370
|
structtocs.system_xml_annotation = system_xml_annotation
|
|
2371
|
+
structtocs.avro_annotation = avro_annotation
|
|
2295
2372
|
structtocs.convert(structure_schema_path, cs_file_path)
|
|
2296
2373
|
|
|
2297
2374
|
|
|
@@ -2303,7 +2380,8 @@ def convert_structure_schema_to_csharp(
|
|
|
2303
2380
|
pascal_properties: bool = False,
|
|
2304
2381
|
system_text_json_annotation: bool = False,
|
|
2305
2382
|
newtonsoft_json_annotation: bool = False,
|
|
2306
|
-
system_xml_annotation: bool = False
|
|
2383
|
+
system_xml_annotation: bool = False,
|
|
2384
|
+
avro_annotation: bool = False
|
|
2307
2385
|
):
|
|
2308
2386
|
"""Converts JSON Structure schema to C# classes
|
|
2309
2387
|
|
|
@@ -2316,6 +2394,7 @@ def convert_structure_schema_to_csharp(
|
|
|
2316
2394
|
system_text_json_annotation (bool, optional): Use System.Text.Json annotations. Defaults to False.
|
|
2317
2395
|
newtonsoft_json_annotation (bool, optional): Use Newtonsoft.Json annotations. Defaults to False.
|
|
2318
2396
|
system_xml_annotation (bool, optional): Use System.Xml.Serialization annotations. Defaults to False.
|
|
2397
|
+
avro_annotation (bool, optional): Use Avro annotations. Defaults to False.
|
|
2319
2398
|
"""
|
|
2320
2399
|
structtocs = StructureToCSharp(base_namespace)
|
|
2321
2400
|
structtocs.project_name = project_name
|
|
@@ -2323,4 +2402,5 @@ def convert_structure_schema_to_csharp(
|
|
|
2323
2402
|
structtocs.system_text_json_annotation = system_text_json_annotation
|
|
2324
2403
|
structtocs.newtonsoft_json_annotation = newtonsoft_json_annotation
|
|
2325
2404
|
structtocs.system_xml_annotation = system_xml_annotation
|
|
2405
|
+
structtocs.avro_annotation = avro_annotation
|
|
2326
2406
|
structtocs.convert_schema(structure_schema, output_dir)
|
avrotize/structuretots.py
CHANGED
|
@@ -125,7 +125,7 @@ class StructureToTypeScript:
|
|
|
125
125
|
namespace_package = '.'.join([part.lower() for part in namespace.split('.')]) if namespace else ''
|
|
126
126
|
package = namespace_package
|
|
127
127
|
if self.base_package:
|
|
128
|
-
package = self.base_package + ('.' if package else '') + package
|
|
128
|
+
package = self.base_package.lower() + ('.' if package else '') + package
|
|
129
129
|
return package
|
|
130
130
|
|
|
131
131
|
def typescript_type_from_structure_type(self, type_name: str) -> str:
|
|
@@ -738,4 +738,4 @@ def convert_structure_schema_to_typescript(structure_schema: JsonNode, output_di
|
|
|
738
738
|
avro_annotation: Whether to include Avro annotations
|
|
739
739
|
"""
|
|
740
740
|
converter = StructureToTypeScript(package_name, typedjson_annotation, avro_annotation)
|
|
741
|
-
converter.convert_schema(structure_schema, output_dir, package_name)
|
|
741
|
+
converter.convert_schema(structure_schema, output_dir, package_name)
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: structurize
|
|
3
|
-
Version: 2.22.
|
|
3
|
+
Version: 2.22.2
|
|
4
4
|
Summary: Tools to convert from and to JSON Structure from various other schema languages.
|
|
5
5
|
Author-email: Clemens Vasters <clemensv@microsoft.com>
|
|
6
6
|
Classifier: Programming Language :: Python :: 3
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
avrotize/__init__.py,sha256=t5h5wkHXr6M0mmHAB5rhjZ3Gxy9xutGTGIfojfao9rI,3820
|
|
2
2
|
avrotize/__main__.py,sha256=5pY8dYAURcOnFRvgb6fgaOIa_SOzPLIWbU8-ZTQ0jG4,88
|
|
3
|
-
avrotize/_version.py,sha256=
|
|
3
|
+
avrotize/_version.py,sha256=Tzal6KLkKmissU9BbKc9vPD8BYI6Pb3CVLukFXfsTYY,714
|
|
4
4
|
avrotize/asn1toavro.py,sha256=QDNwfBfXMxSH-k487CA3CaGCGDzOLs4PpVbbENm5uF0,8386
|
|
5
5
|
avrotize/avrotize.py,sha256=VHFpBltMVBpyt0ju3ZWW725BKjQ4Fk-nrAy8udW-X44,5713
|
|
6
6
|
avrotize/avrotocpp.py,sha256=hRZV247_TDD7Sm6_8sFx-UH5SueLLx2Wg6TvAVUX0iE,25693
|
|
7
|
-
avrotize/avrotocsharp.py,sha256=
|
|
7
|
+
avrotize/avrotocsharp.py,sha256=jOx9ctuUSsdpNDEXnNNfFHOb8zWWHclUvYTF5rInOaM,72339
|
|
8
8
|
avrotize/avrotocsv.py,sha256=PaDEW2aGRFVNLwewWhJ3OwxbKFI3PBg_mTgtT4uLMko,3689
|
|
9
9
|
avrotize/avrotodatapackage.py,sha256=zSCphLvCYiBKRAUCdccsr-4JysH3PyAS6fSgwa65Tss,7259
|
|
10
10
|
avrotize/avrotodb.py,sha256=5fNJgz00VMimyOl7eI0lIxlcaN_JnN0mb2Q9lzCRecw,46989
|
|
@@ -13,7 +13,7 @@ avrotize/avrotographql.py,sha256=i6G7xWjH_Lsn_CLiM4BCPb8OyZuCCpsYjXwXNTRMwEE,739
|
|
|
13
13
|
avrotize/avrotoiceberg.py,sha256=plVHGWkED1YDLcMDxL7NMdJl2f8G32hwlNWFrBLcsD8,9057
|
|
14
14
|
avrotize/avrotojava.py,sha256=NZZ7mUFVzvp7HBsU0XPiCwl4GVXE1RtS86pfNFJsIq8,135427
|
|
15
15
|
avrotize/avrotojs.py,sha256=QjB6XjFnDrpZBZrrWqS0TN8fQfRXBfhHabfG73FOIo8,12249
|
|
16
|
-
avrotize/avrotojsons.py,sha256=
|
|
16
|
+
avrotize/avrotojsons.py,sha256=I7EJz_IaCYLNzcycYXDOLAexHRHQfyb4yoWcxJ02vb0,22697
|
|
17
17
|
avrotize/avrotojstruct.py,sha256=-Hs4Ta958bRKmOfSTzRFENABCZ6lQPSPbIBEXvOQD1M,14660
|
|
18
18
|
avrotize/avrotokusto.py,sha256=D6AiRPa5uiZbqo9dqrFvAknsF5oNXgIzk8_08uZTZ2M,17636
|
|
19
19
|
avrotize/avrotomd.py,sha256=WHPHnfmkI3xDNIHKZ3ReYxj6tib1eCny3JOznNSN6r8,5348
|
|
@@ -25,9 +25,9 @@ avrotize/avrotorust.py,sha256=HEcDirRBCbXQNNs_FmkT-sp1dWQgZ8A23qkQYUxVuXE,24255
|
|
|
25
25
|
avrotize/avrotots.py,sha256=u_XLjlHN0Gof5QYlpqK4X9WoX9rL30TjQMPg4TiyYnI,33241
|
|
26
26
|
avrotize/avrotoxsd.py,sha256=iGQq_8kC0kfKsqvqS6s_mO-kJ8N5G8vXOwqRI_DZUxc,17744
|
|
27
27
|
avrotize/cddltostructure.py,sha256=MA2c-P3CIEAxEaBX-FF299gR55xcLEV3FrfTr2QfayM,74491
|
|
28
|
-
avrotize/commands.json,sha256=
|
|
28
|
+
avrotize/commands.json,sha256=I36P5rEoL8cqcx4P8a_VhXyGsg6NHRPiByQbofYYWj8,93350
|
|
29
29
|
avrotize/common.py,sha256=enqNR1I9-SbW7fNJE3w7N2R87kiN6_9Oa7VB4b2AUBc,31913
|
|
30
|
-
avrotize/constants.py,sha256=
|
|
30
|
+
avrotize/constants.py,sha256=LlgHrvT6RsRPrhFGRNHmFuIj3b1bSd45yC4rBCIGGVA,2753
|
|
31
31
|
avrotize/csvtoavro.py,sha256=TuIYm_Xv8gioEHl1YgWQKOYkFGGHfuwmK5RuEAEXbt8,4293
|
|
32
32
|
avrotize/datapackagetoavro.py,sha256=lw1S3H6UpKtjJj9ywDTuRw-qcihFx0vFJNPK7SlgKvY,2607
|
|
33
33
|
avrotize/dependency_resolver.py,sha256=LGOTutpobJ4kMjAwvs-l0Mt2tEoZFaXCazs-u38qnYk,19374
|
|
@@ -44,7 +44,7 @@ avrotize/proto3parser.py,sha256=MfE84c-oAWWuzYmKlEZ5g5LUF7YzZaASFh2trX3UCaw,1560
|
|
|
44
44
|
avrotize/prototoavro.py,sha256=hqXBGRxYojaEbEgoHZxXwMG4R1nWC7UMl_XNLWfqH38,17346
|
|
45
45
|
avrotize/structuretocddl.py,sha256=RK_dTJf0oAo6BIBM48NHRcWC96OtUjlgUC6HzXs5Lkk,21234
|
|
46
46
|
avrotize/structuretocpp.py,sha256=tBWOvyZPYQ1CHN6RgDnWlmzJ1giOyQ9SlHBHWvhPyiw,35898
|
|
47
|
-
avrotize/structuretocsharp.py,sha256=
|
|
47
|
+
avrotize/structuretocsharp.py,sha256=NnHzeJcOWDbZ_LnGV6AW9hXgP7rQW6Lld9utzxO8l-g,128208
|
|
48
48
|
avrotize/structuretocsv.py,sha256=w9cwXAnnakKaeTtXsLWWO8KwYnXUxyXvC7a-ZKs-E94,13851
|
|
49
49
|
avrotize/structuretodatapackage.py,sha256=NEHRt30KfVDWH1EQakvuMdRZTtfVXx8fsaYud0ofb2g,29768
|
|
50
50
|
avrotize/structuretodb.py,sha256=uk4hKSRNw1JwOsWSZGECjSwvmTFUipRvMgTGlKnviCo,44860
|
|
@@ -59,14 +59,14 @@ avrotize/structuretomd.py,sha256=exfCldYbieVdduhotSoLrxsbphmyJQyeQso9qv4qyUw,136
|
|
|
59
59
|
avrotize/structuretoproto.py,sha256=Aq0-fwMXSjjAxgZ5mq1kpo_TauigMRrJK9LNyoN-YGs,42679
|
|
60
60
|
avrotize/structuretopython.py,sha256=d9EZVDHq7r-x0ZYZIRYfCP6kub7MkEROuvzjTJfNVv0,43958
|
|
61
61
|
avrotize/structuretorust.py,sha256=ChRmO7uzU-pMdDdS0Vtg-MVUaOaNhNUPwH-ZKKOHglU,35134
|
|
62
|
-
avrotize/structuretots.py,sha256=
|
|
62
|
+
avrotize/structuretots.py,sha256=zpdFlhYlwAcaQP4jX0r5tR5KpygXF-dPbuSbEm4O0-E,35283
|
|
63
63
|
avrotize/structuretoxsd.py,sha256=01VpasyWSMOx04sILHLP7H-WkhGdXAEGKohUUfgrNf0,32797
|
|
64
64
|
avrotize/xsdtoavro.py,sha256=nQtNH_3pEZBp67oUCPqzhvItEExHTe-8obsIfNRXt8Y,19064
|
|
65
65
|
avrotize/dependencies/cpp/vcpkg/vcpkg.json,sha256=se5qnUVQ1Q6wN_DqgIioqKg_y7ouh9oly2iBAJJXkgw,414
|
|
66
66
|
avrotize/dependencies/typescript/node22/package.json,sha256=oAW_2X-b715kV7aajwuONZEMkyQUJGviG3GwnoUa7hU,387
|
|
67
|
-
structurize-2.22.
|
|
68
|
-
structurize-2.22.
|
|
69
|
-
structurize-2.22.
|
|
70
|
-
structurize-2.22.
|
|
71
|
-
structurize-2.22.
|
|
72
|
-
structurize-2.22.
|
|
67
|
+
structurize-2.22.2.dist-info/licenses/LICENSE,sha256=xGtQGygTETTtDQJafZCUbpsed3GxO6grmqig-jGEuSk,11348
|
|
68
|
+
structurize-2.22.2.dist-info/METADATA,sha256=VbLggwPdkdLWlW4sh9kH8tAIsDI44006ZLwfbP71bvw,3670
|
|
69
|
+
structurize-2.22.2.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
70
|
+
structurize-2.22.2.dist-info/entry_points.txt,sha256=biIH7jA5auhVqfbwHVk2gmD_gvrPYKgjpCAn0JWZ-Rs,55
|
|
71
|
+
structurize-2.22.2.dist-info/top_level.txt,sha256=yn-yQ0Cm1O9fbF8KJgv4IIvX4YRGelKgPqZF1wS5P50,9
|
|
72
|
+
structurize-2.22.2.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|