@@ -114,11 +114,11 @@ def get_comment(proto_file, path: List[int]) -> str:
114
114
sci .leading_comments .strip ().replace ("\n " , "" ), width = 75
115
115
)
116
116
117
- if path [- 2 ] == 2 :
117
+ if path [- 2 ] == 2 and path [ - 4 ] != 6 :
118
118
# This is a field
119
119
return " # " + " # " .join (lines )
120
120
else :
121
- # This is a class
121
+ # This is a message, enum, service, or method
122
122
if len (lines ) == 1 and len (lines [0 ]) < 70 :
123
123
lines [0 ] = lines [0 ].strip ('"' )
124
124
return f' """{ lines [0 ]} """'
@@ -278,13 +278,16 @@ def generate_code(request, response):
278
278
279
279
output ["enums" ].append (data )
280
280
281
- for service in proto_file .service :
281
+ for i , service in enumerate ( proto_file .service ) :
282
282
# print(service, file=sys.stderr)
283
283
284
- # TODO: comments
285
- data = {"name" : service .name , "methods" : []}
284
+ data = {
285
+ "name" : service .name ,
286
+ "comment" : get_comment (proto_file , [6 , i ]),
287
+ "methods" : [],
288
+ }
286
289
287
- for method in service .method :
290
+ for j , method in enumerate ( service .method ) :
288
291
if method .client_streaming :
289
292
raise NotImplementedError ("Client streaming not yet supported" )
290
293
@@ -304,6 +307,7 @@ def generate_code(request, response):
304
307
{
305
308
"name" : method .name ,
306
309
"py_name" : snake_case (method .name ),
310
+ "comment" : get_comment (proto_file , [6 , i , 2 , j ]),
307
311
"route" : f"/{ package } .{ service .name } /{ method .name } " ,
308
312
"input" : get_ref_type (
309
313
package , output ["imports" ], method .input_type
0 commit comments