From 049c2e42fcb2b97390f29093d0bd67faef44db57 Mon Sep 17 00:00:00 2001 From: Jarkko Jaakola Date: Fri, 24 May 2024 10:29:52 +0300 Subject: [PATCH] fix: Format boolean options to lowercase string in schema --- karapace/protobuf/option_element.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/karapace/protobuf/option_element.py b/karapace/protobuf/option_element.py index 9ff50fe8e..70622d5ef 100644 --- a/karapace/protobuf/option_element.py +++ b/karapace/protobuf/option_element.py @@ -31,10 +31,14 @@ def __init__(self, name: str, kind: Kind, value, is_parenthesized: bool = False) self.formattedName = f"({self.name})" if is_parenthesized else self.name def to_schema(self) -> str: - aline = None + aline = "" if self.kind == self.Kind.STRING: aline = f'{self.formattedName} = "{self.value}"' - elif self.kind in [self.Kind.BOOLEAN, self.Kind.NUMBER, self.Kind.ENUM]: + elif self.kind == self.Kind.BOOLEAN: + aline = f"{self.formattedName} = {str(self.value).lower()}" + elif self.kind == self.Kind.NUMBER: + aline = f"{self.formattedName} = {self.value}" + elif self.kind == self.Kind.ENUM: aline = f"{self.formattedName} = {self.value}" elif self.kind == self.Kind.OPTION: aline = f"{self.formattedName}.{try_to_schema(self.value)}" @@ -42,6 +46,8 @@ def to_schema(self) -> str: aline = [f"{self.formattedName} = {{\n", self.format_option_map(self.value), "}"] elif self.kind == self.Kind.LIST: aline = [f"{self.formattedName} = ", self.append_options(self.value)] + else: + raise ValueError("Unknown value Kind.") if isinstance(aline, list): return "".join(aline)