avrotize 2.22.0__py3-none-any.whl → 2.22.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/_version.py CHANGED
@@ -28,7 +28,7 @@ version_tuple: VERSION_TUPLE
28
28
  commit_id: COMMIT_ID
29
29
  __commit_id__: COMMIT_ID
30
30
 
31
- __version__ = version = '2.22.0'
32
- __version_tuple__ = version_tuple = (2, 22, 0)
31
+ __version__ = version = '2.22.1'
32
+ __version_tuple__ = version_tuple = (2, 22, 1)
33
33
 
34
34
  __commit_id__ = commit_id = None
avrotize/avrotojsons.py CHANGED
@@ -184,16 +184,38 @@ class AvroToJsonSchemaConverter:
184
184
  def handle_type_union(self, types: List[Union[str, Dict[str, Any]]]) -> Dict[str, Any] | List[Dict[str, Any]| str] | str:
185
185
  """
186
186
  Handle Avro type unions, returning a JSON schema that validates against any of the types.
187
+ Preserves nullability from Avro unions containing 'null'.
187
188
  """
189
+ is_nullable = 'null' in types
188
190
  non_null_types = [t for t in types if t != 'null']
191
+
189
192
  if len(non_null_types) == 1:
190
- # Single non-null type
191
- return self.parse_avro_schema(non_null_types[0])
193
+ # Single non-null type - check if it's a primitive that can use type array
194
+ single_type = non_null_types[0]
195
+ json_schema = self.parse_avro_schema(single_type)
196
+
197
+ if is_nullable and isinstance(json_schema, dict):
198
+ # For primitives with a simple 'type' field, we can use type array notation
199
+ if 'type' in json_schema and isinstance(json_schema['type'], str) and '$ref' not in json_schema:
200
+ # Primitive type - add null to type array
201
+ json_schema = copy.deepcopy(json_schema)
202
+ json_schema['type'] = [json_schema['type'], 'null']
203
+ elif '$ref' in json_schema:
204
+ # Reference type - use oneOf with null
205
+ json_schema = {
206
+ 'oneOf': [
207
+ {'type': 'null'},
208
+ json_schema
209
+ ]
210
+ }
211
+ return json_schema
192
212
  else:
193
213
  # Multiple non-null types
194
- union_types = [self.convert_reference(t) if isinstance(t,str) and t in self.defined_types else self.avro_primitive_to_json_type(t)
214
+ union_types = [self.convert_reference(t) if isinstance(t, str) and t in self.defined_types else self.avro_primitive_to_json_type(t)
195
215
  if isinstance(t, str) else self.parse_avro_schema(t)
196
216
  for t in non_null_types]
217
+ if is_nullable:
218
+ union_types.insert(0, {'type': 'null'})
197
219
  return {
198
220
  'oneOf': union_types
199
221
  }
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: avrotize
3
- Version: 2.22.0
3
+ Version: 2.22.1
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
@@ -1,6 +1,6 @@
1
1
  avrotize/__init__.py,sha256=t5h5wkHXr6M0mmHAB5rhjZ3Gxy9xutGTGIfojfao9rI,3820
2
2
  avrotize/__main__.py,sha256=5pY8dYAURcOnFRvgb6fgaOIa_SOzPLIWbU8-ZTQ0jG4,88
3
- avrotize/_version.py,sha256=Lz3YaEDxgU9K9pMHrjQaxnWiYLkcYeae4-H-EdHDdz4,706
3
+ avrotize/_version.py,sha256=2Rc4v0v4QLr2kVq6V3tQOneBqZW00NrqxdxCLKrfD00,706
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
@@ -13,7 +13,7 @@ avrotize/avrotographql.py,sha256=i6G7xWjH_Lsn_CLiM4BCPb8OyZuCCpsYjXwXNTRMwEE,739
13
13
  avrotize/avrotoiceberg.py,sha256=plVHGWkED1YDLcMDxL7NMdJl2f8G32hwlNWFrBLcsD8,9057
14
14
  avrotize/avrotojava.py,sha256=NZZ7mUFVzvp7HBsU0XPiCwl4GVXE1RtS86pfNFJsIq8,135427
15
15
  avrotize/avrotojs.py,sha256=QjB6XjFnDrpZBZrrWqS0TN8fQfRXBfhHabfG73FOIo8,12249
16
- avrotize/avrotojsons.py,sha256=WXWniQqwcl8eU35VibDv7qJJwbiLV_yoWZ4JxiZ8mHA,21588
16
+ avrotize/avrotojsons.py,sha256=I7EJz_IaCYLNzcycYXDOLAexHRHQfyb4yoWcxJ02vb0,22697
17
17
  avrotize/avrotojstruct.py,sha256=-Hs4Ta958bRKmOfSTzRFENABCZ6lQPSPbIBEXvOQD1M,14660
18
18
  avrotize/avrotokusto.py,sha256=D6AiRPa5uiZbqo9dqrFvAknsF5oNXgIzk8_08uZTZ2M,17636
19
19
  avrotize/avrotomd.py,sha256=WHPHnfmkI3xDNIHKZ3ReYxj6tib1eCny3JOznNSN6r8,5348
@@ -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-2.22.0.dist-info/entry_points.txt,sha256=m8J2TWiqbZh7SBQezc1CNrM_GVPWf01zOFcAKhzCC0U,51
168
- avrotize-2.22.0.dist-info/licenses/LICENSE,sha256=xGtQGygTETTtDQJafZCUbpsed3GxO6grmqig-jGEuSk,11348
169
- avrotize-2.22.0.dist-info/WHEEL,sha256=G2gURzTEtmeR8nrdXUJfNiB3VYVxigPQ-bEQujpNiNs,82
170
- avrotize-2.22.0.dist-info/METADATA,sha256=nLTy8xDdjStpgRxX2cOBQ8WSgA_EDF6uHgnk-AQFij8,80208
171
- avrotize-2.22.0.dist-info/RECORD,,
167
+ avrotize-2.22.1.dist-info/entry_points.txt,sha256=m8J2TWiqbZh7SBQezc1CNrM_GVPWf01zOFcAKhzCC0U,51
168
+ avrotize-2.22.1.dist-info/licenses/LICENSE,sha256=xGtQGygTETTtDQJafZCUbpsed3GxO6grmqig-jGEuSk,11348
169
+ avrotize-2.22.1.dist-info/WHEEL,sha256=G2gURzTEtmeR8nrdXUJfNiB3VYVxigPQ-bEQujpNiNs,82
170
+ avrotize-2.22.1.dist-info/METADATA,sha256=VlqM6wO1RE7NuEFnJMM2Gcdy3ZCJRVt1jhw6Um3pzig,80208
171
+ avrotize-2.22.1.dist-info/RECORD,,