From aa907ce74cc92db840cc655f7e26f325f0b6ccdb Mon Sep 17 00:00:00 2001 From: Elia Migliore Date: Thu, 11 Apr 2024 12:38:31 +0200 Subject: [PATCH] Adding support to enable the feature under a configuration --- karapace/config.py | 2 ++ karapace/schema_registry_apis.py | 10 ++++++++-- tests/integration/utils/cluster.py | 1 + 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/karapace/config.py b/karapace/config.py index 9212f6348..574b22603 100644 --- a/karapace/config.py +++ b/karapace/config.py @@ -76,6 +76,7 @@ class Config(TypedDict): karapace_registry: bool name_strategy: str name_strategy_validation: bool + normalization_of_schema_enabled: bool master_election_strategy: str protobuf_runtime_directory: str @@ -148,6 +149,7 @@ class ConfigDefaults(Config, total=False): "karapace_registry": False, "name_strategy": "topic_name", "name_strategy_validation": True, + "normalization_of_schema_enabled": False, "master_election_strategy": "lowest", "protobuf_runtime_directory": "runtime", } diff --git a/karapace/schema_registry_apis.py b/karapace/schema_registry_apis.py index cc8aa341f..5c59e9a84 100644 --- a/karapace/schema_registry_apis.py +++ b/karapace/schema_registry_apis.py @@ -1097,7 +1097,10 @@ async def subjects_schema_post( schema_type = self._validate_schema_type(content_type=content_type, data=body) references = self._validate_references(content_type, schema_type, body) references, new_schema_dependencies = self.schema_registry.resolve_references(references) - normalize = request.query.get("normalize", "false").lower() == "true" + normalize = ( + request.query.get("normalize", "false").lower() == "true" + and self.schema_registry.config["normalization_of_schema_enabled"] + ) try: # When checking if schema is already registered, allow unvalidated schema in as # there might be stored schemas that are non-compliant from the past. @@ -1197,7 +1200,10 @@ async def subject_post( self._validate_schema_request_body(content_type, body) schema_type = self._validate_schema_type(content_type, body) self._validate_schema_key(content_type, body) - normalize = request.query.get("normalize", "false").lower() == "true" + normalize = ( + request.query.get("normalize", "false").lower() == "true" + and self.schema_registry.config["normalization_of_schema_enabled"] + ) references = self._validate_references(content_type, schema_type, body) try: diff --git a/tests/integration/utils/cluster.py b/tests/integration/utils/cluster.py index 31c06e4bd..a59f32c8d 100644 --- a/tests/integration/utils/cluster.py +++ b/tests/integration/utils/cluster.py @@ -61,6 +61,7 @@ async def start_schema_registry_cluster( config.setdefault("advertised_hostname", host) config.setdefault("topic_name", schemas_topic) config.setdefault("karapace_registry", True) + config.setdefault("normalization_of_schema_enabled", True) config.setdefault( "log_format", "%(asctime)s [%(threadName)s] %(filename)s:%(funcName)s:%(lineno)d %(message)s",