Fix documentation (#630)
* Fix missing documentation * Add test * Add test * Format * Reformat
This commit is contained in:
parent
34b8249b91
commit
c621ef8a8d
@ -661,6 +661,7 @@ class EnumDefinitionCompiler(MessageCompiler):
|
||||
|
||||
@dataclass
|
||||
class ServiceCompiler(ProtoContentBase):
|
||||
source_file: FileDescriptorProto
|
||||
parent: OutputTemplate = PLACEHOLDER
|
||||
proto_obj: DescriptorProto = PLACEHOLDER
|
||||
path: List[int] = PLACEHOLDER
|
||||
@ -682,6 +683,7 @@ class ServiceCompiler(ProtoContentBase):
|
||||
|
||||
@dataclass
|
||||
class ServiceMethodCompiler(ProtoContentBase):
|
||||
source_file: FileDescriptorProto
|
||||
parent: ServiceCompiler
|
||||
proto_obj: MethodDescriptorProto
|
||||
path: List[int] = PLACEHOLDER
|
||||
|
@ -143,7 +143,7 @@ def generate_code(request: CodeGeneratorRequest) -> CodeGeneratorResponse:
|
||||
for output_package_name, output_package in request_data.output_packages.items():
|
||||
for proto_input_file in output_package.input_files:
|
||||
for index, service in enumerate(proto_input_file.service):
|
||||
read_protobuf_service(service, index, output_package)
|
||||
read_protobuf_service(proto_input_file, service, index, output_package)
|
||||
|
||||
# Generate output files
|
||||
output_paths: Set[pathlib.Path] = set()
|
||||
@ -249,12 +249,21 @@ def read_protobuf_type(
|
||||
|
||||
|
||||
def read_protobuf_service(
|
||||
service: ServiceDescriptorProto, index: int, output_package: OutputTemplate
|
||||
source_file: FileDescriptorProto,
|
||||
service: ServiceDescriptorProto,
|
||||
index: int,
|
||||
output_package: OutputTemplate,
|
||||
) -> None:
|
||||
service_data = ServiceCompiler(
|
||||
parent=output_package, proto_obj=service, path=[6, index]
|
||||
source_file=source_file,
|
||||
parent=output_package,
|
||||
proto_obj=service,
|
||||
path=[6, index],
|
||||
)
|
||||
for j, method in enumerate(service.method):
|
||||
ServiceMethodCompiler(
|
||||
parent=service_data, proto_obj=method, path=[6, index, 2, j]
|
||||
source_file=source_file,
|
||||
parent=service_data,
|
||||
proto_obj=method,
|
||||
path=[6, index, 2, j],
|
||||
)
|
||||
|
20
tests/inputs/documentation/documentation.proto
Normal file
20
tests/inputs/documentation/documentation.proto
Normal file
@ -0,0 +1,20 @@
|
||||
syntax = "proto3";
|
||||
package documentation;
|
||||
|
||||
// Documentation of message
|
||||
message Test {
|
||||
// Documentation of field
|
||||
uint32 x = 1;
|
||||
}
|
||||
|
||||
// Documentation of enum
|
||||
enum Enum {
|
||||
// Documentation of variant
|
||||
Enum_Variant = 0;
|
||||
}
|
||||
|
||||
// Documentation of service
|
||||
service Service {
|
||||
// Documentation of method
|
||||
rpc get(Test) returns (Test);
|
||||
}
|
29
tests/test_documentation.py
Normal file
29
tests/test_documentation.py
Normal file
@ -0,0 +1,29 @@
|
||||
import ast
|
||||
import inspect
|
||||
|
||||
|
||||
def test_documentation():
|
||||
from .output_betterproto.documentation import (
|
||||
Enum,
|
||||
ServiceBase,
|
||||
ServiceStub,
|
||||
Test,
|
||||
)
|
||||
|
||||
assert Test.__doc__ == "Documentation of message"
|
||||
|
||||
source = inspect.getsource(Test)
|
||||
tree = ast.parse(source)
|
||||
assert tree.body[0].body[2].value.value == "Documentation of field"
|
||||
|
||||
assert Enum.__doc__ == "Documentation of enum"
|
||||
|
||||
source = inspect.getsource(Enum)
|
||||
tree = ast.parse(source)
|
||||
assert tree.body[0].body[2].value.value == "Documentation of variant"
|
||||
|
||||
assert ServiceBase.__doc__ == "Documentation of service"
|
||||
assert ServiceBase.get.__doc__ == "Documentation of method"
|
||||
|
||||
assert ServiceStub.__doc__ == "Documentation of service"
|
||||
assert ServiceStub.get.__doc__ == "Documentation of method"
|
Loading…
x
Reference in New Issue
Block a user