-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsample.py
32 lines (21 loc) · 895 Bytes
/
sample.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
from py2proto import ProtoGenerator, relation
class MessageProto(ProtoGenerator):
class MessageRequest(ProtoGenerator):
message: str
number: int
class MessageResponse(ProtoGenerator):
message: str
service = relation("SendMessage", "MessageRequest", "MessageResponse")
if __name__ == "__main__":
# Set output directory
MessageProto.set_output_directory("outputs")
# Generate proto file
proto_file = MessageProto.generate_proto("messageservice", "message_service")
# Generate pb2 files
MessageProto.generate_pb2(proto_file)
# Generate Swagger file
swagger_file = MessageProto.generate_swagger(proto_file)
# Generate gRPC files for Python and JavaScript
MessageProto.generate_grpc_files(['python', 'javascript'], proto_file, port=50051)
# Run Swagger UI
MessageProto.run_flask()