avrotize 2.21.1__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.
Files changed (171) hide show
  1. avrotize/__init__.py +66 -0
  2. avrotize/__main__.py +6 -0
  3. avrotize/_version.py +34 -0
  4. avrotize/asn1toavro.py +160 -0
  5. avrotize/avrotize.py +152 -0
  6. avrotize/avrotocpp/CMakeLists.txt.jinja +77 -0
  7. avrotize/avrotocpp/build.bat.jinja +7 -0
  8. avrotize/avrotocpp/build.sh.jinja +7 -0
  9. avrotize/avrotocpp/dataclass_body.jinja +108 -0
  10. avrotize/avrotocpp/vcpkg.json.jinja +21 -0
  11. avrotize/avrotocpp.py +483 -0
  12. avrotize/avrotocsharp/README.md.jinja +166 -0
  13. avrotize/avrotocsharp/class_test.cs.jinja +266 -0
  14. avrotize/avrotocsharp/dataclass_core.jinja +293 -0
  15. avrotize/avrotocsharp/enum_test.cs.jinja +20 -0
  16. avrotize/avrotocsharp/project.csproj.jinja +30 -0
  17. avrotize/avrotocsharp/project.sln.jinja +34 -0
  18. avrotize/avrotocsharp/run_coverage.ps1.jinja +98 -0
  19. avrotize/avrotocsharp/run_coverage.sh.jinja +149 -0
  20. avrotize/avrotocsharp/testproject.csproj.jinja +19 -0
  21. avrotize/avrotocsharp.py +1180 -0
  22. avrotize/avrotocsv.py +121 -0
  23. avrotize/avrotodatapackage.py +173 -0
  24. avrotize/avrotodb.py +1383 -0
  25. avrotize/avrotogo/go_enum.jinja +12 -0
  26. avrotize/avrotogo/go_helpers.jinja +31 -0
  27. avrotize/avrotogo/go_struct.jinja +151 -0
  28. avrotize/avrotogo/go_test.jinja +47 -0
  29. avrotize/avrotogo/go_union.jinja +38 -0
  30. avrotize/avrotogo.py +476 -0
  31. avrotize/avrotographql.py +197 -0
  32. avrotize/avrotoiceberg.py +210 -0
  33. avrotize/avrotojava/class_test.java.jinja +212 -0
  34. avrotize/avrotojava/enum_test.java.jinja +21 -0
  35. avrotize/avrotojava/testproject.pom.jinja +54 -0
  36. avrotize/avrotojava.py +2156 -0
  37. avrotize/avrotojs.py +250 -0
  38. avrotize/avrotojsons.py +481 -0
  39. avrotize/avrotojstruct.py +345 -0
  40. avrotize/avrotokusto.py +364 -0
  41. avrotize/avrotomd/README.md.jinja +49 -0
  42. avrotize/avrotomd.py +137 -0
  43. avrotize/avrotools.py +168 -0
  44. avrotize/avrotoparquet.py +208 -0
  45. avrotize/avrotoproto.py +359 -0
  46. avrotize/avrotopython/dataclass_core.jinja +241 -0
  47. avrotize/avrotopython/enum_core.jinja +87 -0
  48. avrotize/avrotopython/pyproject_toml.jinja +18 -0
  49. avrotize/avrotopython/test_class.jinja +97 -0
  50. avrotize/avrotopython/test_enum.jinja +23 -0
  51. avrotize/avrotopython.py +626 -0
  52. avrotize/avrotorust/dataclass_enum.rs.jinja +74 -0
  53. avrotize/avrotorust/dataclass_struct.rs.jinja +204 -0
  54. avrotize/avrotorust/dataclass_union.rs.jinja +105 -0
  55. avrotize/avrotorust.py +435 -0
  56. avrotize/avrotots/class_core.ts.jinja +140 -0
  57. avrotize/avrotots/class_test.ts.jinja +77 -0
  58. avrotize/avrotots/enum_core.ts.jinja +46 -0
  59. avrotize/avrotots/gitignore.jinja +34 -0
  60. avrotize/avrotots/index.ts.jinja +0 -0
  61. avrotize/avrotots/package.json.jinja +23 -0
  62. avrotize/avrotots/tsconfig.json.jinja +21 -0
  63. avrotize/avrotots.py +687 -0
  64. avrotize/avrotoxsd.py +344 -0
  65. avrotize/cddltostructure.py +1841 -0
  66. avrotize/commands.json +3496 -0
  67. avrotize/common.py +834 -0
  68. avrotize/constants.py +87 -0
  69. avrotize/csvtoavro.py +132 -0
  70. avrotize/datapackagetoavro.py +76 -0
  71. avrotize/dependencies/cpp/vcpkg/vcpkg.json +19 -0
  72. avrotize/dependencies/cs/net90/dependencies.csproj +29 -0
  73. avrotize/dependencies/go/go121/go.mod +6 -0
  74. avrotize/dependencies/java/jdk21/pom.xml +91 -0
  75. avrotize/dependencies/python/py312/requirements.txt +13 -0
  76. avrotize/dependencies/rust/stable/Cargo.toml +17 -0
  77. avrotize/dependencies/typescript/node22/package.json +16 -0
  78. avrotize/dependency_resolver.py +348 -0
  79. avrotize/dependency_version.py +432 -0
  80. avrotize/generic/generic.avsc +57 -0
  81. avrotize/jsonstoavro.py +2167 -0
  82. avrotize/jsonstostructure.py +2864 -0
  83. avrotize/jstructtoavro.py +878 -0
  84. avrotize/kstructtoavro.py +93 -0
  85. avrotize/kustotoavro.py +455 -0
  86. avrotize/openapitostructure.py +717 -0
  87. avrotize/parquettoavro.py +157 -0
  88. avrotize/proto2parser.py +498 -0
  89. avrotize/proto3parser.py +403 -0
  90. avrotize/prototoavro.py +382 -0
  91. avrotize/prototypes/any.avsc +19 -0
  92. avrotize/prototypes/api.avsc +106 -0
  93. avrotize/prototypes/duration.avsc +20 -0
  94. avrotize/prototypes/field_mask.avsc +18 -0
  95. avrotize/prototypes/struct.avsc +60 -0
  96. avrotize/prototypes/timestamp.avsc +20 -0
  97. avrotize/prototypes/type.avsc +253 -0
  98. avrotize/prototypes/wrappers.avsc +117 -0
  99. avrotize/structuretocddl.py +597 -0
  100. avrotize/structuretocpp/CMakeLists.txt.jinja +76 -0
  101. avrotize/structuretocpp/build.bat.jinja +3 -0
  102. avrotize/structuretocpp/build.sh.jinja +3 -0
  103. avrotize/structuretocpp/dataclass_body.jinja +50 -0
  104. avrotize/structuretocpp/vcpkg.json.jinja +11 -0
  105. avrotize/structuretocpp.py +697 -0
  106. avrotize/structuretocsharp/class_test.cs.jinja +180 -0
  107. avrotize/structuretocsharp/dataclass_core.jinja +156 -0
  108. avrotize/structuretocsharp/enum_test.cs.jinja +36 -0
  109. avrotize/structuretocsharp/json_structure_converters.cs.jinja +399 -0
  110. avrotize/structuretocsharp/program.cs.jinja +49 -0
  111. avrotize/structuretocsharp/project.csproj.jinja +17 -0
  112. avrotize/structuretocsharp/project.sln.jinja +34 -0
  113. avrotize/structuretocsharp/testproject.csproj.jinja +18 -0
  114. avrotize/structuretocsharp/tuple_converter.cs.jinja +121 -0
  115. avrotize/structuretocsharp.py +2295 -0
  116. avrotize/structuretocsv.py +365 -0
  117. avrotize/structuretodatapackage.py +659 -0
  118. avrotize/structuretodb.py +1125 -0
  119. avrotize/structuretogo/go_enum.jinja +12 -0
  120. avrotize/structuretogo/go_helpers.jinja +26 -0
  121. avrotize/structuretogo/go_interface.jinja +18 -0
  122. avrotize/structuretogo/go_struct.jinja +187 -0
  123. avrotize/structuretogo/go_test.jinja +70 -0
  124. avrotize/structuretogo.py +729 -0
  125. avrotize/structuretographql.py +502 -0
  126. avrotize/structuretoiceberg.py +355 -0
  127. avrotize/structuretojava/choice_core.jinja +34 -0
  128. avrotize/structuretojava/class_core.jinja +23 -0
  129. avrotize/structuretojava/enum_core.jinja +18 -0
  130. avrotize/structuretojava/equals_hashcode.jinja +30 -0
  131. avrotize/structuretojava/pom.xml.jinja +26 -0
  132. avrotize/structuretojava/tuple_core.jinja +49 -0
  133. avrotize/structuretojava.py +938 -0
  134. avrotize/structuretojs/class_core.js.jinja +33 -0
  135. avrotize/structuretojs/enum_core.js.jinja +10 -0
  136. avrotize/structuretojs/package.json.jinja +12 -0
  137. avrotize/structuretojs/test_class.js.jinja +84 -0
  138. avrotize/structuretojs/test_enum.js.jinja +58 -0
  139. avrotize/structuretojs/test_runner.js.jinja +45 -0
  140. avrotize/structuretojs.py +657 -0
  141. avrotize/structuretojsons.py +498 -0
  142. avrotize/structuretokusto.py +639 -0
  143. avrotize/structuretomd/README.md.jinja +204 -0
  144. avrotize/structuretomd.py +322 -0
  145. avrotize/structuretoproto.py +764 -0
  146. avrotize/structuretopython/dataclass_core.jinja +363 -0
  147. avrotize/structuretopython/enum_core.jinja +45 -0
  148. avrotize/structuretopython/map_alias.jinja +21 -0
  149. avrotize/structuretopython/pyproject_toml.jinja +23 -0
  150. avrotize/structuretopython/test_class.jinja +103 -0
  151. avrotize/structuretopython/test_enum.jinja +34 -0
  152. avrotize/structuretopython.py +799 -0
  153. avrotize/structuretorust/dataclass_enum.rs.jinja +63 -0
  154. avrotize/structuretorust/dataclass_struct.rs.jinja +121 -0
  155. avrotize/structuretorust/dataclass_union.rs.jinja +81 -0
  156. avrotize/structuretorust.py +714 -0
  157. avrotize/structuretots/class_core.ts.jinja +78 -0
  158. avrotize/structuretots/enum_core.ts.jinja +6 -0
  159. avrotize/structuretots/gitignore.jinja +8 -0
  160. avrotize/structuretots/index.ts.jinja +1 -0
  161. avrotize/structuretots/package.json.jinja +39 -0
  162. avrotize/structuretots/test_class.ts.jinja +35 -0
  163. avrotize/structuretots/tsconfig.json.jinja +21 -0
  164. avrotize/structuretots.py +740 -0
  165. avrotize/structuretoxsd.py +679 -0
  166. avrotize/xsdtoavro.py +413 -0
  167. avrotize-2.21.1.dist-info/METADATA +1319 -0
  168. avrotize-2.21.1.dist-info/RECORD +171 -0
  169. avrotize-2.21.1.dist-info/WHEEL +4 -0
  170. avrotize-2.21.1.dist-info/entry_points.txt +3 -0
  171. avrotize-2.21.1.dist-info/licenses/LICENSE +201 -0
