|
39 | 39 | from google.api import resource_pb2 |
40 | 40 | from google.api_core import exceptions # type: ignore |
41 | 41 | from google.protobuf import descriptor_pb2 # type: ignore |
| 42 | +from google.protobuf.json_format import MessageToDict # type: ignore |
42 | 43 |
|
43 | 44 | from gapic import utils |
44 | 45 | from gapic.schema import metadata |
@@ -413,7 +414,7 @@ def get_field(self, *field_path: str, |
413 | 414 | # Get the first field in the path. |
414 | 415 | first_field = field_path[0] |
415 | 416 | cursor = self.fields[first_field + |
416 | | - ('_' if first_field in utils.RESERVED_NAMES else '')] |
| 417 | + ('_' if first_field in utils.RESERVED_NAMES else '')] |
417 | 418 |
|
418 | 419 | # Base case: If this is the last field in the path, return it outright. |
419 | 420 | if len(field_path) == 1: |
@@ -536,6 +537,18 @@ def with_context(self, *, collisions: FrozenSet[str]) -> 'EnumType': |
536 | 537 | meta=self.meta.with_context(collisions=collisions), |
537 | 538 | ) |
538 | 539 |
|
| 540 | + @property |
| 541 | + def options_dict(self) -> Dict: |
| 542 | + """Return the EnumOptions (if present) as a dict. |
| 543 | +
|
| 544 | + This is a hack to support a pythonic structure representation for |
| 545 | + the generator templates. |
| 546 | + """ |
| 547 | + return MessageToDict( |
| 548 | + self.enum_pb.options, |
| 549 | + preserving_proto_field_name=True |
| 550 | + ) |
| 551 | + |
539 | 552 |
|
540 | 553 | @dataclasses.dataclass(frozen=True) |
541 | 554 | class PythonType: |
@@ -869,7 +882,7 @@ def paged_result_field(self) -> Optional[Field]: |
869 | 882 |
|
870 | 883 | # The request must have page_token and next_page_token as they keep track of pages |
871 | 884 | for source, source_type, name in ((self.input, str, 'page_token'), |
872 | | - (self.output, str, 'next_page_token')): |
| 885 | + (self.output, str, 'next_page_token')): |
873 | 886 | field = source.fields.get(name, None) |
874 | 887 | if not field or field.type != source_type: |
875 | 888 | return None |
|
0 commit comments