Fix issue that occurs with naming when proto is double nested (#21)
This commit is contained in:
		
				
					committed by
					
						 GitHub
						GitHub
					
				
			
			
				
	
			
			
			
						parent
						
							04a2fcd3eb
						
					
				
				
					commit
					36a14026d8
				
			| @@ -122,19 +122,19 @@ def get_py_zero(type_num: int) -> str: | ||||
|  | ||||
|  | ||||
| def traverse(proto_file): | ||||
|     def _traverse(path, items): | ||||
|     def _traverse(path, items, prefix = ''): | ||||
|         for i, item in enumerate(items): | ||||
|             # Adjust the name since we flatten the heirarchy. | ||||
|             item.name = next_prefix = prefix + item.name | ||||
|             yield item, path + [i] | ||||
|  | ||||
|             if isinstance(item, DescriptorProto): | ||||
|                 for enum in item.enum_type: | ||||
|                     enum.name = item.name + enum.name | ||||
|                     enum.name = next_prefix + enum.name | ||||
|                     yield enum, path + [i, 4] | ||||
|  | ||||
|                 if item.nested_type: | ||||
|                     for n, p in _traverse(path + [i, 3], item.nested_type): | ||||
|                         # Adjust the name since we flatten the heirarchy. | ||||
|                         n.name = item.name + n.name | ||||
|                     for n, p in _traverse(path + [i, 3], item.nested_type, next_prefix): | ||||
|                         yield n, p | ||||
|  | ||||
|     return itertools.chain( | ||||
|   | ||||
							
								
								
									
										11
									
								
								betterproto/tests/nestedtwice.json
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										11
									
								
								betterproto/tests/nestedtwice.json
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,11 @@ | ||||
| { | ||||
|   "root": { | ||||
|     "name": "double-nested", | ||||
|     "parent": { | ||||
|       "child": [{"foo": "hello"}], | ||||
|       "enumChild": ["A"], | ||||
|       "rootParentChild": [{"a": "hello"}], | ||||
|       "bar": true | ||||
|     } | ||||
|   } | ||||
| } | ||||
							
								
								
									
										26
									
								
								betterproto/tests/nestedtwice.proto
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										26
									
								
								betterproto/tests/nestedtwice.proto
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,26 @@ | ||||
| syntax = "proto3"; | ||||
|  | ||||
| message Test { | ||||
|   message Root { | ||||
|     message Parent { | ||||
|       message RootParentChild { | ||||
|         string a = 1; | ||||
|       } | ||||
|       enum EnumChild{ | ||||
|         A = 0; | ||||
|         B = 1; | ||||
|       } | ||||
|       message Child { | ||||
|         string foo = 1; | ||||
|       } | ||||
|       reserved 1; | ||||
|       repeated Child child = 2; | ||||
|       repeated EnumChild enumChild=3; | ||||
|       repeated RootParentChild rootParentChild=4; | ||||
|       bool bar = 5; | ||||
|     } | ||||
|     string name = 1; | ||||
|     Parent parent = 2; | ||||
|   } | ||||
|   Root root = 1; | ||||
| } | ||||
		Reference in New Issue
	
	Block a user