Skip to content

Commit beb8a61

Browse files
committed
Add grpcurl caller, and openapiv2 outputs
1 parent 4b3b606 commit beb8a61

12 files changed

Lines changed: 331 additions & 13 deletions

File tree

protobuf-grpc/Makefile

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ setup:
1919
gen:
2020
@make -s -C ./proto generate
2121

22+
# Wrappers for running clients & servers of each language
2223
server-go:
2324
@go run ./servers/server.go
2425

@@ -30,3 +31,12 @@ client-go:
3031

3132
client-py:
3233
@$(pyvenv) && python3 ./clients/client.py $(name)
34+
35+
# Shows how to use grpcurl as well
36+
client-grpcurl:
37+
@printf 'Echo("Hello, gRPC!"):\n'
38+
@grpcurl -plaintext -protoset=./proto/protoset -d '{"msg": "Hello, gRPC!"}' localhost:8080 echo.v1.EchoService/Echo
39+
@printf 'ListEmployees():\n'
40+
@grpcurl -plaintext -protoset=./proto/protoset localhost:8080 employees.v1.EmployeesService/ListEmployees
41+
@printf 'GetEmployee($(name)):\n'
42+
@grpcurl -plaintext -protoset=./proto/protoset -d '{"short_name": "$(name)"}' localhost:8080 employees.v1.EmployeesService/GetEmployee

protobuf-grpc/pb/echo/v1/echo.pb.go

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
{
2+
"swagger": "2.0",
3+
"info": {
4+
"title": "Proto packages should match the directory structure in your tree. The version\nsuffix is considered best-practice",
5+
"version": "version not set"
6+
},
7+
"tags": [
8+
{
9+
"name": "EchoService"
10+
}
11+
],
12+
"consumes": [
13+
"application/json"
14+
],
15+
"produces": [
16+
"application/json"
17+
],
18+
"paths": {
19+
"/echo.v1.EchoService/Echo": {
20+
"post": {
21+
"summary": "Echo responds to the caller with the same message they sent",
22+
"operationId": "EchoService_Echo",
23+
"responses": {
24+
"200": {
25+
"description": "A successful response.",
26+
"schema": {
27+
"$ref": "#/definitions/v1EchoResponse"
28+
}
29+
},
30+
"default": {
31+
"description": "An unexpected error response.",
32+
"schema": {
33+
"$ref": "#/definitions/rpcStatus"
34+
}
35+
}
36+
},
37+
"parameters": [
38+
{
39+
"name": "body",
40+
"in": "body",
41+
"required": true,
42+
"schema": {
43+
"$ref": "#/definitions/v1EchoRequest"
44+
}
45+
}
46+
],
47+
"tags": [
48+
"EchoService"
49+
]
50+
}
51+
}
52+
},
53+
"definitions": {
54+
"protobufAny": {
55+
"type": "object",
56+
"properties": {
57+
"@type": {
58+
"type": "string"
59+
}
60+
},
61+
"additionalProperties": {}
62+
},
63+
"rpcStatus": {
64+
"type": "object",
65+
"properties": {
66+
"code": {
67+
"type": "integer",
68+
"format": "int32"
69+
},
70+
"message": {
71+
"type": "string"
72+
},
73+
"details": {
74+
"type": "array",
75+
"items": {
76+
"type": "object",
77+
"$ref": "#/definitions/protobufAny"
78+
}
79+
}
80+
}
81+
},
82+
"v1EchoRequest": {
83+
"type": "object",
84+
"properties": {
85+
"msg": {
86+
"type": "string",
87+
"title": "The message to be echo'd back to the caller"
88+
}
89+
},
90+
"title": "The request sent to the Echo Service's Echo method"
91+
},
92+
"v1EchoResponse": {
93+
"type": "object",
94+
"properties": {
95+
"msg": {
96+
"type": "string",
97+
"title": "The message to be echo'd back to the caller"
98+
}
99+
},
100+
"title": "The response from the Echo Service's Echo method"
101+
}
102+
}
103+
}

protobuf-grpc/pb/echo/v1/echo_grpc.pb.go

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

