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.
- avrotize/__init__.py +66 -0
- avrotize/__main__.py +6 -0
- avrotize/_version.py +34 -0
- avrotize/asn1toavro.py +160 -0
- avrotize/avrotize.py +152 -0
- avrotize/avrotocpp/CMakeLists.txt.jinja +77 -0
- avrotize/avrotocpp/build.bat.jinja +7 -0
- avrotize/avrotocpp/build.sh.jinja +7 -0
- avrotize/avrotocpp/dataclass_body.jinja +108 -0
- avrotize/avrotocpp/vcpkg.json.jinja +21 -0
- avrotize/avrotocpp.py +483 -0
- avrotize/avrotocsharp/README.md.jinja +166 -0
- avrotize/avrotocsharp/class_test.cs.jinja +266 -0
- avrotize/avrotocsharp/dataclass_core.jinja +293 -0
- avrotize/avrotocsharp/enum_test.cs.jinja +20 -0
- avrotize/avrotocsharp/project.csproj.jinja +30 -0
- avrotize/avrotocsharp/project.sln.jinja +34 -0
- avrotize/avrotocsharp/run_coverage.ps1.jinja +98 -0
- avrotize/avrotocsharp/run_coverage.sh.jinja +149 -0
- avrotize/avrotocsharp/testproject.csproj.jinja +19 -0
- avrotize/avrotocsharp.py +1180 -0
- avrotize/avrotocsv.py +121 -0
- avrotize/avrotodatapackage.py +173 -0
- avrotize/avrotodb.py +1383 -0
- avrotize/avrotogo/go_enum.jinja +12 -0
- avrotize/avrotogo/go_helpers.jinja +31 -0
- avrotize/avrotogo/go_struct.jinja +151 -0
- avrotize/avrotogo/go_test.jinja +47 -0
- avrotize/avrotogo/go_union.jinja +38 -0
- avrotize/avrotogo.py +476 -0
- avrotize/avrotographql.py +197 -0
- avrotize/avrotoiceberg.py +210 -0
- avrotize/avrotojava/class_test.java.jinja +212 -0
- avrotize/avrotojava/enum_test.java.jinja +21 -0
- avrotize/avrotojava/testproject.pom.jinja +54 -0
- avrotize/avrotojava.py +2156 -0
- avrotize/avrotojs.py +250 -0
- avrotize/avrotojsons.py +481 -0
- avrotize/avrotojstruct.py +345 -0
- avrotize/avrotokusto.py +364 -0
- avrotize/avrotomd/README.md.jinja +49 -0
- avrotize/avrotomd.py +137 -0
- avrotize/avrotools.py +168 -0
- avrotize/avrotoparquet.py +208 -0
- avrotize/avrotoproto.py +359 -0
- avrotize/avrotopython/dataclass_core.jinja +241 -0
- avrotize/avrotopython/enum_core.jinja +87 -0
- avrotize/avrotopython/pyproject_toml.jinja +18 -0
- avrotize/avrotopython/test_class.jinja +97 -0
- avrotize/avrotopython/test_enum.jinja +23 -0
- avrotize/avrotopython.py +626 -0
- avrotize/avrotorust/dataclass_enum.rs.jinja +74 -0
- avrotize/avrotorust/dataclass_struct.rs.jinja +204 -0
- avrotize/avrotorust/dataclass_union.rs.jinja +105 -0
- avrotize/avrotorust.py +435 -0
- avrotize/avrotots/class_core.ts.jinja +140 -0
- avrotize/avrotots/class_test.ts.jinja +77 -0
- avrotize/avrotots/enum_core.ts.jinja +46 -0
- avrotize/avrotots/gitignore.jinja +34 -0
- avrotize/avrotots/index.ts.jinja +0 -0
- avrotize/avrotots/package.json.jinja +23 -0
- avrotize/avrotots/tsconfig.json.jinja +21 -0
- avrotize/avrotots.py +687 -0
- avrotize/avrotoxsd.py +344 -0
- avrotize/cddltostructure.py +1841 -0
- avrotize/commands.json +3496 -0
- avrotize/common.py +834 -0
- avrotize/constants.py +87 -0
- avrotize/csvtoavro.py +132 -0
- avrotize/datapackagetoavro.py +76 -0
- avrotize/dependencies/cpp/vcpkg/vcpkg.json +19 -0
- avrotize/dependencies/cs/net90/dependencies.csproj +29 -0
- avrotize/dependencies/go/go121/go.mod +6 -0
- avrotize/dependencies/java/jdk21/pom.xml +91 -0
- avrotize/dependencies/python/py312/requirements.txt +13 -0
- avrotize/dependencies/rust/stable/Cargo.toml +17 -0
- avrotize/dependencies/typescript/node22/package.json +16 -0
- avrotize/dependency_resolver.py +348 -0
- avrotize/dependency_version.py +432 -0
- avrotize/generic/generic.avsc +57 -0
- avrotize/jsonstoavro.py +2167 -0
- avrotize/jsonstostructure.py +2864 -0
- avrotize/jstructtoavro.py +878 -0
- avrotize/kstructtoavro.py +93 -0
- avrotize/kustotoavro.py +455 -0
- avrotize/openapitostructure.py +717 -0
- avrotize/parquettoavro.py +157 -0
- avrotize/proto2parser.py +498 -0
- avrotize/proto3parser.py +403 -0
- avrotize/prototoavro.py +382 -0
- avrotize/prototypes/any.avsc +19 -0
- avrotize/prototypes/api.avsc +106 -0
- avrotize/prototypes/duration.avsc +20 -0
- avrotize/prototypes/field_mask.avsc +18 -0
- avrotize/prototypes/struct.avsc +60 -0
- avrotize/prototypes/timestamp.avsc +20 -0
- avrotize/prototypes/type.avsc +253 -0
- avrotize/prototypes/wrappers.avsc +117 -0
- avrotize/structuretocddl.py +597 -0
- avrotize/structuretocpp/CMakeLists.txt.jinja +76 -0
- avrotize/structuretocpp/build.bat.jinja +3 -0
- avrotize/structuretocpp/build.sh.jinja +3 -0
- avrotize/structuretocpp/dataclass_body.jinja +50 -0
- avrotize/structuretocpp/vcpkg.json.jinja +11 -0
- avrotize/structuretocpp.py +697 -0
- avrotize/structuretocsharp/class_test.cs.jinja +180 -0
- avrotize/structuretocsharp/dataclass_core.jinja +156 -0
- avrotize/structuretocsharp/enum_test.cs.jinja +36 -0
- avrotize/structuretocsharp/json_structure_converters.cs.jinja +399 -0
- avrotize/structuretocsharp/program.cs.jinja +49 -0
- avrotize/structuretocsharp/project.csproj.jinja +17 -0
- avrotize/structuretocsharp/project.sln.jinja +34 -0
- avrotize/structuretocsharp/testproject.csproj.jinja +18 -0
- avrotize/structuretocsharp/tuple_converter.cs.jinja +121 -0
- avrotize/structuretocsharp.py +2295 -0
- avrotize/structuretocsv.py +365 -0
- avrotize/structuretodatapackage.py +659 -0
- avrotize/structuretodb.py +1125 -0
- avrotize/structuretogo/go_enum.jinja +12 -0
- avrotize/structuretogo/go_helpers.jinja +26 -0
- avrotize/structuretogo/go_interface.jinja +18 -0
- avrotize/structuretogo/go_struct.jinja +187 -0
- avrotize/structuretogo/go_test.jinja +70 -0
- avrotize/structuretogo.py +729 -0
- avrotize/structuretographql.py +502 -0
- avrotize/structuretoiceberg.py +355 -0
- avrotize/structuretojava/choice_core.jinja +34 -0
- avrotize/structuretojava/class_core.jinja +23 -0
- avrotize/structuretojava/enum_core.jinja +18 -0
- avrotize/structuretojava/equals_hashcode.jinja +30 -0
- avrotize/structuretojava/pom.xml.jinja +26 -0
- avrotize/structuretojava/tuple_core.jinja +49 -0
- avrotize/structuretojava.py +938 -0
- avrotize/structuretojs/class_core.js.jinja +33 -0
- avrotize/structuretojs/enum_core.js.jinja +10 -0
- avrotize/structuretojs/package.json.jinja +12 -0
- avrotize/structuretojs/test_class.js.jinja +84 -0
- avrotize/structuretojs/test_enum.js.jinja +58 -0
- avrotize/structuretojs/test_runner.js.jinja +45 -0
- avrotize/structuretojs.py +657 -0
- avrotize/structuretojsons.py +498 -0
- avrotize/structuretokusto.py +639 -0
- avrotize/structuretomd/README.md.jinja +204 -0
- avrotize/structuretomd.py +322 -0
- avrotize/structuretoproto.py +764 -0
- avrotize/structuretopython/dataclass_core.jinja +363 -0
- avrotize/structuretopython/enum_core.jinja +45 -0
- avrotize/structuretopython/map_alias.jinja +21 -0
- avrotize/structuretopython/pyproject_toml.jinja +23 -0
- avrotize/structuretopython/test_class.jinja +103 -0
- avrotize/structuretopython/test_enum.jinja +34 -0
- avrotize/structuretopython.py +799 -0
- avrotize/structuretorust/dataclass_enum.rs.jinja +63 -0
- avrotize/structuretorust/dataclass_struct.rs.jinja +121 -0
- avrotize/structuretorust/dataclass_union.rs.jinja +81 -0
- avrotize/structuretorust.py +714 -0
- avrotize/structuretots/class_core.ts.jinja +78 -0
- avrotize/structuretots/enum_core.ts.jinja +6 -0
- avrotize/structuretots/gitignore.jinja +8 -0
- avrotize/structuretots/index.ts.jinja +1 -0
- avrotize/structuretots/package.json.jinja +39 -0
- avrotize/structuretots/test_class.ts.jinja +35 -0
- avrotize/structuretots/tsconfig.json.jinja +21 -0
- avrotize/structuretots.py +740 -0
- avrotize/structuretoxsd.py +679 -0
- avrotize/xsdtoavro.py +413 -0
- avrotize-2.21.1.dist-info/METADATA +1319 -0
- avrotize-2.21.1.dist-info/RECORD +171 -0
- avrotize-2.21.1.dist-info/WHEEL +4 -0
- avrotize-2.21.1.dist-info/entry_points.txt +3 -0
- avrotize-2.21.1.dist-info/licenses/LICENSE +201 -0
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
package {{ base_package }}
|
|
2
|
+
|
|
3
|
+
{%- if doc %}
|
|
4
|
+
// {{ doc }}
|
|
5
|
+
{%- endif %}
|
|
6
|
+
type {{ enum_name }} {{ base_type }}
|
|
7
|
+
|
|
8
|
+
const (
|
|
9
|
+
{%- for symbol in symbols %}
|
|
10
|
+
{{ enum_name }}_{{ symbol }} {{ enum_name }} = {% if base_type == 'string' %}"{{ symbol }}"{% else %}{{ loop.index0 }}{% endif %}
|
|
11
|
+
{%- endfor %}
|
|
12
|
+
)
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
package {{ base_package }}
|
|
2
|
+
|
|
3
|
+
{%- if needs_time_import %}
|
|
4
|
+
|
|
5
|
+
import "time"
|
|
6
|
+
{%- endif %}
|
|
7
|
+
|
|
8
|
+
{%- for struct in structs %}
|
|
9
|
+
|
|
10
|
+
// CreateInstance{{ struct.name }} creates a new instance of {{ struct.name }} with sample data
|
|
11
|
+
func CreateInstance{{ struct.name }}() {{ struct.name }} {
|
|
12
|
+
return {{ struct.name }}{
|
|
13
|
+
{%- for field in struct.fields %}
|
|
14
|
+
{{ field.name }}: {{ field.value }},
|
|
15
|
+
{%- endfor %}
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
{% endfor %}
|
|
19
|
+
|
|
20
|
+
{%- for enum in enums %}
|
|
21
|
+
|
|
22
|
+
// CreateInstance{{ enum.name }} creates a sample instance of {{ enum.name }}
|
|
23
|
+
func CreateInstance{{ enum.name }}() {{ enum.name }} {
|
|
24
|
+
return {{ enum.name }}_{{ enum.symbols[0] }}
|
|
25
|
+
}
|
|
26
|
+
{% endfor %}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
package {{ base_package }}
|
|
2
|
+
|
|
3
|
+
{%- if doc %}
|
|
4
|
+
// {{ doc }}
|
|
5
|
+
// This is an abstract type - implementations should use concrete types that implement this interface.
|
|
6
|
+
{%- endif %}
|
|
7
|
+
type {{ interface_name }} interface {
|
|
8
|
+
{%- for method in methods %}
|
|
9
|
+
{%- if method.doc %}
|
|
10
|
+
// {{ method.doc }}
|
|
11
|
+
{%- endif %}
|
|
12
|
+
{%- if method.return_type %}
|
|
13
|
+
{{ method.name }}() {{ method.return_type }}
|
|
14
|
+
{%- else %}
|
|
15
|
+
{{ method.name }}({{ method.param_name }} {{ method.param_type }})
|
|
16
|
+
{%- endif %}
|
|
17
|
+
{%- endfor %}
|
|
18
|
+
}
|
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
package {{ base_package }}
|
|
2
|
+
|
|
3
|
+
import (
|
|
4
|
+
{%- for import_item in imports %}
|
|
5
|
+
"{{ import_item }}"
|
|
6
|
+
{%- endfor %}
|
|
7
|
+
{%- if json_annotation %}
|
|
8
|
+
"encoding/json"
|
|
9
|
+
{%- endif %}
|
|
10
|
+
{%- if json_annotation or avro_annotation %}
|
|
11
|
+
"compress/gzip"
|
|
12
|
+
"bytes"
|
|
13
|
+
"fmt"
|
|
14
|
+
"io"
|
|
15
|
+
"strings"
|
|
16
|
+
{%- endif %}
|
|
17
|
+
{%- if avro_annotation %}
|
|
18
|
+
"github.com/hamba/avro/v2"
|
|
19
|
+
{%- endif %}
|
|
20
|
+
{%- for ref_pkg in referenced_packages %}
|
|
21
|
+
"{{ ref_pkg }}"
|
|
22
|
+
{%- endfor %}
|
|
23
|
+
)
|
|
24
|
+
|
|
25
|
+
{%- if doc %}
|
|
26
|
+
// {{ doc }}
|
|
27
|
+
{%- endif %}
|
|
28
|
+
type {{ struct_name }} struct {
|
|
29
|
+
{%- for field in fields %}
|
|
30
|
+
{{ field.name }} {{ field.type }}{% if json_annotation or avro_annotation %} `{%- if json_annotation -%}json:"{{ field.original_name }}"{%- endif -%}{%- if avro_annotation %} avro:"{{ field.original_name }}"{%- endif -%}`{% endif %}
|
|
31
|
+
{%- endfor %}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
{%- if base_interface %}
|
|
35
|
+
|
|
36
|
+
// Verify that {{ struct_name }} implements {{ base_interface }} interface
|
|
37
|
+
var _ {{ base_interface }} = (*{{ struct_name }})(nil)
|
|
38
|
+
|
|
39
|
+
{%- for field in fields %}
|
|
40
|
+
|
|
41
|
+
// Get{{ field.name }} returns the {{ field.original_name }} field
|
|
42
|
+
func (s *{{ struct_name }}) Get{{ field.name }}() {{ field.type }} {
|
|
43
|
+
return s.{{ field.name }}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
// Set{{ field.name }} sets the {{ field.original_name }} field
|
|
47
|
+
func (s *{{ struct_name }}) Set{{ field.name }}(value {{ field.type }}) {
|
|
48
|
+
s.{{ field.name }} = value
|
|
49
|
+
}
|
|
50
|
+
{%- endfor %}
|
|
51
|
+
{%- endif %}
|
|
52
|
+
|
|
53
|
+
{%- if avro_annotation and avro_schema %}
|
|
54
|
+
|
|
55
|
+
// AvroSchema is the embedded Avro schema for {{ struct_name }}
|
|
56
|
+
const {{ struct_name }}AvroSchema = `{{ avro_schema }}`
|
|
57
|
+
|
|
58
|
+
// GetAvroSchema returns the parsed Avro schema for {{ struct_name }}
|
|
59
|
+
func (s *{{ struct_name }}) GetAvroSchema() (avro.Schema, error) {
|
|
60
|
+
return avro.Parse({{ struct_name }}AvroSchema)
|
|
61
|
+
}
|
|
62
|
+
{%- endif %}
|
|
63
|
+
|
|
64
|
+
{%- if json_annotation or avro_annotation %}
|
|
65
|
+
func (s *{{ struct_name }}) ToByteArray(contentType string) ([]byte, error) {
|
|
66
|
+
var result []byte
|
|
67
|
+
var err error
|
|
68
|
+
|
|
69
|
+
// Strip +gzip suffix to get the base media type
|
|
70
|
+
mediaType := strings.Split(contentType, ";")[0]
|
|
71
|
+
isGzipped := strings.HasSuffix(mediaType, "+gzip")
|
|
72
|
+
if isGzipped {
|
|
73
|
+
mediaType = strings.TrimSuffix(mediaType, "+gzip")
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
switch mediaType {
|
|
77
|
+
{%- if json_annotation %}
|
|
78
|
+
case "application/json":
|
|
79
|
+
result, err = json.Marshal(s)
|
|
80
|
+
if err != nil {
|
|
81
|
+
return nil, err
|
|
82
|
+
}
|
|
83
|
+
{%- endif %}
|
|
84
|
+
{%- if avro_annotation %}
|
|
85
|
+
case "avro/binary", "application/vnd.apache.avro+avro":
|
|
86
|
+
schema, err := s.GetAvroSchema()
|
|
87
|
+
if err != nil {
|
|
88
|
+
return nil, fmt.Errorf("failed to parse Avro schema: %w", err)
|
|
89
|
+
}
|
|
90
|
+
result, err = avro.Marshal(schema, s)
|
|
91
|
+
if err != nil {
|
|
92
|
+
return nil, fmt.Errorf("failed to marshal Avro: %w", err)
|
|
93
|
+
}
|
|
94
|
+
{%- endif %}
|
|
95
|
+
default:
|
|
96
|
+
return nil, fmt.Errorf("unsupported media type: %s", mediaType)
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
if isGzipped {
|
|
100
|
+
var buf bytes.Buffer
|
|
101
|
+
gzipWriter := gzip.NewWriter(&buf)
|
|
102
|
+
_, err = gzipWriter.Write(result)
|
|
103
|
+
if err != nil {
|
|
104
|
+
return nil, err
|
|
105
|
+
}
|
|
106
|
+
err = gzipWriter.Close()
|
|
107
|
+
if err != nil {
|
|
108
|
+
return nil, err
|
|
109
|
+
}
|
|
110
|
+
result = buf.Bytes()
|
|
111
|
+
}
|
|
112
|
+
return result, nil
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
func {{ struct_name }}FromData(data interface{}, contentType string) (*{{ struct_name }}, error) {
|
|
116
|
+
var err error
|
|
117
|
+
var s {{ struct_name }}
|
|
118
|
+
|
|
119
|
+
// Strip +gzip suffix to get the base media type
|
|
120
|
+
mediaType := strings.Split(contentType, ";")[0]
|
|
121
|
+
isGzipped := strings.HasSuffix(mediaType, "+gzip")
|
|
122
|
+
if isGzipped {
|
|
123
|
+
mediaType = strings.TrimSuffix(mediaType, "+gzip")
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
if isGzipped {
|
|
127
|
+
var reader io.Reader
|
|
128
|
+
switch v := data.(type) {
|
|
129
|
+
case []byte:
|
|
130
|
+
reader = bytes.NewReader(v)
|
|
131
|
+
case io.Reader:
|
|
132
|
+
reader = v
|
|
133
|
+
default:
|
|
134
|
+
return nil, fmt.Errorf("unsupported data type for gzip: %T", data)
|
|
135
|
+
}
|
|
136
|
+
gzipReader, err := gzip.NewReader(reader)
|
|
137
|
+
if err != nil {
|
|
138
|
+
return nil, err
|
|
139
|
+
}
|
|
140
|
+
defer gzipReader.Close()
|
|
141
|
+
data, err = io.ReadAll(gzipReader)
|
|
142
|
+
if err != nil {
|
|
143
|
+
return nil, err
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
switch mediaType {
|
|
148
|
+
{%- if json_annotation %}
|
|
149
|
+
case "application/json":
|
|
150
|
+
switch v := data.(type) {
|
|
151
|
+
case []byte:
|
|
152
|
+
err = json.Unmarshal(v, &s)
|
|
153
|
+
case string:
|
|
154
|
+
err = json.Unmarshal([]byte(v), &s)
|
|
155
|
+
case io.Reader:
|
|
156
|
+
err = json.NewDecoder(v).Decode(&s)
|
|
157
|
+
default:
|
|
158
|
+
return nil, fmt.Errorf("unsupported data type for JSON: %T", data)
|
|
159
|
+
}
|
|
160
|
+
{%- endif %}
|
|
161
|
+
{%- if avro_annotation %}
|
|
162
|
+
case "avro/binary", "application/vnd.apache.avro+avro":
|
|
163
|
+
var tempInstance {{ struct_name }}
|
|
164
|
+
schema, schemaErr := tempInstance.GetAvroSchema()
|
|
165
|
+
if schemaErr != nil {
|
|
166
|
+
return nil, fmt.Errorf("failed to parse Avro schema: %w", schemaErr)
|
|
167
|
+
}
|
|
168
|
+
switch v := data.(type) {
|
|
169
|
+
case []byte:
|
|
170
|
+
err = avro.Unmarshal(schema, v, &s)
|
|
171
|
+
default:
|
|
172
|
+
return nil, fmt.Errorf("unsupported data type for Avro: %T", data)
|
|
173
|
+
}
|
|
174
|
+
{%- endif %}
|
|
175
|
+
default:
|
|
176
|
+
return nil, fmt.Errorf("unsupported media type: %s", mediaType)
|
|
177
|
+
}
|
|
178
|
+
if err != nil {
|
|
179
|
+
return nil, err
|
|
180
|
+
}
|
|
181
|
+
return &s, nil
|
|
182
|
+
}
|
|
183
|
+
{%- endif %}
|
|
184
|
+
|
|
185
|
+
func (s *{{ struct_name }}) ToObject() interface{} {
|
|
186
|
+
return s
|
|
187
|
+
}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
package {{ base_package }}
|
|
2
|
+
|
|
3
|
+
import (
|
|
4
|
+
"testing"
|
|
5
|
+
{%- if json_annotation and kind == 'struct' %}
|
|
6
|
+
"encoding/json"
|
|
7
|
+
{%- endif %}
|
|
8
|
+
)
|
|
9
|
+
|
|
10
|
+
func Test{{ struct_name }}(t *testing.T) {
|
|
11
|
+
{%- if kind == 'struct' %}
|
|
12
|
+
{%- if json_annotation %}
|
|
13
|
+
instance := CreateInstance{{ struct_name }}()
|
|
14
|
+
|
|
15
|
+
// Test JSON marshaling
|
|
16
|
+
data, err := json.Marshal(&instance)
|
|
17
|
+
if err != nil {
|
|
18
|
+
t.Fatalf("Failed to marshal {{ struct_name }}: %v", err)
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
// Test JSON unmarshaling
|
|
22
|
+
var decoded {{ struct_name }}
|
|
23
|
+
err = json.Unmarshal(data, &decoded)
|
|
24
|
+
if err != nil {
|
|
25
|
+
t.Fatalf("Failed to unmarshal {{ struct_name }}: %v", err)
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
// Test ToByteArray and FromData methods
|
|
29
|
+
contentType := "application/json"
|
|
30
|
+
byteArray, err := instance.ToByteArray(contentType)
|
|
31
|
+
if err != nil {
|
|
32
|
+
t.Fatalf("Failed to convert to byte array: %v", err)
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
fromData, err := {{ struct_name }}FromData(byteArray, contentType)
|
|
36
|
+
if err != nil {
|
|
37
|
+
t.Fatalf("Failed to create from data: %v", err)
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
if fromData == nil {
|
|
41
|
+
t.Fatal("FromData returned nil")
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
// Test with gzipped data
|
|
45
|
+
contentTypeGzip := "application/json+gzip"
|
|
46
|
+
byteArrayGzip, err := instance.ToByteArray(contentTypeGzip)
|
|
47
|
+
if err != nil {
|
|
48
|
+
t.Fatalf("Failed to convert to gzipped byte array: %v", err)
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
fromDataGzip, err := {{ struct_name }}FromData(byteArrayGzip, contentTypeGzip)
|
|
52
|
+
if err != nil {
|
|
53
|
+
t.Fatalf("Failed to create from gzipped data: %v", err)
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
if fromDataGzip == nil {
|
|
57
|
+
t.Fatal("FromData with gzip returned nil")
|
|
58
|
+
}
|
|
59
|
+
{%- else %}
|
|
60
|
+
// Basic instance creation test (no JSON serialization without json annotation)
|
|
61
|
+
instance := CreateInstance{{ struct_name }}()
|
|
62
|
+
_ = instance // Verify instance creation works
|
|
63
|
+
{%- endif %}
|
|
64
|
+
{%- elif kind == 'enum' %}
|
|
65
|
+
// Test enum values
|
|
66
|
+
{%- for symbol in fields %}
|
|
67
|
+
_ = {{ struct_name }}_{{ symbol }}
|
|
68
|
+
{%- endfor %}
|
|
69
|
+
{%- endif %}
|
|
70
|
+
}
|