Esempio n. 1
0
 def to_schema(self) -> str:
     result: list = list()
     append_documentation(result, self.documentation)
     result.append(f"{self.name} = {self.tag}")
     if self.options:
         result.append(" ")
         append_options(result, self.options)
     result.append(";\n")
     return "".join(result)
Esempio n. 2
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
Esempio n. 3
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)
Esempio n. 4
0
    def to_schema(self):
        result: list = list()
        append_documentation(result, self.documentation)

        if self.label:
            result.append(f"{self.label.name.lower()} ")

        result.append(f"{self.element_type} {self.name} = {self.tag}")

        options_with_default = self.options_with_special_values()
        if options_with_default:
            result.append(' ')
            append_options(result, options_with_default)
        result.append(";\n")

        return "".join(result)
Esempio n. 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
Esempio n. 6
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)
Esempio n. 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)
Esempio n. 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)
Esempio n. 9
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)
Esempio n. 10
0
    def to_schema(self) -> str:
        result: list = []
        append_documentation(result, self.documentation)
        result.append("extensions ")

        for index in range(0, len(self.values)):
            value = self.values[index]
            if index > 0:
                result.append(", ")
            if isinstance(value, int):
                result.append(str(value))
            # TODO: maybe replace Kotlin IntRange by list?
            elif isinstance(value, KotlinRange):
                result.append(f"{value.minimum} to ")
                last_value = value.maximum
                if last_value < MAX_TAG_VALUE:
                    result.append(str(last_value))
                else:
                    result.append("max")
            else:
                raise AssertionError()

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