@@ -142,6 +142,10 @@ class ProtobufSerializer(object):
142
142
| ``auto.register.schemas`` | bool | previously associated with a particular subject. |
143
143
| | | Defaults to True. |
144
144
+-------------------------------------+----------+------------------------------------------------------+
145
+ | | | Whether to normalize schemas, which will |
146
+ | ``normalize.schemas`` | bool | transform schemas to have a consistent format, |
147
+ | | | including ordering properties and references. |
148
+ +---------------------------+----------+----------------------------------------------------------------+
145
149
| | | Whether to use the latest subject version for |
146
150
| ``use.latest.version`` | bool | serialization. |
147
151
| | | WARNING: There is no check that the latest |
@@ -212,14 +216,15 @@ class ProtobufSerializer(object):
212
216
`Protobuf API reference <https://googleapis.dev/python/protobuf/latest/google/protobuf.html>`_
213
217
214
218
""" # noqa: E501
215
- __slots__ = ['_auto_register' , '_use_latest_version' , '_skip_known_types' ,
219
+ __slots__ = ['_auto_register' , '_normalize_schemas' , ' _use_latest_version' , '_skip_known_types' ,
216
220
'_registry' , '_known_subjects' ,
217
221
'_msg_class' , '_msg_index' , '_schema' , '_schema_id' ,
218
222
'_ref_reference_subject_func' , '_subject_name_func' ,
219
223
'_use_deprecated_format' ]
220
224
# default configuration
221
225
_default_conf = {
222
226
'auto.register.schemas' : True ,
227
+ 'normalize.schemas' : False ,
223
228
'use.latest.version' : False ,
224
229
'skip.known.types' : False ,
225
230
'subject.name.strategy' : topic_subject_name_strategy ,
@@ -245,6 +250,10 @@ def __init__(self, msg_type, schema_registry_client, conf=None):
245
250
if not isinstance (self ._auto_register , bool ):
246
251
raise ValueError ("auto.register.schemas must be a boolean value" )
247
252
253
+ self ._normalize_schemas = conf_copy .pop ('normalize.schemas' )
254
+ if not isinstance (self ._normalize_schemas , bool ):
255
+ raise ValueError ("normalize.schemas must be a boolean value" )
256
+
248
257
self ._use_latest_version = conf_copy .pop ('use.latest.version' )
249
258
if not isinstance (self ._use_latest_version , bool ):
250
259
raise ValueError ("use.latest.version must be a boolean value" )
@@ -405,10 +414,11 @@ def __call__(self, message_type, ctx):
405
414
406
415
if self ._auto_register :
407
416
self ._schema_id = self ._registry .register_schema (subject ,
408
- self ._schema )
417
+ self ._schema ,
418
+ self ._normalize_schemas )
409
419
else :
410
420
self ._schema_id = self ._registry .lookup_schema (
411
- subject , self ._schema ).schema_id
421
+ subject , self ._schema , self . _normalize_schemas ).schema_id
412
422
413
423
self ._known_subjects .add (subject )
414
424
0 commit comments