Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix java multiple files protobuf option rendering #884

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions karapace/protobuf/option_element.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,23 @@ 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)}"
elif self.kind == self.Kind.MAP:
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)
Expand Down
25 changes: 25 additions & 0 deletions tests/unit/test_protobuf_binary_serialization.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,36 @@
"CgdkZWZhdWx0Ig8KA0tleRIICgJpZBgBKAUiLQoDRG9nEgoKBG5hbWUYASgJEgwKBndlaWdodBgCKAUSDAoEdG95cxgEIAMoCWIGcHJvdG8z"
)

schema_serialized2 = (
"CiZwcm90by90ZWNoL2Rvam8vZHNwL3YxL2V2ZW50X2tleS5wcm90bxIQdGVjaC5kb2pvLmRzcC52MSIaCghFdmVudEtleRIOCgJpZBgBIAEoCVI"
+ "CaWRCiAEKFGNvbS50ZWNoLmRvam8uZHNwLnYxQg1FdmVudEtleVByb3RvUAGiAgNURESqAhBUZWNoLkRvam8uRHNwLlYxygIQVGVjaFxEb2pvXER"
+ "zcFxWMeICHFRlY2hcRG9qb1xEc3BcVjFcR1BCTWV0YWRhdGHqAhNUZWNoOjpEb2pvOjpEc3A6OlYxYgZwcm90bzM="
)

schema_plain2 = """\
syntax = "proto3";
package tech.dojo.dsp.v1;

option java_package = "com.tech.dojo.dsp.v1";
option java_outer_classname = "EventKeyProto";
option java_multiple_files = true;
option objc_class_prefix = "TDD";
option csharp_namespace = "Tech.Dojo.Dsp.V1";
option php_namespace = "Tech\\\\Dojo\\\\Dsp\\\\V1";
option php_metadata_namespace = "Tech\\\\Dojo\\\\Dsp\\\\V1\\\\GPBMetadata";
option ruby_package = "Tech::Dojo::Dsp::V1";

message EventKey {
string id = 1;
}
"""


@pytest.mark.parametrize(
"schema_plain,schema_serialized",
[
(schema_plain1, schema_serialized1),
(schema_plain2, schema_serialized2),
(schema_protobuf_plain, schema_protobuf_plain_bin),
(schema_protobuf_order_after, schema_protobuf_order_after_bin),
(schema_protobuf_nested_message4, schema_protobuf_nested_message4_bin),
Expand Down
Loading