avrotize 2.22.1__py3-none-any.whl → 3.0.0__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 +2 -2
- avrotize/avrotocsharp/class_test.cs.jinja +33 -2
- avrotize/avrotocsharp/dataclass_core.jinja +26 -5
- avrotize/avrotocsharp/project.csproj.jinja +3 -0
- avrotize/avrotocsharp.py +19 -1
- avrotize/avrotocsv.py +16 -0
- avrotize/commands.json +213 -4
- avrotize/constants.py +5 -0
- avrotize/dependencies/cs/net90/dependencies.csproj +1 -0
- avrotize/structuretocsharp/dataclass_core.jinja +110 -3
- avrotize/structuretocsharp/project.csproj.jinja +3 -0
- avrotize/structuretocsharp.py +108 -28
- avrotize/structuretots.py +2 -2
- {avrotize-2.22.1.dist-info → avrotize-3.0.0.dist-info}/METADATA +63 -14
- {avrotize-2.22.1.dist-info → avrotize-3.0.0.dist-info}/RECORD +18 -18
- {avrotize-2.22.1.dist-info → avrotize-3.0.0.dist-info}/WHEEL +0 -0
- {avrotize-2.22.1.dist-info → avrotize-3.0.0.dist-info}/entry_points.txt +0 -0
- {avrotize-2.22.1.dist-info → avrotize-3.0.0.dist-info}/licenses/LICENSE +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 = '
|
|
32
|
-
__version_tuple__ = version_tuple = (
|
|
31
|
+
__version__ = version = '3.0.0'
|
|
32
|
+
__version_tuple__ = version_tuple = (3, 0, 0)
|
|
33
33
|
|
|
34
34
|
__commit_id__ = commit_id = None
|
|
@@ -166,7 +166,18 @@ public class {{ test_class_name }}
|
|
|
166
166
|
Assert.That(newInstance, Is.EqualTo(_instance));
|
|
167
167
|
}
|
|
168
168
|
{%- endif %}
|
|
169
|
-
{%- if
|
|
169
|
+
{%- if cbor_annotation %}
|
|
170
|
+
/// <summary> Testing CBOR serializer </summary>
|
|
171
|
+
[Test]
|
|
172
|
+
public void Test_ToByteArray_FromData_Cbor()
|
|
173
|
+
{
|
|
174
|
+
var mediaType = "application/cbor";
|
|
175
|
+
var bytes = _instance.ToByteArray(mediaType);
|
|
176
|
+
var newInstance = {{ class_base_name }}.FromData(bytes, mediaType);
|
|
177
|
+
Assert.That(newInstance, Is.EqualTo(_instance));
|
|
178
|
+
}
|
|
179
|
+
{%- endif %}
|
|
180
|
+
{%- if avro_annotation or system_text_json_annotation or newtonsoft_json_annotation or system_xml_annotation or msgpack_annotation or cbor_annotation or protobuf_net_annotation %}
|
|
170
181
|
|
|
171
182
|
/// <summary> Testing FromData with edge cases </summary>
|
|
172
183
|
[Test]
|
|
@@ -188,6 +199,9 @@ public class {{ test_class_name }}
|
|
|
188
199
|
{%- elif msgpack_annotation %}
|
|
189
200
|
// Test null data - FromData returns null for null input
|
|
190
201
|
Assert.That({{ class_base_name }}.FromData((byte[])null!, "application/msgpack"), Is.Null);
|
|
202
|
+
{%- elif cbor_annotation %}
|
|
203
|
+
// Test null data - FromData returns null for null input
|
|
204
|
+
Assert.That({{ class_base_name }}.FromData((byte[])null!, "application/cbor"), Is.Null);
|
|
191
205
|
{%- elif protobuf_net_annotation %}
|
|
192
206
|
// Test null data - FromData returns null for null input
|
|
193
207
|
Assert.That({{ class_base_name }}.FromData((byte[])null!, "application/x-protobuf"), Is.Null);
|
|
@@ -242,7 +256,24 @@ public class {{ test_class_name }}
|
|
|
242
256
|
Assert.That(newInstance, Is.EqualTo(_instance));
|
|
243
257
|
}
|
|
244
258
|
{%- endif %}
|
|
245
|
-
{%- if
|
|
259
|
+
{%- if cbor_annotation and not (system_text_json_annotation or newtonsoft_json_annotation or msgpack_annotation) %}
|
|
260
|
+
|
|
261
|
+
/// <summary> Testing Gzip compression with CBOR </summary>
|
|
262
|
+
[Test]
|
|
263
|
+
public void Test_ToByteArray_Gzip_Cbor()
|
|
264
|
+
{
|
|
265
|
+
var mediaType = "application/cbor";
|
|
266
|
+
var gzipMediaType = "application/cbor+gzip";
|
|
267
|
+
var plainBytes = _instance.ToByteArray(mediaType);
|
|
268
|
+
var gzipBytes = _instance.ToByteArray(gzipMediaType);
|
|
269
|
+
// Gzip compressed data should start with magic bytes 0x1f 0x8b
|
|
270
|
+
Assert.That(gzipBytes.Length >= 2 && gzipBytes[0] == 0x1f && gzipBytes[1] == 0x8b, Is.True,
|
|
271
|
+
"Gzip compressed data should have correct magic bytes");
|
|
272
|
+
var newInstance = {{ class_base_name }}.FromData(gzipBytes, gzipMediaType);
|
|
273
|
+
Assert.That(newInstance, Is.EqualTo(_instance));
|
|
274
|
+
}
|
|
275
|
+
{%- endif %}
|
|
276
|
+
{%- if protobuf_net_annotation and not (system_text_json_annotation or newtonsoft_json_annotation or msgpack_annotation or cbor_annotation) %}
|
|
246
277
|
|
|
247
278
|
/// <summary> Testing Gzip compression with Protobuf </summary>
|
|
248
279
|
[Test]
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
{%- if avro_annotation or system_text_json_annotation or newtonsoft_json_annotation or system_xml_annotation or protobuf_net_annotation or msgpack_annotation %}
|
|
1
|
+
{%- if avro_annotation or system_text_json_annotation or newtonsoft_json_annotation or system_xml_annotation or protobuf_net_annotation or msgpack_annotation or cbor_annotation %}
|
|
2
2
|
/// <summary>
|
|
3
3
|
/// Creates an object from the data
|
|
4
4
|
/// </summary>
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
if ( data is {{ class_name }}) return ({{ class_name }})data;
|
|
12
12
|
if ( contentTypeString == null ) contentTypeString = System.Net.Mime.MediaTypeNames.Application.Octet;
|
|
13
13
|
var contentType = new System.Net.Mime.ContentType(contentTypeString);
|
|
14
|
-
{%- if avro_annotation or system_text_json_annotation or newtonsoft_json_annotation or system_xml_annotation or protobuf_net_annotation or msgpack_annotation %}
|
|
14
|
+
{%- if avro_annotation or system_text_json_annotation or newtonsoft_json_annotation or system_xml_annotation or protobuf_net_annotation or msgpack_annotation or cbor_annotation %}
|
|
15
15
|
if ( contentType.MediaType.EndsWith("+gzip"))
|
|
16
16
|
{
|
|
17
17
|
var stream = data switch
|
|
@@ -149,12 +149,25 @@
|
|
|
149
149
|
};
|
|
150
150
|
return MessagePack.MessagePackSerializer.Deserialize<{{ class_name }}>(bytes);
|
|
151
151
|
}
|
|
152
|
+
{%- endif %}
|
|
153
|
+
{%- if cbor_annotation %}
|
|
154
|
+
if (contentType.MediaType.StartsWith("application/cbor"))
|
|
155
|
+
{
|
|
156
|
+
var bytes = data switch
|
|
157
|
+
{
|
|
158
|
+
byte[] b => b,
|
|
159
|
+
System.IO.Stream s => ReadStreamToBytes(s),
|
|
160
|
+
System.BinaryData bd => bd.ToArray(),
|
|
161
|
+
_ => throw new NotSupportedException("Data type not supported for CBOR")
|
|
162
|
+
};
|
|
163
|
+
return Dahomey.Cbor.Cbor.Deserialize<{{ class_name }}>(new ReadOnlySpan<byte>(bytes));
|
|
164
|
+
}
|
|
152
165
|
{%- endif %}
|
|
153
166
|
throw new System.NotSupportedException($"Unsupported media type {contentType.MediaType}");
|
|
154
167
|
}
|
|
155
168
|
{%- endif %}
|
|
156
169
|
|
|
157
|
-
{%- if msgpack_annotation %}
|
|
170
|
+
{%- if msgpack_annotation or cbor_annotation %}
|
|
158
171
|
private static byte[] ReadStreamToBytes(System.IO.Stream stream)
|
|
159
172
|
{
|
|
160
173
|
using (var memoryStream = new System.IO.MemoryStream())
|
|
@@ -190,7 +203,7 @@
|
|
|
190
203
|
{%- if avro_annotation %}
|
|
191
204
|
{%- endif%}
|
|
192
205
|
|
|
193
|
-
{%- if avro_annotation or system_text_json_annotation or newtonsoft_json_annotation or system_xml_annotation or protobuf_net_annotation or msgpack_annotation %}
|
|
206
|
+
{%- if avro_annotation or system_text_json_annotation or newtonsoft_json_annotation or system_xml_annotation or protobuf_net_annotation or msgpack_annotation or cbor_annotation %}
|
|
194
207
|
/// <summary>
|
|
195
208
|
/// Converts the object to a byte array
|
|
196
209
|
/// </summary>
|
|
@@ -263,7 +276,15 @@
|
|
|
263
276
|
result = MessagePack.MessagePackSerializer.Serialize(this);
|
|
264
277
|
}
|
|
265
278
|
{%- endif %}
|
|
266
|
-
{%- if
|
|
279
|
+
{%- if cbor_annotation %}
|
|
280
|
+
if (contentType.MediaType.StartsWith("application/cbor"))
|
|
281
|
+
{
|
|
282
|
+
var bufferWriter = new System.Buffers.ArrayBufferWriter<byte>();
|
|
283
|
+
Dahomey.Cbor.Cbor.Serialize(this, bufferWriter);
|
|
284
|
+
result = bufferWriter.WrittenSpan.ToArray();
|
|
285
|
+
}
|
|
286
|
+
{%- endif %}
|
|
287
|
+
{%- if avro_annotation or system_text_json_annotation or newtonsoft_json_annotation or system_xml_annotation or protobuf_net_annotation or msgpack_annotation or cbor_annotation %}
|
|
267
288
|
if (result != null && contentType.MediaType.EndsWith("+gzip"))
|
|
268
289
|
{
|
|
269
290
|
var stream = new System.IO.MemoryStream();
|
|
@@ -20,6 +20,9 @@
|
|
|
20
20
|
{%- if msgpack_annotation %}
|
|
21
21
|
<PackageReference Include="MessagePack" Version="{{ MSGPACK_VERSION }}" />
|
|
22
22
|
{%- endif %}
|
|
23
|
+
{%- if cbor_annotation %}
|
|
24
|
+
<PackageReference Include="Dahomey.Cbor" Version="{{ CBOR_VERSION }}" />
|
|
25
|
+
{%- endif %}
|
|
23
26
|
<PackageReference Include="System.Memory.Data" Version="{{ SYSTEM_MEMORY_DATA_VERSION }}" />
|
|
24
27
|
</ItemGroup>
|
|
25
28
|
<ItemGroup>
|
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/avrotocsv.py
CHANGED
|
@@ -39,7 +39,23 @@ class AvroToCSVSchemaConverter:
|
|
|
39
39
|
|
|
40
40
|
:param avro_schema: Avro schema as a dictionary.
|
|
41
41
|
:return: CSV schema as a dictionary.
|
|
42
|
+
:raises ValueError: If the schema is not a single record type.
|
|
42
43
|
"""
|
|
44
|
+
# Handle schema arrays (unions of records) - not supported
|
|
45
|
+
if isinstance(avro_schema, list):
|
|
46
|
+
raise ValueError(
|
|
47
|
+
"CSV schema conversion only supports single record schemas. "
|
|
48
|
+
"The provided schema is an array/union of multiple types. "
|
|
49
|
+
"Use --record-type to specify a single record type if available."
|
|
50
|
+
)
|
|
51
|
+
|
|
52
|
+
# Ensure it's a record type with fields
|
|
53
|
+
if not isinstance(avro_schema, dict) or 'fields' not in avro_schema:
|
|
54
|
+
raise ValueError(
|
|
55
|
+
"CSV schema conversion only supports Avro record types with 'fields'. "
|
|
56
|
+
f"The provided schema has type: {avro_schema.get('type', 'unknown') if isinstance(avro_schema, dict) else type(avro_schema).__name__}"
|
|
57
|
+
)
|
|
58
|
+
|
|
43
59
|
csv_schema = {
|
|
44
60
|
"fields": []
|
|
45
61
|
}
|
avrotize/commands.json
CHANGED
|
@@ -649,6 +649,108 @@
|
|
|
649
649
|
}
|
|
650
650
|
]
|
|
651
651
|
},
|
|
652
|
+
{
|
|
653
|
+
"command": "s2k",
|
|
654
|
+
"description": "Convert JSON Structure schema to Kusto table schemas",
|
|
655
|
+
"group": "4_RTDB",
|
|
656
|
+
"function": {
|
|
657
|
+
"name": "avrotize.structuretokusto.convert_structure_to_kusto",
|
|
658
|
+
"args": {
|
|
659
|
+
"structure_schema_path": "input_file_path",
|
|
660
|
+
"kusto_file_path": "output_file_path",
|
|
661
|
+
"kusto_uri": "args.kusto_uri",
|
|
662
|
+
"kusto_database": "args.kusto_database",
|
|
663
|
+
"structure_record_type": "args.record_type",
|
|
664
|
+
"emit_cloudevents_columns": "args.emit_cloudevents_columns",
|
|
665
|
+
"emit_cloudevents_dispatch_table": "args.emit_cloudevents_dispatch"
|
|
666
|
+
}
|
|
667
|
+
},
|
|
668
|
+
"extensions": [
|
|
669
|
+
".struct.json",
|
|
670
|
+
".json"
|
|
671
|
+
],
|
|
672
|
+
"args": [
|
|
673
|
+
{
|
|
674
|
+
"name": "input",
|
|
675
|
+
"type": "str",
|
|
676
|
+
"nargs": "?",
|
|
677
|
+
"help": "Path to the JSON Structure schema file (or read from stdin if omitted)",
|
|
678
|
+
"required": false
|
|
679
|
+
},
|
|
680
|
+
{
|
|
681
|
+
"name": "--out",
|
|
682
|
+
"type": "str",
|
|
683
|
+
"help": "Path to the Kusto table schema file",
|
|
684
|
+
"required": false
|
|
685
|
+
},
|
|
686
|
+
{
|
|
687
|
+
"name": "--struct",
|
|
688
|
+
"type": "str",
|
|
689
|
+
"help": "Deprecated: Path to the JSON Structure schema file (for backcompat)",
|
|
690
|
+
"required": false
|
|
691
|
+
},
|
|
692
|
+
{
|
|
693
|
+
"name": "--kusto-uri",
|
|
694
|
+
"type": "str",
|
|
695
|
+
"help": "Kusto Cluster URI to apply the generated schema to.",
|
|
696
|
+
"required": false
|
|
697
|
+
},
|
|
698
|
+
{
|
|
699
|
+
"name": "--kusto-database",
|
|
700
|
+
"type": "str",
|
|
701
|
+
"help": "Kusto database name to apply the generated schema to",
|
|
702
|
+
"required": false
|
|
703
|
+
},
|
|
704
|
+
{
|
|
705
|
+
"name": "--record-type",
|
|
706
|
+
"type": "str",
|
|
707
|
+
"help": "Record type in the JSON Structure schema",
|
|
708
|
+
"required": false
|
|
709
|
+
},
|
|
710
|
+
{
|
|
711
|
+
"name": "--emit-cloudevents-columns",
|
|
712
|
+
"type": "bool",
|
|
713
|
+
"help": "Add CloudEvents columns to the Kusto table",
|
|
714
|
+
"default": false,
|
|
715
|
+
"required": false
|
|
716
|
+
},
|
|
717
|
+
{
|
|
718
|
+
"name": "--emit-cloudevents-dispatch",
|
|
719
|
+
"type": "bool",
|
|
720
|
+
"help": "Emit a _cloudevents_dispatch ingestion table and update policies for each generated table",
|
|
721
|
+
"required": false
|
|
722
|
+
}
|
|
723
|
+
],
|
|
724
|
+
"suggested_output_file_path": "{input_file_name}.kql",
|
|
725
|
+
"prompts": [
|
|
726
|
+
{
|
|
727
|
+
"name": "--kusto-uri",
|
|
728
|
+
"message": "Enter the Kusto Cluster URI (optional)",
|
|
729
|
+
"type": "str",
|
|
730
|
+
"required": false
|
|
731
|
+
},
|
|
732
|
+
{
|
|
733
|
+
"name": "--kusto-database",
|
|
734
|
+
"message": "Enter the Kusto database name (optional)",
|
|
735
|
+
"type": "str",
|
|
736
|
+
"required": false
|
|
737
|
+
},
|
|
738
|
+
{
|
|
739
|
+
"name": "--emit-cloudevents-columns",
|
|
740
|
+
"message": "Add CloudEvents columns to the Kusto table?",
|
|
741
|
+
"type": "bool",
|
|
742
|
+
"default": false,
|
|
743
|
+
"required": false
|
|
744
|
+
},
|
|
745
|
+
{
|
|
746
|
+
"name": "--emit-cloudevents-dispatch",
|
|
747
|
+
"message": "Emit a _cloudevents_dispatch ingestion table and update policies?",
|
|
748
|
+
"type": "bool",
|
|
749
|
+
"default": false,
|
|
750
|
+
"required": false
|
|
751
|
+
}
|
|
752
|
+
]
|
|
753
|
+
},
|
|
652
754
|
{
|
|
653
755
|
"command": "k2a",
|
|
654
756
|
"description": "Convert Kusto schema to Avrotize schema",
|
|
@@ -836,7 +938,7 @@
|
|
|
836
938
|
]
|
|
837
939
|
},
|
|
838
940
|
{
|
|
839
|
-
"command": "
|
|
941
|
+
"command": "s2sql",
|
|
840
942
|
"description": "Convert JSON Structure schema to SQL schema",
|
|
841
943
|
"group": "5_SQL",
|
|
842
944
|
"function": {
|
|
@@ -1255,6 +1357,8 @@
|
|
|
1255
1357
|
"system_text_json_annotation": "args.system_text_json_annotation",
|
|
1256
1358
|
"newtonsoft_json_annotation": "args.newtonsoft_json_annotation",
|
|
1257
1359
|
"system_xml_annotation": "args.system_xml_annotation",
|
|
1360
|
+
"msgpack_annotation": "args.msgpack_annotation",
|
|
1361
|
+
"cbor_annotation": "args.cbor_annotation",
|
|
1258
1362
|
"pascal_properties": "args.pascal_properties",
|
|
1259
1363
|
"base_namespace": "args.namespace"
|
|
1260
1364
|
}
|
|
@@ -1323,6 +1427,20 @@
|
|
|
1323
1427
|
"default": false,
|
|
1324
1428
|
"required": false
|
|
1325
1429
|
},
|
|
1430
|
+
{
|
|
1431
|
+
"name": "--msgpack-annotation",
|
|
1432
|
+
"type": "bool",
|
|
1433
|
+
"help": "Use MessagePack annotations",
|
|
1434
|
+
"default": false,
|
|
1435
|
+
"required": false
|
|
1436
|
+
},
|
|
1437
|
+
{
|
|
1438
|
+
"name": "--cbor-annotation",
|
|
1439
|
+
"type": "bool",
|
|
1440
|
+
"help": "Use Dahomey.Cbor annotations",
|
|
1441
|
+
"default": false,
|
|
1442
|
+
"required": false
|
|
1443
|
+
},
|
|
1326
1444
|
{
|
|
1327
1445
|
"name": "--pascal-properties",
|
|
1328
1446
|
"type": "bool",
|
|
@@ -1375,6 +1493,7 @@
|
|
|
1375
1493
|
"system_text_json_annotation": "args.system_text_json_annotation",
|
|
1376
1494
|
"newtonsoft_json_annotation": "args.newtonsoft_json_annotation",
|
|
1377
1495
|
"system_xml_annotation": "args.system_xml_annotation",
|
|
1496
|
+
"avro_annotation": "args.avro_annotation",
|
|
1378
1497
|
"pascal_properties": "args.pascal_properties",
|
|
1379
1498
|
"base_namespace": "args.namespace",
|
|
1380
1499
|
"project_name": "args.project_name"
|
|
@@ -1437,6 +1556,13 @@
|
|
|
1437
1556
|
"default": false,
|
|
1438
1557
|
"required": false
|
|
1439
1558
|
},
|
|
1559
|
+
{
|
|
1560
|
+
"name": "--avro-annotation",
|
|
1561
|
+
"type": "bool",
|
|
1562
|
+
"help": "Use Avro annotations",
|
|
1563
|
+
"default": false,
|
|
1564
|
+
"required": false
|
|
1565
|
+
},
|
|
1440
1566
|
{
|
|
1441
1567
|
"name": "--pascal-properties",
|
|
1442
1568
|
"type": "bool",
|
|
@@ -1468,6 +1594,13 @@
|
|
|
1468
1594
|
"default": false,
|
|
1469
1595
|
"required": false
|
|
1470
1596
|
},
|
|
1597
|
+
{
|
|
1598
|
+
"name": "--avro-annotation",
|
|
1599
|
+
"message": "Use Avro annotations?",
|
|
1600
|
+
"type": "bool",
|
|
1601
|
+
"default": false,
|
|
1602
|
+
"required": false
|
|
1603
|
+
},
|
|
1471
1604
|
{
|
|
1472
1605
|
"name": "--pascal-properties",
|
|
1473
1606
|
"message": "Use PascalCase properties?",
|
|
@@ -1790,6 +1923,44 @@
|
|
|
1790
1923
|
"suggested_output_file_path": "{input_file_name}.csv.json",
|
|
1791
1924
|
"prompts": []
|
|
1792
1925
|
},
|
|
1926
|
+
{
|
|
1927
|
+
"command": "a2csv",
|
|
1928
|
+
"description": "Convert Avrotize schema to CSV schema",
|
|
1929
|
+
"group": "1_Schemas",
|
|
1930
|
+
"function": {
|
|
1931
|
+
"name": "avrotize.avrotocsv.convert_avro_to_csv_schema",
|
|
1932
|
+
"args": {
|
|
1933
|
+
"avro_schema_path": "input_file_path",
|
|
1934
|
+
"csv_schema_path": "output_file_path"
|
|
1935
|
+
}
|
|
1936
|
+
},
|
|
1937
|
+
"extensions": [
|
|
1938
|
+
".avsc"
|
|
1939
|
+
],
|
|
1940
|
+
"args": [
|
|
1941
|
+
{
|
|
1942
|
+
"name": "input",
|
|
1943
|
+
"type": "str",
|
|
1944
|
+
"nargs": "?",
|
|
1945
|
+
"help": "Path to the Avrotize schema file (or read from stdin if omitted)",
|
|
1946
|
+
"required": false
|
|
1947
|
+
},
|
|
1948
|
+
{
|
|
1949
|
+
"name": "--out",
|
|
1950
|
+
"type": "str",
|
|
1951
|
+
"help": "Output path for the CSV schema file",
|
|
1952
|
+
"required": false
|
|
1953
|
+
},
|
|
1954
|
+
{
|
|
1955
|
+
"name": "--avsc",
|
|
1956
|
+
"type": "str",
|
|
1957
|
+
"help": "Deprecated: Path to the Avrotize schema file (for backcompat)",
|
|
1958
|
+
"required": false
|
|
1959
|
+
}
|
|
1960
|
+
],
|
|
1961
|
+
"suggested_output_file_path": "{input_file_name}.csv.json",
|
|
1962
|
+
"prompts": []
|
|
1963
|
+
},
|
|
1793
1964
|
{
|
|
1794
1965
|
"command": "s2rust",
|
|
1795
1966
|
"description": "Convert JSON Structure to Rust classes",
|
|
@@ -2116,7 +2287,7 @@
|
|
|
2116
2287
|
]
|
|
2117
2288
|
},
|
|
2118
2289
|
{
|
|
2119
|
-
"command": "
|
|
2290
|
+
"command": "s2graphql",
|
|
2120
2291
|
"description": "Convert JSON Structure schema to GraphQL schema",
|
|
2121
2292
|
"group": "1_Schemas",
|
|
2122
2293
|
"function": {
|
|
@@ -2148,6 +2319,44 @@
|
|
|
2148
2319
|
"suggested_output_file_path": "{input_file_name}.graphql",
|
|
2149
2320
|
"prompts": []
|
|
2150
2321
|
},
|
|
2322
|
+
{
|
|
2323
|
+
"command": "a2graphql",
|
|
2324
|
+
"description": "Convert Avrotize schema to GraphQL schema",
|
|
2325
|
+
"group": "1_Schemas",
|
|
2326
|
+
"function": {
|
|
2327
|
+
"name": "avrotize.avrotographql.convert_avro_to_graphql",
|
|
2328
|
+
"args": {
|
|
2329
|
+
"avro_schema_path": "input_file_path",
|
|
2330
|
+
"graphql_schema_path": "output_file_path"
|
|
2331
|
+
}
|
|
2332
|
+
},
|
|
2333
|
+
"extensions": [
|
|
2334
|
+
".avsc"
|
|
2335
|
+
],
|
|
2336
|
+
"args": [
|
|
2337
|
+
{
|
|
2338
|
+
"name": "input",
|
|
2339
|
+
"type": "str",
|
|
2340
|
+
"nargs": "?",
|
|
2341
|
+
"help": "Path to the Avrotize schema file (or read from stdin if omitted)",
|
|
2342
|
+
"required": false
|
|
2343
|
+
},
|
|
2344
|
+
{
|
|
2345
|
+
"name": "--out",
|
|
2346
|
+
"type": "str",
|
|
2347
|
+
"help": "Path to the GraphQL schema file",
|
|
2348
|
+
"required": false
|
|
2349
|
+
},
|
|
2350
|
+
{
|
|
2351
|
+
"name": "--avsc",
|
|
2352
|
+
"type": "str",
|
|
2353
|
+
"help": "Deprecated: Path to the Avrotize schema file (for backcompat)",
|
|
2354
|
+
"required": false
|
|
2355
|
+
}
|
|
2356
|
+
],
|
|
2357
|
+
"suggested_output_file_path": "{input_file_name}.graphql",
|
|
2358
|
+
"prompts": []
|
|
2359
|
+
},
|
|
2151
2360
|
{
|
|
2152
2361
|
"command": "a2ts",
|
|
2153
2362
|
"description": "Convert Avrotize schema to TypeScript classes",
|
|
@@ -2793,7 +3002,7 @@
|
|
|
2793
3002
|
]
|
|
2794
3003
|
},
|
|
2795
3004
|
{
|
|
2796
|
-
"command": "
|
|
3005
|
+
"command": "s2cassandra",
|
|
2797
3006
|
"description": "Convert JSON Structure schema to Cassandra schema",
|
|
2798
3007
|
"group": "5_SQL",
|
|
2799
3008
|
"function": {
|
|
@@ -3337,7 +3546,7 @@
|
|
|
3337
3546
|
"prompts": []
|
|
3338
3547
|
},
|
|
3339
3548
|
{
|
|
3340
|
-
"command": "
|
|
3549
|
+
"command": "s2md",
|
|
3341
3550
|
"description": "Convert JSON Structure schema to Markdown documentation",
|
|
3342
3551
|
"group": "7_Utility",
|
|
3343
3552
|
"function": {
|
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')
|
|
@@ -18,6 +18,7 @@
|
|
|
18
18
|
<PackageReference Include="System.Memory.Data" Version="9.0.3" />
|
|
19
19
|
<PackageReference Include="protobuf-net" Version="3.2.30" />
|
|
20
20
|
<PackageReference Include="MessagePack" Version="3.1.4" />
|
|
21
|
+
<PackageReference Include="Dahomey.Cbor" Version="1.25.1" />
|
|
21
22
|
</ItemGroup>
|
|
22
23
|
|
|
23
24
|
<!-- Testing -->
|
|
@@ -1,4 +1,11 @@
|
|
|
1
|
-
{%- if
|
|
1
|
+
{%- if avro_annotation %}
|
|
2
|
+
/// <summary>
|
|
3
|
+
/// The Avro schema for this class
|
|
4
|
+
/// </summary>
|
|
5
|
+
private static readonly Avro.Schema AvroSchema = Avro.Schema.Parse("{{ avro_schema_json }}");
|
|
6
|
+
{%- endif %}
|
|
7
|
+
|
|
8
|
+
{%- if system_text_json_annotation or newtonsoft_json_annotation or system_xml_annotation or avro_annotation %}
|
|
2
9
|
/// <summary>
|
|
3
10
|
/// Creates an object from the data
|
|
4
11
|
/// </summary>
|
|
@@ -11,7 +18,7 @@
|
|
|
11
18
|
if ( data is {{ class_name }}) return ({{ class_name }})data;
|
|
12
19
|
if ( contentTypeString == null ) contentTypeString = System.Net.Mime.MediaTypeNames.Application.Octet;
|
|
13
20
|
var contentType = new System.Net.Mime.ContentType(contentTypeString);
|
|
14
|
-
{%- if system_text_json_annotation or newtonsoft_json_annotation or system_xml_annotation %}
|
|
21
|
+
{%- if system_text_json_annotation or newtonsoft_json_annotation or system_xml_annotation or avro_annotation %}
|
|
15
22
|
if ( contentType.MediaType.EndsWith("+gzip"))
|
|
16
23
|
{
|
|
17
24
|
var stream = data switch
|
|
@@ -92,12 +99,72 @@
|
|
|
92
99
|
return ({{ class_name }}?)serializer.Deserialize(memoryStream);
|
|
93
100
|
}
|
|
94
101
|
}
|
|
102
|
+
{%- endif %}
|
|
103
|
+
{%- if avro_annotation %}
|
|
104
|
+
if ( contentType.MediaType == "avro/binary" || contentType.MediaType == "application/vnd.apache.avro+avro")
|
|
105
|
+
{
|
|
106
|
+
if (data is byte[])
|
|
107
|
+
{
|
|
108
|
+
using (var stream = new System.IO.MemoryStream((byte[])data))
|
|
109
|
+
{
|
|
110
|
+
var reader = new Avro.Generic.GenericDatumReader<Avro.Generic.GenericRecord>(AvroSchema, AvroSchema);
|
|
111
|
+
var decoder = new Avro.IO.BinaryDecoder(stream);
|
|
112
|
+
var record = reader.Read(null, decoder);
|
|
113
|
+
return FromAvroRecord(record);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
else if (data is System.IO.Stream)
|
|
117
|
+
{
|
|
118
|
+
var reader = new Avro.Generic.GenericDatumReader<Avro.Generic.GenericRecord>(AvroSchema, AvroSchema);
|
|
119
|
+
var decoder = new Avro.IO.BinaryDecoder((System.IO.Stream)data);
|
|
120
|
+
var record = reader.Read(null, decoder);
|
|
121
|
+
return FromAvroRecord(record);
|
|
122
|
+
}
|
|
123
|
+
else if (data is System.BinaryData)
|
|
124
|
+
{
|
|
125
|
+
using (var stream = new System.IO.MemoryStream(((System.BinaryData)data).ToArray()))
|
|
126
|
+
{
|
|
127
|
+
var reader = new Avro.Generic.GenericDatumReader<Avro.Generic.GenericRecord>(AvroSchema, AvroSchema);
|
|
128
|
+
var decoder = new Avro.IO.BinaryDecoder(stream);
|
|
129
|
+
var record = reader.Read(null, decoder);
|
|
130
|
+
return FromAvroRecord(record);
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
}
|
|
95
134
|
{%- endif %}
|
|
96
135
|
throw new System.NotSupportedException($"Unsupported media type {contentType.MediaType}");
|
|
97
136
|
}
|
|
98
137
|
{%- endif %}
|
|
99
138
|
|
|
100
|
-
{%- if
|
|
139
|
+
{%- if avro_annotation %}
|
|
140
|
+
/// <summary>
|
|
141
|
+
/// Creates an instance from an Avro GenericRecord
|
|
142
|
+
/// </summary>
|
|
143
|
+
/// <param name="record">The Avro record</param>
|
|
144
|
+
/// <returns>The converted object</returns>
|
|
145
|
+
/// <remarks>
|
|
146
|
+
/// This method uses JSON as an intermediate format for conversion. This approach works well
|
|
147
|
+
/// for simple types but may have limitations with complex Avro union types that use
|
|
148
|
+
/// different JSON encoding than System.Text.Json. For complex schemas with unions,
|
|
149
|
+
/// consider implementing custom mapping logic directly from GenericRecord properties.
|
|
150
|
+
/// </remarks>
|
|
151
|
+
private static {{ class_name }}? FromAvroRecord(Avro.Generic.GenericRecord record)
|
|
152
|
+
{
|
|
153
|
+
// Convert Avro record to JSON and then deserialize
|
|
154
|
+
// This approach works for simple cases; for complex types, you may need custom mapping
|
|
155
|
+
using (var jsonStream = new System.IO.MemoryStream())
|
|
156
|
+
{
|
|
157
|
+
var jsonEncoder = new Avro.IO.JsonEncoder(AvroSchema, jsonStream);
|
|
158
|
+
var writer = new Avro.Generic.GenericDatumWriter<Avro.Generic.GenericRecord>(AvroSchema);
|
|
159
|
+
writer.Write(record, jsonEncoder);
|
|
160
|
+
jsonEncoder.Flush();
|
|
161
|
+
jsonStream.Position = 0;
|
|
162
|
+
return System.Text.Json.JsonSerializer.Deserialize<{{ class_name }}>(jsonStream);
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
{%- endif %}
|
|
166
|
+
|
|
167
|
+
{%- if system_text_json_annotation or newtonsoft_json_annotation or system_xml_annotation or avro_annotation %}
|
|
101
168
|
/// <summary>
|
|
102
169
|
/// Converts the object to a byte array
|
|
103
170
|
/// </summary>
|
|
@@ -138,6 +205,20 @@
|
|
|
138
205
|
}
|
|
139
206
|
}
|
|
140
207
|
}
|
|
208
|
+
{%- endif %}
|
|
209
|
+
{%- if avro_annotation %}
|
|
210
|
+
if (contentType.MediaType == "avro/binary" || contentType.MediaType == "application/vnd.apache.avro+avro")
|
|
211
|
+
{
|
|
212
|
+
using (var stream = new System.IO.MemoryStream())
|
|
213
|
+
{
|
|
214
|
+
var record = ToAvroRecord();
|
|
215
|
+
var writer = new Avro.Generic.GenericDatumWriter<Avro.Generic.GenericRecord>(AvroSchema);
|
|
216
|
+
var encoder = new Avro.IO.BinaryEncoder(stream);
|
|
217
|
+
writer.Write(record, encoder);
|
|
218
|
+
encoder.Flush();
|
|
219
|
+
result = stream.ToArray();
|
|
220
|
+
}
|
|
221
|
+
}
|
|
141
222
|
{%- endif %}
|
|
142
223
|
if ( result == null ) throw new System.NotSupportedException($"Unsupported media type {contentType.MediaType}");
|
|
143
224
|
if ( contentType.MediaType.EndsWith("+gzip"))
|
|
@@ -154,3 +235,29 @@
|
|
|
154
235
|
return result;
|
|
155
236
|
}
|
|
156
237
|
{%- endif %}
|
|
238
|
+
|
|
239
|
+
{%- if avro_annotation %}
|
|
240
|
+
/// <summary>
|
|
241
|
+
/// Converts this object to an Avro GenericRecord
|
|
242
|
+
/// </summary>
|
|
243
|
+
/// <returns>The Avro record</returns>
|
|
244
|
+
/// <remarks>
|
|
245
|
+
/// This method uses JSON as an intermediate format for conversion. This approach works well
|
|
246
|
+
/// for simple types but may have limitations with complex types containing unions, as
|
|
247
|
+
/// Avro's JSON encoding for unions differs from System.Text.Json's encoding. For complex
|
|
248
|
+
/// schemas with unions or other advanced Avro features, consider implementing custom
|
|
249
|
+
/// mapping logic directly to GenericRecord properties.
|
|
250
|
+
/// </remarks>
|
|
251
|
+
private Avro.Generic.GenericRecord ToAvroRecord()
|
|
252
|
+
{
|
|
253
|
+
// Convert to JSON first, then use Avro's JSON decoder
|
|
254
|
+
// This approach works for simple cases; for complex types, you may need custom mapping
|
|
255
|
+
var jsonBytes = System.Text.Json.JsonSerializer.SerializeToUtf8Bytes(this, this.GetType());
|
|
256
|
+
using (var jsonStream = new System.IO.MemoryStream(jsonBytes))
|
|
257
|
+
{
|
|
258
|
+
var decoder = new Avro.IO.JsonDecoder(AvroSchema, jsonStream);
|
|
259
|
+
var reader = new Avro.Generic.GenericDatumReader<Avro.Generic.GenericRecord>(AvroSchema, AvroSchema);
|
|
260
|
+
return reader.Read(reuse: null, decoder);
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
{%- endif %}
|
|
@@ -11,6 +11,9 @@
|
|
|
11
11
|
{%- if system_text_json_annotation %}
|
|
12
12
|
<PackageReference Include="System.Text.Json" Version="{{ SYSTEM_TEXT_JSON_VERSION }}" />
|
|
13
13
|
{%- endif %}
|
|
14
|
+
{%- if avro_annotation %}
|
|
15
|
+
<PackageReference Include="Apache.Avro" Version="{{ CSHARP_AVRO_VERSION }}" />
|
|
16
|
+
{%- endif %}
|
|
14
17
|
<PackageReference Include="System.Memory.Data" Version="{{ SYSTEM_MEMORY_DATA_VERSION }}" />
|
|
15
18
|
</ItemGroup>
|
|
16
19
|
</Project>
|
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: avrotize
|
|
3
|
-
Version:
|
|
3
|
+
Version: 3.0.0
|
|
4
4
|
Summary: Tools to convert from and to Avro Schema from various other schema languages.
|
|
5
5
|
Author-email: Clemens Vasters <clemensv@microsoft.com>
|
|
6
6
|
Requires-Python: >=3.10
|
|
@@ -90,13 +90,13 @@ Converting from Avrotize Schema:
|
|
|
90
90
|
- [`avrotize a2k`](#convert-avrotize-schema-to-kusto-table-declaration) - Convert Avrotize Schema to Kusto table definition.
|
|
91
91
|
- [`avrotize s2k`](#convert-json-structure-schema-to-kusto-table-declaration) - Convert JSON Structure Schema to Kusto table definition.
|
|
92
92
|
- [`avrotize a2sql`](#convert-avrotize-schema-to-sql-table-definition) - Convert Avrotize Schema to SQL table definition.
|
|
93
|
-
- [`avrotize
|
|
93
|
+
- [`avrotize s2sql`](#convert-json-structure-schema-to-sql-schema) - Convert JSON Structure Schema to SQL table definition.
|
|
94
94
|
- [`avrotize a2pq`](#convert-avrotize-schema-to-empty-parquet-file) - Convert Avrotize Schema to Parquet or Iceberg schema.
|
|
95
95
|
- [`avrotize a2ib`](#convert-avrotize-schema-to-iceberg-schema) - Convert Avrotize Schema to Iceberg schema.
|
|
96
96
|
- [`avrotize s2ib`](#convert-json-structure-to-iceberg-schema) - Convert JSON Structure to Iceberg schema.
|
|
97
97
|
- [`avrotize a2mongo`](#convert-avrotize-schema-to-mongodb-schema) - Convert Avrotize Schema to MongoDB schema.
|
|
98
98
|
- [`avrotize a2cassandra`](#convert-avrotize-schema-to-cassandra-schema) - Convert Avrotize Schema to Cassandra schema.
|
|
99
|
-
- [`avrotize
|
|
99
|
+
- [`avrotize s2cassandra`](#convert-json-structure-schema-to-cassandra-schema) - Convert JSON Structure Schema to Cassandra schema.
|
|
100
100
|
- [`avrotize a2es`](#convert-avrotize-schema-to-elasticsearch-schema) - Convert Avrotize Schema to Elasticsearch schema.
|
|
101
101
|
- [`avrotize a2dynamodb`](#convert-avrotize-schema-to-dynamodb-schema) - Convert Avrotize Schema to DynamoDB schema.
|
|
102
102
|
- [`avrotize a2cosmos`](#convert-avrotize-schema-to-cosmosdb-schema) - Convert Avrotize Schema to CosmosDB schema.
|
|
@@ -106,7 +106,7 @@ Converting from Avrotize Schema:
|
|
|
106
106
|
- [`avrotize a2neo4j`](#convert-avrotize-schema-to-neo4j-schema) - Convert Avrotize Schema to Neo4j schema.
|
|
107
107
|
- [`avrotize a2dp`](#convert-avrotize-schema-to-datapackage-schema) - Convert Avrotize Schema to Datapackage schema.
|
|
108
108
|
- [`avrotize a2md`](#convert-avrotize-schema-to-markdown-documentation) - Convert Avrotize Schema to Markdown documentation.
|
|
109
|
-
- [`avrotize
|
|
109
|
+
- [`avrotize s2md`](#convert-json-structure-schema-to-markdown-documentation) - Convert JSON Structure schema to Markdown documentation.
|
|
110
110
|
|
|
111
111
|
Direct conversions (JSON Structure):
|
|
112
112
|
|
|
@@ -137,7 +137,10 @@ Generate code from JSON Structure:
|
|
|
137
137
|
Direct JSON Structure conversions:
|
|
138
138
|
|
|
139
139
|
- [`avrotize s2csv`](#convert-json-structure-to-csv-schema) - Convert JSON Structure schema to CSV schema.
|
|
140
|
+
- [`avrotize a2csv`](#convert-avrotize-schema-to-csv-schema) - Convert Avrotize schema to CSV schema.
|
|
140
141
|
- [`avrotize s2x`](#convert-json-structure-to-xml-schema-xsd) - Convert JSON Structure to XML Schema (XSD).
|
|
142
|
+
- [`avrotize s2graphql`](#convert-json-structure-schema-to-graphql-schema) - Convert JSON Structure schema to GraphQL schema.
|
|
143
|
+
- [`avrotize a2graphql`](#convert-avrotize-schema-to-graphql-schema) - Convert Avrotize schema to GraphQL schema.
|
|
141
144
|
|
|
142
145
|
Other commands:
|
|
143
146
|
|
|
@@ -147,10 +150,6 @@ JSON Structure conversions:
|
|
|
147
150
|
|
|
148
151
|
- [`avrotize s2dp`](#convert-json-structure-schema-to-datapackage-schema) - Convert JSON Structure schema to Datapackage schema.
|
|
149
152
|
|
|
150
|
-
Direct conversions (not via Avrotize Schema):
|
|
151
|
-
|
|
152
|
-
- [`avrotize struct2gql`](#convert-json-structure-schema-to-graphql-schema) - Convert JSON Structure schema to GraphQL schema.
|
|
153
|
-
|
|
154
153
|
## Overview
|
|
155
154
|
|
|
156
155
|
You can use Avrotize to convert between Avro/Avrotize Schema and other schema formats like JSON Schema, XML Schema (XSD), Protocol Buffers (Protobuf), ASN.1, and database schema formats like Kusto Data Table Definition (KQL) and SQL Table Definition. That means you can also convert from JSON Schema to Protobuf going via Avrotize Schema.
|
|
@@ -489,7 +488,7 @@ For detailed conversion rules and type mappings for each SQL dialect, refer to t
|
|
|
489
488
|
### Convert JSON Structure Schema to SQL Schema
|
|
490
489
|
|
|
491
490
|
```bash
|
|
492
|
-
avrotize
|
|
491
|
+
avrotize s2sql [input] --out <path_to_sql_script> --dialect <dialect> [--emit-cloudevents-columns]
|
|
493
492
|
```
|
|
494
493
|
|
|
495
494
|
Parameters:
|
|
@@ -545,7 +544,7 @@ Refer to the detailed conversion notes for Cassandra in the [NoSQL Conversion No
|
|
|
545
544
|
### Convert JSON Structure Schema to Cassandra Schema
|
|
546
545
|
|
|
547
546
|
```bash
|
|
548
|
-
avrotize
|
|
547
|
+
avrotize s2cassandra [input] --out <output_file> [--emit-cloudevents-columns]
|
|
549
548
|
```
|
|
550
549
|
|
|
551
550
|
Parameters:
|
|
@@ -1153,7 +1152,7 @@ Conversion notes:
|
|
|
1153
1152
|
### Convert JSON Structure schema to Markdown documentation
|
|
1154
1153
|
|
|
1155
1154
|
```bash
|
|
1156
|
-
avrotize
|
|
1155
|
+
avrotize s2md <path_to_structure_schema_file> [--out <path_to_markdown_file>]
|
|
1157
1156
|
```
|
|
1158
1157
|
|
|
1159
1158
|
Parameters:
|
|
@@ -1201,6 +1200,25 @@ Conversion notes:
|
|
|
1201
1200
|
- Enum and const keywords are supported and preserved in the output.
|
|
1202
1201
|
- JSON Structure-specific features like `$ref`, `$extends`, definitions, and namespaces are resolved during conversion.
|
|
1203
1202
|
|
|
1203
|
+
### Convert Avrotize Schema to CSV Schema
|
|
1204
|
+
|
|
1205
|
+
```bash
|
|
1206
|
+
avrotize a2csv <path_to_avro_schema_file> [--out <path_to_csv_schema_file>]
|
|
1207
|
+
```
|
|
1208
|
+
|
|
1209
|
+
Parameters:
|
|
1210
|
+
|
|
1211
|
+
- `<path_to_avro_schema_file>`: The path to the Avrotize schema file to be converted. If omitted, the file is read from stdin.
|
|
1212
|
+
- `--out`: The path to the CSV schema file to write the conversion result to. If omitted, the output is directed to stdout.
|
|
1213
|
+
|
|
1214
|
+
Conversion notes:
|
|
1215
|
+
|
|
1216
|
+
- The tool converts Avrotize schemas to CSV Schema format.
|
|
1217
|
+
- Avro primitive types (string, int, long, float, double, boolean, bytes) are mapped to appropriate CSV schema types.
|
|
1218
|
+
- Avro logical types (date, timestamp-millis, decimal, uuid) are preserved in the output.
|
|
1219
|
+
- Complex types (records, arrays, maps) are represented as strings in CSV schema, as CSV format doesn't have native support for nested structures.
|
|
1220
|
+
- Only single record types can be converted to CSV schema.
|
|
1221
|
+
|
|
1204
1222
|
### Convert JSON Structure to Protocol Buffers
|
|
1205
1223
|
|
|
1206
1224
|
```bash
|
|
@@ -1283,7 +1301,7 @@ Conversion notes:
|
|
|
1283
1301
|
### Convert JSON Structure schema to GraphQL schema
|
|
1284
1302
|
|
|
1285
1303
|
```bash
|
|
1286
|
-
avrotize
|
|
1304
|
+
avrotize s2graphql [input] --out <path_to_graphql_schema_file>
|
|
1287
1305
|
```
|
|
1288
1306
|
|
|
1289
1307
|
Parameters:
|
|
@@ -1308,12 +1326,43 @@ Example:
|
|
|
1308
1326
|
|
|
1309
1327
|
```bash
|
|
1310
1328
|
# Convert a JSON Structure schema to GraphQL
|
|
1311
|
-
avrotize
|
|
1329
|
+
avrotize s2graphql myschema.struct.json --out myschema.graphql
|
|
1312
1330
|
|
|
1313
1331
|
# Read from stdin and write to stdout
|
|
1314
|
-
cat myschema.struct.json | avrotize
|
|
1332
|
+
cat myschema.struct.json | avrotize s2graphql > myschema.graphql
|
|
1333
|
+
```
|
|
1334
|
+
|
|
1335
|
+
### Convert Avrotize schema to GraphQL schema
|
|
1336
|
+
|
|
1337
|
+
```bash
|
|
1338
|
+
avrotize a2graphql [input] --out <path_to_graphql_schema_file>
|
|
1315
1339
|
```
|
|
1316
1340
|
|
|
1341
|
+
Parameters:
|
|
1342
|
+
|
|
1343
|
+
- `[input]`: The path to the Avrotize schema file. If omitted, the file is read from stdin.
|
|
1344
|
+
- `--out <path_to_graphql_schema_file>`: The path to the output GraphQL schema file.
|
|
1345
|
+
|
|
1346
|
+
Conversion notes:
|
|
1347
|
+
|
|
1348
|
+
- Converts Avrotize schema to GraphQL schema language (SDL)
|
|
1349
|
+
- Avro primitive types (string, int, long, float, double, boolean, bytes) are mapped to GraphQL scalar types
|
|
1350
|
+
- Avro logical types (date, timestamp-millis, decimal, uuid) are mapped to custom GraphQL scalars
|
|
1351
|
+
- Avro record types become GraphQL object types
|
|
1352
|
+
- Avro arrays become GraphQL lists `[Type]`
|
|
1353
|
+
- Avro maps are represented using the JSON scalar type
|
|
1354
|
+
- Avro unions are converted to GraphQL union types
|
|
1355
|
+
- Avro enums become GraphQL enum types
|
|
1356
|
+
|
|
1357
|
+
Example:
|
|
1358
|
+
|
|
1359
|
+
```bash
|
|
1360
|
+
# Convert an Avrotize schema to GraphQL
|
|
1361
|
+
avrotize a2graphql myschema.avsc --out myschema.graphql
|
|
1362
|
+
|
|
1363
|
+
# Read from stdin and write to stdout
|
|
1364
|
+
cat myschema.avsc | avrotize a2graphql > myschema.graphql
|
|
1365
|
+
```
|
|
1317
1366
|
|
|
1318
1367
|
This document provides an overview of the usage and functionality of Avrotize. For more detailed information, please refer to the [Avrotize Schema documentation](specs/avrotize-schema.md) and the individual command help messages.
|
|
1319
1368
|
|
|
@@ -1,11 +1,11 @@
|
|
|
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=9fL11DDeXfhKmxyz_HrYU3Yy7BjMWrJklCddPlmAj6A,704
|
|
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=
|
|
8
|
-
avrotize/avrotocsv.py,sha256=
|
|
7
|
+
avrotize/avrotocsharp.py,sha256=jOx9ctuUSsdpNDEXnNNfFHOb8zWWHclUvYTF5rInOaM,72339
|
|
8
|
+
avrotize/avrotocsv.py,sha256=yqVbP4Ar8bZyEgOAmHuHAsQKfCVjIO5_pa5dtaKLZKE,4575
|
|
9
9
|
avrotize/avrotodatapackage.py,sha256=zSCphLvCYiBKRAUCdccsr-4JysH3PyAS6fSgwa65Tss,7259
|
|
10
10
|
avrotize/avrotodb.py,sha256=5fNJgz00VMimyOl7eI0lIxlcaN_JnN0mb2Q9lzCRecw,46989
|
|
11
11
|
avrotize/avrotogo.py,sha256=H4jxdO7laRWKJuU6mytz2sgUa_20hZUlsBrUGrCe_UU,22405
|
|
@@ -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=3N1Jblh-_o2GRbhcrMXLUEf0pijsYu6ff-nAbT5nhTE,98316
|
|
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,7 +59,7 @@ 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/avrotocpp/CMakeLists.txt.jinja,sha256=t2ADvvi3o20xfVrsRBaUvZlpVCDR4h6Szsf0GcuSkH0,3015
|
|
@@ -68,10 +68,10 @@ avrotize/avrotocpp/build.sh.jinja,sha256=kBTv3w1iwSFzwI_MLS6nOjezcUC2mOI0yWndfyn
|
|
|
68
68
|
avrotize/avrotocpp/dataclass_body.jinja,sha256=miwbmWNPFn5wv_ncgphXAtAeaB5yx1023lj7bbsbB9I,4621
|
|
69
69
|
avrotize/avrotocpp/vcpkg.json.jinja,sha256=gEBg8px6sPwdyVTFf8RuLCaz4tkgbiantnLyToUvtxo,464
|
|
70
70
|
avrotize/avrotocsharp/README.md.jinja,sha256=g1TRA1bV2wEudRGDasHQrwlVmxd2HGTmH3itk8pTCoQ,4518
|
|
71
|
-
avrotize/avrotocsharp/class_test.cs.jinja,sha256=
|
|
72
|
-
avrotize/avrotocsharp/dataclass_core.jinja,sha256=
|
|
71
|
+
avrotize/avrotocsharp/class_test.cs.jinja,sha256=sjXOrnBydaFwAaS_4mBqz4EyA0nlLfRMFAkfSx3Wqyo,13661
|
|
72
|
+
avrotize/avrotocsharp/dataclass_core.jinja,sha256=7sL70Djt7PNgbN1AYsby-VrblUtvvne62J9YkwUYX14,15061
|
|
73
73
|
avrotize/avrotocsharp/enum_test.cs.jinja,sha256=BUiBLe1yvnxs-4cgwEjYXqkWmR94iVJsRIhBd_quFYc,579
|
|
74
|
-
avrotize/avrotocsharp/project.csproj.jinja,sha256=
|
|
74
|
+
avrotize/avrotocsharp/project.csproj.jinja,sha256=TjbHNnPVlSLTJaFiUZWCc0bKMwzDNl05tFkqhl3qJ48,1571
|
|
75
75
|
avrotize/avrotocsharp/project.sln.jinja,sha256=a5DcTeRa63bf9mOQzczMrYgmjHCOhdHMB7wVFPagnWU,1480
|
|
76
76
|
avrotize/avrotocsharp/run_coverage.ps1.jinja,sha256=oydzkAqmxYij3vH64q3FxLI8T3lPiYop8B3qyyXdqlI,3988
|
|
77
77
|
avrotize/avrotocsharp/run_coverage.sh.jinja,sha256=ua7Bfj4SAwb4JWz2bYbP85LXLNfzvVAR7ktW-XGslk4,4480
|
|
@@ -101,7 +101,7 @@ avrotize/avrotots/index.ts.jinja,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hS
|
|
|
101
101
|
avrotize/avrotots/package.json.jinja,sha256=3ZqMVLP1ALkyXcVVA5j8Kyi5obNLJBv7dlgwKzYZfa8,555
|
|
102
102
|
avrotize/avrotots/tsconfig.json.jinja,sha256=Job00bmIiHEWQjA-Ze2-OdoTzT-GjVbL36fYuqtXLNs,537
|
|
103
103
|
avrotize/dependencies/cpp/vcpkg/vcpkg.json,sha256=se5qnUVQ1Q6wN_DqgIioqKg_y7ouh9oly2iBAJJXkgw,414
|
|
104
|
-
avrotize/dependencies/cs/net90/dependencies.csproj,sha256=
|
|
104
|
+
avrotize/dependencies/cs/net90/dependencies.csproj,sha256=R5wHAApZubbG0QBwWXHARxPBQB0XNX_W1CmuUNT-544,1238
|
|
105
105
|
avrotize/dependencies/go/go121/go.mod,sha256=ZHjoQNugEIJdkfwwLupG5x6KpUyDp8HxyVnJfHG3wuE,203
|
|
106
106
|
avrotize/dependencies/java/jdk21/pom.xml,sha256=Tbq8arhxXD4GEnSA_Y4NYuG9H4aqAdNVX3VoQBUef5I,3177
|
|
107
107
|
avrotize/dependencies/python/py312/requirements.txt,sha256=zMr7YjvCg75g66b-HURTr-n_vjxSv0J7A97aydoyYLA,336
|
|
@@ -122,11 +122,11 @@ avrotize/structuretocpp/build.sh.jinja,sha256=EAzRK0jkoSUV9e9kVIB6tDYPEzf3vemrQz
|
|
|
122
122
|
avrotize/structuretocpp/dataclass_body.jinja,sha256=B978Gdi1btO_EUJH5j0DjbHanQdX7jHEkd-MuQU89dA,2472
|
|
123
123
|
avrotize/structuretocpp/vcpkg.json.jinja,sha256=Oo4SyS8X4CdCnZPqqit-D8TeoNQ-cG5JYQJJUoFLZf0,201
|
|
124
124
|
avrotize/structuretocsharp/class_test.cs.jinja,sha256=7vwHcu745wLsxVrx__QfWzztvlr29oN5bw2BDKMkZtI,8171
|
|
125
|
-
avrotize/structuretocsharp/dataclass_core.jinja,sha256=
|
|
125
|
+
avrotize/structuretocsharp/dataclass_core.jinja,sha256=UeXsMDScZCsfsGDeTCBkL_XMvlwEd0_9RCxgZGEpfCs,12448
|
|
126
126
|
avrotize/structuretocsharp/enum_test.cs.jinja,sha256=euS5w2I3NiHBY7PSNY7bPF0JBEVLagZ423cZiYPn-iY,1238
|
|
127
127
|
avrotize/structuretocsharp/json_structure_converters.cs.jinja,sha256=JqDu9_h97A4QFFk_j3IVLkcYjCh2_HxiAee7VVZrkWc,12810
|
|
128
128
|
avrotize/structuretocsharp/program.cs.jinja,sha256=E6KrgNAdKY_Xh3tRKL-IMMPcGrWshtteBPmXrcg-nYk,2405
|
|
129
|
-
avrotize/structuretocsharp/project.csproj.jinja,sha256=
|
|
129
|
+
avrotize/structuretocsharp/project.csproj.jinja,sha256=ZYy0zgqASyi-Tb_yP84iq1Xc8ciwFRORWd-Nj7ZIEgM,844
|
|
130
130
|
avrotize/structuretocsharp/project.sln.jinja,sha256=QKNG10hUo3sPCajx213TEUfZIMftxjRWqEhDyrSlJtM,1481
|
|
131
131
|
avrotize/structuretocsharp/testproject.csproj.jinja,sha256=7SDzEM0wNV4a7JfCWG5AYiZT7KyJA-9gq_57tHqifRI,756
|
|
132
132
|
avrotize/structuretocsharp/tuple_converter.cs.jinja,sha256=b2dsU7-5HcYdUMb1xpDAogBnKvKp7H86euT6EDrwLdc,3975
|
|
@@ -164,8 +164,8 @@ avrotize/structuretots/index.ts.jinja,sha256=-R4R_En1N4W_BEN3z3bLts9Xi4KnBTDLrYM
|
|
|
164
164
|
avrotize/structuretots/package.json.jinja,sha256=OfJn4g68VhBP-yvJCdsWm_1RHx1kphsmdWpxu_Fst1E,819
|
|
165
165
|
avrotize/structuretots/test_class.ts.jinja,sha256=7tJ6hPo3A9zToTkwolVyXYhmZ_E4uI_OnnYsUUzUEdQ,1180
|
|
166
166
|
avrotize/structuretots/tsconfig.json.jinja,sha256=8Pl65JW8uOMEexxkteobo0ZEqsJBO31HegNRUrf8XGQ,515
|
|
167
|
-
avrotize-
|
|
168
|
-
avrotize-
|
|
169
|
-
avrotize-
|
|
170
|
-
avrotize-
|
|
171
|
-
avrotize-
|
|
167
|
+
avrotize-3.0.0.dist-info/entry_points.txt,sha256=m8J2TWiqbZh7SBQezc1CNrM_GVPWf01zOFcAKhzCC0U,51
|
|
168
|
+
avrotize-3.0.0.dist-info/licenses/LICENSE,sha256=xGtQGygTETTtDQJafZCUbpsed3GxO6grmqig-jGEuSk,11348
|
|
169
|
+
avrotize-3.0.0.dist-info/WHEEL,sha256=G2gURzTEtmeR8nrdXUJfNiB3VYVxigPQ-bEQujpNiNs,82
|
|
170
|
+
avrotize-3.0.0.dist-info/METADATA,sha256=08ps9dsDdgQiglCf7idjcYMovejdlViYENVZf0Xtqc8,82284
|
|
171
|
+
avrotize-3.0.0.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|