gRPC service/method comments
This commit is contained in:
parent
45a6da0fad
commit
a33d92d89d
@ -114,11 +114,11 @@ def get_comment(proto_file, path: List[int]) -> str:
|
|||||||
sci.leading_comments.strip().replace("\n", ""), width=75
|
sci.leading_comments.strip().replace("\n", ""), width=75
|
||||||
)
|
)
|
||||||
|
|
||||||
if path[-2] == 2:
|
if path[-2] == 2 and path[-4] != 6:
|
||||||
# This is a field
|
# This is a field
|
||||||
return " # " + " # ".join(lines)
|
return " # " + " # ".join(lines)
|
||||||
else:
|
else:
|
||||||
# This is a class
|
# This is a message, enum, service, or method
|
||||||
if len(lines) == 1 and len(lines[0]) < 70:
|
if len(lines) == 1 and len(lines[0]) < 70:
|
||||||
lines[0] = lines[0].strip('"')
|
lines[0] = lines[0].strip('"')
|
||||||
return f' """{lines[0]}"""'
|
return f' """{lines[0]}"""'
|
||||||
@ -278,13 +278,16 @@ def generate_code(request, response):
|
|||||||
|
|
||||||
output["enums"].append(data)
|
output["enums"].append(data)
|
||||||
|
|
||||||
for service in proto_file.service:
|
for i, service in enumerate(proto_file.service):
|
||||||
# print(service, file=sys.stderr)
|
# print(service, file=sys.stderr)
|
||||||
|
|
||||||
# TODO: comments
|
data = {
|
||||||
data = {"name": service.name, "methods": []}
|
"name": service.name,
|
||||||
|
"comment": get_comment(proto_file, [6, i]),
|
||||||
|
"methods": [],
|
||||||
|
}
|
||||||
|
|
||||||
for method in service.method:
|
for j, method in enumerate(service.method):
|
||||||
if method.client_streaming:
|
if method.client_streaming:
|
||||||
raise NotImplementedError("Client streaming not yet supported")
|
raise NotImplementedError("Client streaming not yet supported")
|
||||||
|
|
||||||
@ -304,6 +307,7 @@ def generate_code(request, response):
|
|||||||
{
|
{
|
||||||
"name": method.name,
|
"name": method.name,
|
||||||
"py_name": snake_case(method.name),
|
"py_name": snake_case(method.name),
|
||||||
|
"comment": get_comment(proto_file, [6, i, 2, j]),
|
||||||
"route": f"/{package}.{service.name}/{method.name}",
|
"route": f"/{package}.{service.name}/{method.name}",
|
||||||
"input": get_ref_type(
|
"input": get_ref_type(
|
||||||
package, output["imports"], method.input_type
|
package, output["imports"], method.input_type
|
||||||
|
@ -54,8 +54,16 @@ class {{ message.name }}(betterproto.Message):
|
|||||||
{% endfor %}
|
{% endfor %}
|
||||||
{% for service in description.services %}
|
{% for service in description.services %}
|
||||||
class {{ service.name }}Stub(betterproto.ServiceStub):
|
class {{ service.name }}Stub(betterproto.ServiceStub):
|
||||||
|
{% if service.comment %}
|
||||||
|
{{ service.comment }}
|
||||||
|
|
||||||
|
{% endif %}
|
||||||
{% for method in service.methods %}
|
{% for method in service.methods %}
|
||||||
async def {{ method.py_name }}(self{% if method.input_message and method.input_message.properties %}, *, {% for field in method.input_message.properties %}{{ field.name }}: {% if field.zero == "None" %}Optional[{{ field.type }}]{% else %}{{ field.type }}{% endif %} = {{ field.zero }}{% if not loop.last %}, {% endif %}{% endfor %}{% endif %}) -> {% if method.server_streaming %}AsyncGenerator[{{ method.output }}, None]{% else %}{{ method.output }}{% endif %}:
|
async def {{ method.py_name }}(self{% if method.input_message and method.input_message.properties %}, *, {% for field in method.input_message.properties %}{{ field.name }}: {% if field.zero == "None" %}Optional[{{ field.type }}]{% else %}{{ field.type }}{% endif %} = {{ field.zero }}{% if not loop.last %}, {% endif %}{% endfor %}{% endif %}) -> {% if method.server_streaming %}AsyncGenerator[{{ method.output }}, None]{% else %}{{ method.output }}{% endif %}:
|
||||||
|
{% if method.comment %}
|
||||||
|
{{ method.comment }}
|
||||||
|
|
||||||
|
{% endif %}
|
||||||
request = {{ method.input }}()
|
request = {{ method.input }}()
|
||||||
{% for field in method.input_message.properties %}
|
{% for field in method.input_message.properties %}
|
||||||
{% if field.field_type == 'message' %}
|
{% if field.field_type == 'message' %}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user