Skip to content

Commit

Permalink
Adding support to enable the feature under a configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
eliax1996 committed Apr 11, 2024
1 parent 35de565 commit aa907ce
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
2 changes: 2 additions & 0 deletions karapace/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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",
}
Expand Down
10 changes: 8 additions & 2 deletions karapace/schema_registry_apis.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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:
Expand Down
1 change: 1 addition & 0 deletions tests/integration/utils/cluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit aa907ce

Please sign in to comment.