@@ -0,0 +1,399 @@
1
+ using System;
2
+ using System.Globalization;
3
+ using System.Text.Json;
4
+ using System.Text.Json.Serialization;
5
+ using System.Xml;
6
+
7
+ {% if namespace %}
8
+ namespace {{ namespace }}
9
+ {
10
+ {% endif %}
11
+ {% set ind=4 if namespace else 0 %}
12
+ {% filter indent(width=ind, first=True) %}
13
+ /// <summary>
14
+ /// JSON converters for JSON Structure types that require string serialization.
15
+ /// Per JSON Structure Core spec, int64, uint64, int128, uint128, and decimal
16
+ /// types use string representation in JSON to preserve precision.
17
+ /// </summary>
18
+ public static class JsonStructureConverters
19
+ {
20
+ /// <summary>
21
+ /// Gets default JsonSerializerOptions configured with JSON Structure converters
22
+ /// </summary>
23
+ public static JsonSerializerOptions GetOptions()
24
+ {
25
+ var options = new JsonSerializerOptions();
26
+ options.Converters.Add(new Int64StringConverter());
27
+ options.Converters.Add(new NullableInt64StringConverter());
28
+ options.Converters.Add(new UInt64StringConverter());
29
+ options.Converters.Add(new NullableUInt64StringConverter());
30
+ options.Converters.Add(new Int128StringConverter());
31
+ options.Converters.Add(new NullableInt128StringConverter());
32
+ options.Converters.Add(new UInt128StringConverter());
33
+ options.Converters.Add(new NullableUInt128StringConverter());
34
+ options.Converters.Add(new DecimalStringConverter());
35
+ options.Converters.Add(new NullableDecimalStringConverter());
36
+ options.Converters.Add(new TimeSpanIso8601Converter());
37
+ options.Converters.Add(new NullableTimeSpanIso8601Converter());
38
+ return options;
39
+ }
40
+ }
41
+
42
+ /// <summary>
43
+ /// Converts Int64 (long) to/from JSON string for precision preservation
44
+ /// </summary>
45
+ public class Int64StringConverter : JsonConverter<long>
46
+ {
47
+ /// <inheritdoc/>
48
+ public override long Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
49
+ {
50
+ if (reader.TokenType == JsonTokenType.String)
51
+ {
52
+ return long.Parse(reader.GetString()!, CultureInfo.InvariantCulture);
53
+ }
54
+ return reader.GetInt64();
55
+ }
56
+
57
+ /// <inheritdoc/>
58
+ public override void Write(Utf8JsonWriter writer, long value, JsonSerializerOptions options)
59
+ {
60
+ writer.WriteStringValue(value.ToString(CultureInfo.InvariantCulture));
61
+ }
62
+ }
63
+
64
+ /// <summary>
65
+ /// Converts nullable Int64 (long?) to/from JSON string for precision preservation
66
+ /// </summary>
67
+ public class NullableInt64StringConverter : JsonConverter<long?>
68
+ {
69
+ /// <inheritdoc/>
70
+ public override long? Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
71
+ {
72
+ if (reader.TokenType == JsonTokenType.Null)
73
+ {
74
+ return null;
75
+ }
76
+ if (reader.TokenType == JsonTokenType.String)
77
+ {
78
+ var str = reader.GetString();
79
+ if (string.IsNullOrEmpty(str)) return null;
80
+ return long.Parse(str, CultureInfo.InvariantCulture);
81
+ }
82
+ return reader.GetInt64();
83
+ }
84
+
85
+ /// <inheritdoc/>
86
+ public override void Write(Utf8JsonWriter writer, long? value, JsonSerializerOptions options)
87
+ {
88
+ if (value.HasValue)
89
+ {
90
+ writer.WriteStringValue(value.Value.ToString(CultureInfo.InvariantCulture));
91
+ }
92
+ else
93
+ {
94
+ writer.WriteNullValue();
95
+ }
96
+ }
97
+ }
98
+
99
+ /// <summary>
100
+ /// Converts UInt64 (ulong) to/from JSON string for precision preservation
101
+ /// </summary>
102
+ public class UInt64StringConverter : JsonConverter<ulong>
103
+ {
104
+ /// <inheritdoc/>
105
+ public override ulong Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
106
+ {
107
+ if (reader.TokenType == JsonTokenType.String)
108
+ {
109
+ return ulong.Parse(reader.GetString()!, CultureInfo.InvariantCulture);
110
+ }
111
+ return reader.GetUInt64();
112
+ }
113
+
114
+ /// <inheritdoc/>
115
+ public override void Write(Utf8JsonWriter writer, ulong value, JsonSerializerOptions options)
116
+ {
117
+ writer.WriteStringValue(value.ToString(CultureInfo.InvariantCulture));
118
+ }
119
+ }
120
+
121
+ /// <summary>
122
+ /// Converts nullable UInt64 (ulong?) to/from JSON string for precision preservation
123
+ /// </summary>
124
+ public class NullableUInt64StringConverter : JsonConverter<ulong?>
125
+ {
126
+ /// <inheritdoc/>
127
+ public override ulong? Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
128
+ {
129
+ if (reader.TokenType == JsonTokenType.Null)
130
+ {
131
+ return null;
132
+ }
133
+ if (reader.TokenType == JsonTokenType.String)
134
+ {
135
+ var str = reader.GetString();
136
+ if (string.IsNullOrEmpty(str)) return null;
137
+ return ulong.Parse(str, CultureInfo.InvariantCulture);
138
+ }
139
+ return reader.GetUInt64();
140
+ }
141
+
142
+ /// <inheritdoc/>
143
+ public override void Write(Utf8JsonWriter writer, ulong? value, JsonSerializerOptions options)
144
+ {
145
+ if (value.HasValue)
146
+ {
147
+ writer.WriteStringValue(value.Value.ToString(CultureInfo.InvariantCulture));
148
+ }
149
+ else
150
+ {
151
+ writer.WriteNullValue();
152
+ }
153
+ }
154
+ }
155
+
156
+ /// <summary>
157
+ /// Converts Int128 to/from JSON string for precision preservation
158
+ /// </summary>
159
+ public class Int128StringConverter : JsonConverter<Int128>
160
+ {
161
+ /// <inheritdoc/>
162
+ public override Int128 Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
163
+ {
164
+ if (reader.TokenType == JsonTokenType.String)
165
+ {
166
+ return Int128.Parse(reader.GetString()!, CultureInfo.InvariantCulture);
167
+ }
168
+ // Fallback: try to read as number
169
+ return Int128.Parse(reader.GetInt64().ToString(), CultureInfo.InvariantCulture);
170
+ }
171
+
172
+ /// <inheritdoc/>
173
+ public override void Write(Utf8JsonWriter writer, Int128 value, JsonSerializerOptions options)
174
+ {
175
+ writer.WriteStringValue(value.ToString(CultureInfo.InvariantCulture));
176
+ }
177
+ }
178
+
179
+ /// <summary>
180
+ /// Converts nullable Int128 to/from JSON string for precision preservation
181
+ /// </summary>
182
+ public class NullableInt128StringConverter : JsonConverter<Int128?>
183
+ {
184
+ /// <inheritdoc/>
185
+ public override Int128? Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
186
+ {
187
+ if (reader.TokenType == JsonTokenType.Null)
188
+ {
189
+ return null;
190
+ }
191
+ if (reader.TokenType == JsonTokenType.String)
192
+ {
193
+ var str = reader.GetString();
194
+ if (string.IsNullOrEmpty(str)) return null;
195
+ return Int128.Parse(str, CultureInfo.InvariantCulture);
196
+ }
197
+ return Int128.Parse(reader.GetInt64().ToString(), CultureInfo.InvariantCulture);
198
+ }
199
+
200
+ /// <inheritdoc/>
201
+ public override void Write(Utf8JsonWriter writer, Int128? value, JsonSerializerOptions options)
202
+ {
203
+ if (value.HasValue)
204
+ {
205
+ writer.WriteStringValue(value.Value.ToString(CultureInfo.InvariantCulture));
206
+ }
207
+ else
208
+ {
209
+ writer.WriteNullValue();
210
+ }
211
+ }
212
+ }
213
+
214
+ /// <summary>
215
+ /// Converts UInt128 to/from JSON string for precision preservation
216
+ /// </summary>
217
+ public class UInt128StringConverter : JsonConverter<UInt128>
218
+ {
219
+ /// <inheritdoc/>
220
+ public override UInt128 Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
221
+ {
222
+ if (reader.TokenType == JsonTokenType.String)
223
+ {
224
+ return UInt128.Parse(reader.GetString()!, CultureInfo.InvariantCulture);
225
+ }
226
+ return UInt128.Parse(reader.GetUInt64().ToString(), CultureInfo.InvariantCulture);
227
+ }
228
+
229
+ /// <inheritdoc/>
230
+ public override void Write(Utf8JsonWriter writer, UInt128 value, JsonSerializerOptions options)
231
+ {
232
+ writer.WriteStringValue(value.ToString(CultureInfo.InvariantCulture));
233
+ }
234
+ }
235
+
236
+ /// <summary>
237
+ /// Converts nullable UInt128 to/from JSON string for precision preservation
238
+ /// </summary>
239
+ public class NullableUInt128StringConverter : JsonConverter<UInt128?>
240
+ {
241
+ /// <inheritdoc/>
242
+ public override UInt128? Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
243
+ {
244
+ if (reader.TokenType == JsonTokenType.Null)
245
+ {
246
+ return null;
247
+ }
248
+ if (reader.TokenType == JsonTokenType.String)
249
+ {
250
+ var str = reader.GetString();
251
+ if (string.IsNullOrEmpty(str)) return null;
252
+ return UInt128.Parse(str, CultureInfo.InvariantCulture);
253
+ }
254
+ return UInt128.Parse(reader.GetUInt64().ToString(), CultureInfo.InvariantCulture);
255
+ }
256
+
257
+ /// <inheritdoc/>
258
+ public override void Write(Utf8JsonWriter writer, UInt128? value, JsonSerializerOptions options)
259
+ {
260
+ if (value.HasValue)
261
+ {
262
+ writer.WriteStringValue(value.Value.ToString(CultureInfo.InvariantCulture));
263
+ }
264
+ else
265
+ {
266
+ writer.WriteNullValue();
267
+ }
268
+ }
269
+ }
270
+
271
+ /// <summary>
272
+ /// Converts decimal to/from JSON string for precision preservation
273
+ /// </summary>
274
+ public class DecimalStringConverter : JsonConverter<decimal>
275
+ {
276
+ /// <inheritdoc/>
277
+ public override decimal Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
278
+ {
279
+ if (reader.TokenType == JsonTokenType.String)
280
+ {
281
+ return decimal.Parse(reader.GetString()!, CultureInfo.InvariantCulture);
282
+ }
283
+ return reader.GetDecimal();
284
+ }
285
+
286
+ /// <inheritdoc/>
287
+ public override void Write(Utf8JsonWriter writer, decimal value, JsonSerializerOptions options)
288
+ {
289
+ writer.WriteStringValue(value.ToString(CultureInfo.InvariantCulture));
290
+ }
291
+ }
292
+
293
+ /// <summary>
294
+ /// Converts nullable decimal to/from JSON string for precision preservation
295
+ /// </summary>
296
+ public class NullableDecimalStringConverter : JsonConverter<decimal?>
297
+ {
298
+ /// <inheritdoc/>
299
+ public override decimal? Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
300
+ {
301
+ if (reader.TokenType == JsonTokenType.Null)
302
+ {
303
+ return null;
304
+ }
305
+ if (reader.TokenType == JsonTokenType.String)
306
+ {
307
+ var str = reader.GetString();
308
+ if (string.IsNullOrEmpty(str)) return null;
309
+ return decimal.Parse(str, CultureInfo.InvariantCulture);
310
+ }
311
+ return reader.GetDecimal();
312
+ }
313
+
314
+ /// <inheritdoc/>
315
+ public override void Write(Utf8JsonWriter writer, decimal? value, JsonSerializerOptions options)
316
+ {
317
+ if (value.HasValue)
318
+ {
319
+ writer.WriteStringValue(value.Value.ToString(CultureInfo.InvariantCulture));
320
+ }
321
+ else
322
+ {
323
+ writer.WriteNullValue();
324
+ }
325
+ }
326
+ }
327
+
328
+ /// <summary>
329
+ /// Converts TimeSpan to/from ISO 8601 duration format (e.g., "PT1H30M")
330
+ /// </summary>
331
+ public class TimeSpanIso8601Converter : JsonConverter<TimeSpan>
332
+ {
333
+ /// <inheritdoc/>
334
+ public override TimeSpan Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
335
+ {
336
+ var str = reader.GetString();
337
+ if (string.IsNullOrEmpty(str))
338
+ {
339
+ return TimeSpan.Zero;
340
+ }
341
+ // Try ISO 8601 duration format first
342
+ if (str.StartsWith("P", StringComparison.OrdinalIgnoreCase))
343
+ {
344
+ return XmlConvert.ToTimeSpan(str);
345
+ }
346
+ // Fall back to standard TimeSpan parsing
347
+ return TimeSpan.Parse(str, CultureInfo.InvariantCulture);
348
+ }
349
+
350
+ /// <inheritdoc/>
351
+ public override void Write(Utf8JsonWriter writer, TimeSpan value, JsonSerializerOptions options)
352
+ {
353
+ writer.WriteStringValue(XmlConvert.ToString(value));
354
+ }
355
+ }
356
+
357
+ /// <summary>
358
+ /// Converts nullable TimeSpan to/from ISO 8601 duration format (e.g., "PT1H30M")
359
+ /// </summary>
360
+ public class NullableTimeSpanIso8601Converter : JsonConverter<TimeSpan?>
361
+ {
362
+ /// <inheritdoc/>
363
+ public override TimeSpan? Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
364
+ {
365
+ if (reader.TokenType == JsonTokenType.Null)
366
+ {
367
+ return null;
368
+ }
369
+ var str = reader.GetString();
370
+ if (string.IsNullOrEmpty(str))
371
+ {
372
+ return null;
373
+ }
374
+ // Try ISO 8601 duration format first
375
+ if (str.StartsWith("P", StringComparison.OrdinalIgnoreCase))
376
+ {
377
+ return XmlConvert.ToTimeSpan(str);
378
+ }
379
+ // Fall back to standard TimeSpan parsing
380
+ return TimeSpan.Parse(str, CultureInfo.InvariantCulture);
381
+ }
382
+
383
+ /// <inheritdoc/>
384
+ public override void Write(Utf8JsonWriter writer, TimeSpan? value, JsonSerializerOptions options)
385
+ {
386
+ if (value.HasValue)
387
+ {
388
+ writer.WriteStringValue(XmlConvert.ToString(value.Value));
389
+ }
390
+ else
391
+ {
392
+ writer.WriteNullValue();
393
+ }
394
+ }
395
+ }
396
+ {% endfilter %}
397
+ {% if namespace %}
398
+ }
399
+ {% endif %}
@@ -0,0 +1,49 @@
1
+ using System;
2
+ using System.Collections.Generic;
3
+ using System.IO;
4
+ using System.Text.Json;
5
+
6
+ /// <summary>
7
+ /// Program that creates instances using test classes and serializes them to JSON
8
+ /// for validation against JSON Structure schemas.
9
+ /// Uses the ToByteArray method when available to ensure the class's serialization path is tested.
10
+ /// </summary>
11
+ public class InstanceSerializerProgram
12
+ {
13
+ public static void Main(string[] args)
14
+ {
15
+ string outputDir = args.Length > 0 ? args[0] : ".";
16
+ Directory.CreateDirectory(outputDir);
17
+
18
+ Console.WriteLine($"Generating JSON instance files in: {outputDir}");
19
+
20
+ {%- for class_info in classes %}
21
+ // Generate instance for {{ class_info.class_name }}
22
+ try
23
+ {
24
+ var test_{{ class_info.class_name }} = new {{ class_info.full_qualified_test_name }}();
25
+ var instance_{{ class_info.class_name }} = test_{{ class_info.class_name }}.CreateInstance();
26
+ {%- if has_to_byte_array %}
27
+ // Use ToByteArray to serialize via the class's serialization method
28
+ var bytes_{{ class_info.class_name }} = instance_{{ class_info.class_name }}.ToByteArray("application/json");
29
+ var filePath_{{ class_info.class_name }} = Path.Combine(outputDir, "{{ class_info.class_name }}.json");
30
+ File.WriteAllBytes(filePath_{{ class_info.class_name }}, bytes_{{ class_info.class_name }});
31
+ {%- else %}
32
+ // Fallback: use JsonSerializer directly when ToByteArray is not available
33
+ var jsonOptions = new JsonSerializerOptions { WriteIndented = true };
34
+ var json_{{ class_info.class_name }} = JsonSerializer.Serialize(instance_{{ class_info.class_name }}, jsonOptions);
35
+ var filePath_{{ class_info.class_name }} = Path.Combine(outputDir, "{{ class_info.class_name }}.json");
36
+ File.WriteAllText(filePath_{{ class_info.class_name }}, json_{{ class_info.class_name }});
37
+ {%- endif %}
38
+ Console.WriteLine($"Created: {filePath_{{ class_info.class_name }}}");
39
+ }
40
+ catch (Exception ex)
41
+ {
42
+ Console.WriteLine($"Error generating {{ class_info.class_name }}: {ex.Message}");
43
+ Console.WriteLine($"Stack trace: {ex.StackTrace}");
44
+ }
45
+ {% endfor %}
46
+
47
+ Console.WriteLine("JSON instance generation complete.");
48
+ }
49
+ }
@@ -0,0 +1,17 @@
1
+ <Project Sdk="Microsoft.NET.Sdk">
2
+ <PropertyGroup>
3
+ <TargetFramework>net9.0</TargetFramework>
4
+ <Nullable>enable</Nullable>
5
+ <GenerateDocumentationFile>true</GenerateDocumentationFile>
6
+ </PropertyGroup>
7
+ <ItemGroup>
8
+ {%- if newtonsoft_json_annotation %}
9
+ <PackageReference Include="Newtonsoft.Json" Version="{{ NEWTONSOFT_JSON_VERSION }}" />
10
+ {%- endif %}
11
+ {%- if system_text_json_annotation %}
12
+ <PackageReference Include="System.Text.Json" Version="{{ SYSTEM_TEXT_JSON_VERSION }}" />
13
+ {%- endif %}
14
+ <PackageReference Include="System.Memory.Data" Version="{{ SYSTEM_MEMORY_DATA_VERSION }}" />
15
+ </ItemGroup>
16
+ </Project>
17
+
@@ -0,0 +1,34 @@
1
+ {%- set slnguid = uuid() -%}
2
+ {%- set prjguid = uuid() -%}
3
+ {%- set testguid = uuid() -%}
4
+ {%- set slnguid2 = uuid() -%}
5
+ Microsoft Visual Studio Solution File, Format Version 12.00
6
+ # Visual Studio Version 17
7
+ VisualStudioVersion = 17.5.002.0
8
+ MinimumVisualStudioVersion = 10.0.40219.1
9
+ Project("{ {{-slnguid-}} }") = "{{project_name|pascal}}", "src\{{project_name|pascal}}.csproj", "{ {{-prjguid-}} }"
10
+ EndProject
11
+ Project("{ {{-slnguid-}} }") = "{{project_name|pascal}}_test", "test\{{project_name|pascal}}.Test.csproj", "{ {{-testguid-}} }"
12
+ EndProject
13
+ Global
14
+ GlobalSection(SolutionConfigurationPlatforms) = preSolution
15
+ Debug|Any CPU = Debug|Any CPU
16
+ Release|Any CPU = Release|Any CPU
17
+ EndGlobalSection
18
+ GlobalSection(ProjectConfigurationPlatforms) = postSolution
19
+ { {{-prjguid-}} }.Debug|Any CPU.ActiveCfg = Debug|Any CPU
20
+ { {{-prjguid-}} }.Debug|Any CPU.Build.0 = Debug|Any CPU
21
+ { {{-prjguid-}} }.Release|Any CPU.ActiveCfg = Release|Any CPU
22
+ { {{-prjguid-}} }.Release|Any CPU.Build.0 = Release|Any CPU
23
+ { {{-testguid-}} }.Debug|Any CPU.ActiveCfg = Debug|Any CPU
24
+ { {{-testguid-}} }.Debug|Any CPU.Build.0 = Debug|Any CPU
25
+ { {{-testguid-}} }.Release|Any CPU.ActiveCfg = Release|Any CPU
26
+ { {{-testguid-}} }.Release|Any CPU.Build.0 = Release|Any CPU
27
+ EndGlobalSection
28
+ GlobalSection(SolutionProperties) = preSolution
29
+ HideSolutionNode = FALSE
30
+ EndGlobalSection
31
+ GlobalSection(ExtensibilityGlobals) = postSolution
32
+ SolutionGuid = { {{-slnguid2-}} }
33
+ EndGlobalSection
34
+ EndGlobal
@@ -0,0 +1,18 @@
1
+ <Project Sdk="Microsoft.NET.Sdk">
2
+ <PropertyGroup>
3
+ <TargetFramework>net9.0</TargetFramework>
4
+ <Nullable>enable</Nullable>
5
+ <GenerateDocumentationFile>true</GenerateDocumentationFile>
6
+ <OutputType>Exe</OutputType>
7
+ <StartupObject>InstanceSerializerProgram</StartupObject>
8
+ </PropertyGroup>
9
+ <ItemGroup>
10
+ <ProjectReference Include="../src/{{project_name | pascal}}.csproj"/>
11
+ </ItemGroup>
12
+ <ItemGroup>
13
+ <PackageReference Include="NUnit" Version="{{ NUNIT_VERSION }}" />
14
+ <PackageReference Include="NUnit3TestAdapter" Version="{{ NUNIT_ADAPTER_VERSION }}" />
15
+ <PackageReference Include="Microsoft.NET.Test.Sdk" Version="{{ MSTEST_SDK_VERSION }}" />
16
+ </ItemGroup>
17
+ </Project>
18
+
@@ -0,0 +1,121 @@
1
+ using System;
2
+ using System.Linq;
3
+ using System.Reflection;
4
+ using System.Text.Json;
5
+ using System.Text.Json.Serialization;
6
+
7
+ {% if namespace %}
8
+ namespace {{ namespace }}
9
+ {
10
+ {% endif %}
11
+ {% set ind=4 if namespace else 0 %}
12
+ {% filter indent(width=ind, first=True) %}
13
+ /// <summary>
14
+ /// JSON converter for tuple types that serializes as JSON array per JSON Structure spec
15
+ /// </summary>
16
+ /// <typeparam name="T">The tuple record struct type</typeparam>
17
+ public class TupleJsonConverter<T> : JsonConverter<T> where T : struct
18
+ {
19
+ private readonly PropertyInfo[] _properties;
20
+ private readonly ConstructorInfo _constructor;
21
+
22
+ /// <summary>
23
+ /// Initializes the converter with property order from record struct
24
+ /// </summary>
25
+ public TupleJsonConverter()
26
+ {
27
+ var type = typeof(T);
28
+
29
+ // Get constructor parameters to determine correct order
30
+ _constructor = type.GetConstructors().FirstOrDefault()
31
+ ?? throw new InvalidOperationException($"No constructor found for tuple type {type.Name}");
32
+
33
+ var parameters = _constructor.GetParameters();
34
+ _properties = new PropertyInfo[parameters.Length];
35
+
36
+ // Match properties to constructor parameters by name (case-insensitive)
37
+ for (int i = 0; i < parameters.Length; i++)
38
+ {
39
+ var param = parameters[i];
40
+ var property = type.GetProperty(
41
+ param.Name!,
42
+ BindingFlags.Public | BindingFlags.Instance | BindingFlags.IgnoreCase
43
+ );
44
+
45
+ if (property == null)
46
+ {
47
+ throw new InvalidOperationException(
48
+ $"Property not found for constructor parameter '{param.Name}' in tuple type {type.Name}"
49
+ );
50
+ }
51
+
52
+ _properties[i] = property;
53
+ }
54
+ }
55
+
56
+ /// <summary>
57
+ /// Reads tuple from JSON array
58
+ /// </summary>
59
+ public override T Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
60
+ {
61
+ if (reader.TokenType != JsonTokenType.StartArray)
62
+ {
63
+ throw new JsonException($"Expected array for tuple type {typeToConvert.Name}, got {reader.TokenType}");
64
+ }
65
+
66
+ var values = new object?[_properties.Length];
67
+ var index = 0;
68
+
69
+ while (reader.Read())
70
+ {
71
+ if (reader.TokenType == JsonTokenType.EndArray)
72
+ {
73
+ break;
74
+ }
75
+
76
+ if (index >= _properties.Length)
77
+ {
78
+ throw new JsonException($"Too many elements in array for tuple type {typeToConvert.Name}. Expected {_properties.Length} elements.");
79
+ }
80
+
81
+ var propertyType = _properties[index].PropertyType;
82
+ values[index] = JsonSerializer.Deserialize(ref reader, propertyType, options);
83
+ index++;
84
+ }
85
+
86
+ if (index < _properties.Length)
87
+ {
88
+ throw new JsonException($"Not enough elements in array for tuple type {typeToConvert.Name}. Expected {_properties.Length}, got {index}.");
89
+ }
90
+
91
+ // Invoke constructor with values in correct order
92
+ try
93
+ {
94
+ return (T)_constructor.Invoke(values);
95
+ }
96
+ catch (Exception ex)
97
+ {
98
+ throw new JsonException($"Failed to construct tuple type {typeToConvert.Name}", ex);
99
+ }
100
+ }
101
+
102
+ /// <summary>
103
+ /// Writes tuple as JSON array
104
+ /// </summary>
105
+ public override void Write(Utf8JsonWriter writer, T value, JsonSerializerOptions options)
106
+ {
107
+ writer.WriteStartArray();
108
+
109
+ foreach (var property in _properties)
110
+ {
111
+ var propertyValue = property.GetValue(value);
112
+ JsonSerializer.Serialize(writer, propertyValue, property.PropertyType, options);
113
+ }
114
+
115
+ writer.WriteEndArray();
116
+ }
117
+ }
118
+ {% endfilter %}
119
+ {% if namespace %}
120
+ }
121
+ {% endif %}