Skip to content
This repository was archived by the owner on May 29, 2023. It is now read-only.

Commit 2aa15a4

Browse files
Document nested messages correctly. (#4)
1 parent 2e97a9f commit 2aa15a4

File tree

3 files changed

+39
-2
lines changed

3 files changed

+39
-2
lines changed

protoc_docs/parser.py

+12
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,18 @@ def parse_path(self, struct, path, docstring, message_structure=None):
178178
# If the length of the path is 2 or greater, call this method
179179
# recursively.
180180
if len(path) >= 2:
181+
# Nested types are possible.
182+
#
183+
# In this case, we need to ensure that we do not lose
184+
# the outer layers of the nested type name; otherwise the
185+
# insertion point name will be wrong.
186+
if not message_structure.name.endswith(child.name):
187+
message_structure = MessageStructure.get_or_create(
188+
name='{parent}.{child}'.format(
189+
child=child.name,
190+
parent=message_structure.name,
191+
),
192+
)
181193
return self.parse_path(child, path, docstring, message_structure)
182194

183195
# Write the documentation to the appropriate spot.

tests/test_parser.py

+26-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,32 @@ def test_find_docs(self):
5050

5151
# Make incredibly basic assertions about the collected data.
5252
assert len(answer) == 1
53-
assert len(answer['protos/descriptor.proto']) == 22
53+
assert {i.name for i in answer['protos/descriptor.proto']} == {
54+
'google.protobuf.FileDescriptorSet',
55+
'google.protobuf.FieldOptions',
56+
'google.protobuf.FileOptions',
57+
'google.protobuf.MessageOptions',
58+
'google.protobuf.FileDescriptorProto',
59+
'google.protobuf.FieldDescriptorProto',
60+
'google.protobuf.ServiceOptions',
61+
'google.protobuf.MethodDescriptorProto',
62+
'google.protobuf.EnumDescriptorProto',
63+
'google.protobuf.EnumValueDescriptorProto',
64+
'google.protobuf.UninterpretedOption.NamePart',
65+
'google.protobuf.SourceCodeInfo',
66+
'google.protobuf.SourceCodeInfo.Location',
67+
'google.protobuf.GeneratedCodeInfo.Annotation',
68+
'google.protobuf.MethodOptions',
69+
'google.protobuf.DescriptorProto',
70+
'google.protobuf.GeneratedCodeInfo',
71+
'google.protobuf.EnumValueOptions',
72+
'google.protobuf.UninterpretedOption',
73+
'google.protobuf.ServiceDescriptorProto',
74+
'google.protobuf.OneofOptions',
75+
'google.protobuf.DescriptorProto.ReservedRange',
76+
'google.protobuf.OneofDescriptorProto',
77+
'google.protobuf.EnumOptions',
78+
}
5479

5580
def test_find_docs_no_output_files(self):
5681
# Read the file, but this time wipe out the list of target output

tests/test_py_docstring.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -58,4 +58,4 @@ def test_real_input_file(self):
5858

5959
# Just ensure that the bytestream is the appropriate length.
6060
# This is a terrible test. :-/
61-
assert len(output_file.getvalue()) == 25043
61+
assert len(output_file.getvalue()) == 25294

0 commit comments

Comments
 (0)