protobuf-grpc/pb/echo/v1/echo_pb2_grpc.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ class EchoServiceServicer(object):
3737
"""
3838

3939
def Echo(self, request, context):
40-
"""Missing associated documentation comment in .proto file."""
40+
"""Echo responds to the caller with the same message they sent
41+
"""
4142
context.set_code(grpc.StatusCode.UNIMPLEMENTED)
4243
context.set_details('Method not implemented!')
4344
raise NotImplementedError('Method not implemented!')

protobuf-grpc/pb/employees/v1/employees.pb.go

Lines changed: 10 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 146 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,146 @@
1+
{
2+
"swagger": "2.0",
3+
"info": {
4+
"title": "employees/v1/employees.proto",
5+
"version": "version not set"
6+
},
7+
"tags": [
8+
{
9+
"name": "EmployeesService"
10+
}
11+
],
12+
"consumes": [
13+
"application/json"
14+
],
15+
"produces": [
16+
"application/json"
17+
],
18+
"paths": {
19+
"/employees/v1/get_employee/{shortName}": {
20+
"get": {
21+
"summary": "GetEmployee takes a short (friendly) name for a single employee, and\nreturns that employee's associated record",
22+
"operationId": "EmployeesService_GetEmployee",
23+
"responses": {
24+
"200": {
25+
"description": "A successful response.",
26+
"schema": {
27+
"$ref": "#/definitions/v1GetEmployeeResponse"
28+
}
29+
},
30+
"default": {
31+
"description": "An unexpected error response.",
32+
"schema": {
33+
"$ref": "#/definitions/rpcStatus"
34+
}
35+
}
36+
},
37+
"parameters": [
38+
{
39+
"name": "shortName",
40+
"in": "path",
41+
"required": true,
42+
"type": "string"
43+
}
44+
],
45+
"tags": [
46+
"EmployeesService"
47+
]
48+
}
49+
},
50+
"/employees/v1/list_employees": {
51+
"get": {
52+
"summary": "ListEmployees returns all possible employees' short names that can be used\nin calls to GetEmployee",
53+
"operationId": "EmployeesService_ListEmployees",
54+
"responses": {
55+
"200": {
56+
"description": "A successful response.",
57+
"schema": {
58+
"$ref": "#/definitions/v1ListEmployeesResponse"
59+
}
60+
},
61+
"default": {
62+
"description": "An unexpected error response.",
63+
"schema": {
64+
"$ref": "#/definitions/rpcStatus"
65+
}
66+
}
67+
},
68+
"tags": [
69+
"EmployeesService"
70+
]
71+
}
72+
}
73+
},
74+
"definitions": {
75+
"protobufAny": {
76+
"type": "object",
77+
"properties": {
78+
"@type": {
79+
"type": "string"
80+
}
81+
},
82+
"additionalProperties": {}
83+
},
84+
"rpcStatus": {
85+
"type": "object",
86+
"properties": {
87+
"code": {
88+
"type": "integer",
89+
"format": "int32"
90+
},
91+
"message": {
92+
"type": "string"
93+
},
94+
"details": {
95+
"type": "array",
96+
"items": {
97+
"type": "object",
98+
"$ref": "#/definitions/protobufAny"
99+
}
100+
}
101+
}
102+
},
103+
"v1Employee": {
104+
"type": "object",
105+
"properties": {
106+
"id": {
107+
"type": "string",
108+
"format": "int64",
109+
"title": "Employee ID number"
110+
},
111+
"fullName": {
112+
"type": "string",
113+
"title": "Employee full name"
114+
},
115+
"birthday": {
116+
"type": "string",
117+
"title": "Employee birthday, in RFC 3339 date format"
118+
}
119+
},
120+
"title": "Defines the record structure for each employee"
121+
},
122+
"v1GetEmployeeResponse": {
123+
"type": "object",
124+
"properties": {
125+
"employee": {
126+
"$ref": "#/definitions/v1Employee",
127+
"title": "Contains Employee record details"
128+
}
129+
},
130+
"title": "Response from the GetEmployee call"
131+
},
132+
"v1ListEmployeesResponse": {
133+
"type": "object",
134+
"properties": {
135+
"shortNames": {
136+
"type": "array",
137+
"items": {
138+
"type": "string"
139+
},
140+
"title": "List of short (friendly) names for Employees"
141+
}
142+
},
143+
"title": "Response from the ListEmployees call"
144+
}
145+
}
146+
}

0 commit comments

Comments
 (0)