Example #1
0
 def format_option_map(self, value: dict) -> str:
     keys = list(value.keys())
     last_index = len(keys) - 1
     result: list = list()
     for index, key in enumerate(keys):
         endl = "," if (index != last_index) else ""
         append_indented(result, f"{key}: {self.format_option_map_value(value[key])}{endl}")
     return "".join(result)
Example #2
0
    def format_list_map_value(self, value) -> str:

        last_index = len(value) - 1
        result: list = []
        for index, elm in enumerate(value):
            endl = "," if (index != last_index) else ""
            append_indented(result, f"{self.format_option_map_value(elm)}{endl}")
        return "".join(result)
Example #3
0
    def to_schema(self):
        result: list = list()
        append_documentation(result, self.documentation)
        result.append(f"extend {self.name} {{")
        if self.fields:
            result.append("\n")
        for field in self.fields:
            append_indented(result, field.to_schema())

        result.append("}\n")
        return result
Example #4
0
    def to_schema(self) -> str:
        result: list = []
        append_documentation(result, self.documentation)

        # TODO: compare lower() to lowercase() and toLowerCase(Locale.US) Kotlin
        if self.label:
            result.append(f"{str(self.label.name).lower()} ")
        result.append(f"group {self.name} = {self.tag} {{")
        if self.fields:
            result.append("\n")
            for field in self.fields:
                append_indented(result, field.to_schema())
        result.append("}\n")
        return "".join(result)
Example #5
0
    def to_schema(self):
        result: list = list()
        append_documentation(result, self.documentation)
        result.append(f"service {self.name} {{")
        if self.options:
            result.append("\n")
        for option in self.options:
            append_indented(result, option.to_schema_declaration())

        if self.rpcs:
            result.append('\n')
            for rpc in self.rpcs:
                append_indented(result, rpc.to_schema())

        result.append("}\n")
        return result
Example #6
0
    def append_options(options: list):
        data: list = list()
        count = len(options)
        if count == 1:
            data.append('[')
            data.append(try_to_schema(options[0]))
            data.append(']')
            return "".join(data)

        data.append("[\n")
        for i in range(0, count):
            if i < count:
                endl = ","
            else:
                endl = ""
            append_indented(data, try_to_schema(options[i]) + endl)
        data.append(']')
        return "".join(data)
Example #7
0
    def to_schema(self) -> str:
        result: list = list()
        append_documentation(result, self.documentation)
        result.append(f"enum {self.name} {{")

        if self.options or self.constants:
            result.append("\n")

        if self.options:
            for option in self.options:
                append_indented(result, option.to_schema_declaration())

        if self.constants:
            for constant in self.constants:
                append_indented(result, constant.to_schema())

        result.append("}\n")
        return "".join(result)
Example #8
0
    def to_schema(self) -> str:
        result: list = list()
        append_documentation(result, self.documentation)
        result.append(f"rpc {self.name} (")

        if self.request_streaming:
            result.append("stream ")
        result.append(f"{self.request_type}) returns (")

        if self.response_streaming:
            result.append("stream ")
        result.append(f"{self.response_type})")

        if self.options:
            result.append(" {\n")
            for option in self.options:
                append_indented(result, option.to_schema_declaration())
            result.append("}")
        result.append(";\n")
        return "".join(result)
Example #9
0
    def to_schema(self) -> str:
        result: list = list()
        append_documentation(result, self.documentation)
        result.append(f"oneof {self.name} {{")
        if self.options:
            for option in self.options:
                append_indented(result, option.to_schema_declaration())

        if self.fields:
            result.append("\n")
            for field in self.fields:
                append_indented(result, field.to_schema())
        if self.groups:
            result.append("\n")
            for group in self.groups:
                append_indented(result, group.to_schema())
        result.append("}\n")
        return "".join(result)
Example #10
0
    def to_schema(self) -> str:
        result: list = list()
        append_documentation(result, self.documentation)
        result.append(f"message {self.name} {{")
        if self.reserveds:
            result.append("\n")
            for reserved in self.reserveds:
                append_indented(result, reserved.to_schema())

        if self.options:
            result.append("\n")
            for option in self.options:
                append_indented(result, option.to_schema_declaration())

        if self.fields:
            for field in self.fields:
                result.append("\n")
                append_indented(result, field.to_schema())

        if self.one_ofs:
            for one_of in self.one_ofs:
                result.append("\n")
                append_indented(result, one_of.to_schema())

        if self.groups:
            for group in self.groups:
                result.append("\n")
                append_indented(result, group.to_schema())

        if self.extensions:
            result.append("\n")
            for extension in self.extensions:
                append_indented(result, extension.to_schema())

        if self.nested_types:
            result.append("\n")
            for nested_type in self.nested_types:
                append_indented(result, nested_type.to_schema())

        result.append("}\n")
        return "".join(result)