grpc-rest 0.1.18 → 0.1.19

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8c776db1bb156562864c41be6a4af47debe30d420329359847e71db6b5913711
4
- data.tar.gz: 7c4745a5d2dd7e560d0e18b022972473a4487bedf9b9efc4ba387d5cbe42bfc0
3
+ metadata.gz: 3c9a0fd0dc8a21c8ff8e5103a6bdffe98cc51cb522fb8dac59a65b2e9ceacc7c
4
+ data.tar.gz: a42ae7274e7a9db0161e3a40374d050a334312c742d8737652ab8fd8aaa55ec4
5
5
  SHA512:
6
- metadata.gz: 4e7f53b6c264c80f768dd91c0c25da350651cd386d7a51b88f7eedf814d2f0eced41a261ee9e3800ba867fdb69bc4a87ac22700c6b33ae3d50d576555b66875e
7
- data.tar.gz: 456d38962848fc73f1c40f0a59336de1d17017e2e138511f046836674a947a11390b20b7180a4b7d4d5befa6f132a23793d5cc7518263a93c1ed0be8255fa246
6
+ metadata.gz: 624a27f0b5345256376d3a3cbd418543339d9f604ef42866da442a4589fd0732702b61e02f37d14e31b1cb53f5d707d73a8924af45df9be65995942316b75d86
7
+ data.tar.gz: d548c211f158b8095ec655691e11c1cb815382ecdfce8a42ed014fdcf82d5286e333d2894a8c5bdb3564b861beba29387b2936a39c6d28108e7d3d472da6ff45
data/CHANGELOG CHANGED
@@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## UNRELEASED
9
9
 
10
+ # 0.1.19 - 2024-08-22
11
+
12
+ - Add `emit_defaults` extension for JSON responses.
13
+
10
14
  # 0.1.18 - 2024-08-15
11
15
  - Automatically add prefixes to enum values if not provided
12
16
 
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- grpc-rest (0.1.17)
4
+ grpc-rest (0.1.19)
5
5
  grpc
6
6
  rails (>= 6.0)
7
7
 
data/README.md CHANGED
@@ -130,9 +130,32 @@ end
130
130
 
131
131
  This gem does not currently support the full path expression capabilities of grpc-gateway or the Google [http proto](https://github.com/googleapis/googleapis/blob/master/google/api/http.proto). It only supports very basic single wildcard globbing (`*`). Contributions are welcome for more complex cases if they are needed.
132
132
 
133
+ ## Proto Options
134
+
135
+ By default, grpc-rest uses the Protobuf default of omitting empty values on response. You can change this behavior by using an OpenAPI extension with the key `x-grpc-rest-emit-defaults`:
136
+
137
+ ```protobuf
138
+ service MyService {
139
+ rpc Test(MyRequest) returns (MyResponse) {
140
+ option (google.api.http) = {
141
+ get: "/test/"
142
+ };
143
+ option (grpc.gateway.protoc_gen_openapiv2.options.openapiv2_operation) = {
144
+ extensions: {
145
+ key: 'x-grpc-rest-emit-defaults';
146
+ value: {
147
+ bool_value: true;
148
+ }
149
+ }
150
+ };
151
+ }
152
+ }
153
+ ```
154
+
155
+
133
156
  ## To Do
134
157
 
135
- * Replace Go implementation with Ruby (+ executable) once [service and method lookup](https://github.com/protocolbuffers/protobuf/pull/15817) is released.
158
+ * Replace Go implementation with Ruby (+ executable)
136
159
 
137
160
  ## Contributing
138
161
 
@@ -1,3 +1,3 @@
1
1
  module GrpcRest
2
- VERSION = '0.1.18'
2
+ VERSION = '0.1.19'
3
3
  end
data/lib/grpc_rest.rb CHANGED
@@ -212,7 +212,7 @@ module GrpcRest
212
212
  klass.new.public_send(method, request)
213
213
  end
214
214
 
215
- def send_request(service, method, request)
215
+ def get_response(service, method, request)
216
216
  if defined?(Gruf)
217
217
  service_obj = service.constantize::Service
218
218
  klass = ::Gruf::Controllers::Base.subclasses.find do |k|
@@ -224,6 +224,15 @@ module GrpcRest
224
224
  end
225
225
  send_grpc_request(service, method, request)
226
226
  end
227
+
228
+ def send_request(service, method, request, options={})
229
+ response = get_response(service, method, request)
230
+ if options[:emit_defaults]
231
+ response.to_json(emit_defaults: true)
232
+ else
233
+ response
234
+ end
235
+ end
227
236
  end
228
237
 
229
238
  end
@@ -5,17 +5,21 @@ go 1.22.0
5
5
  require (
6
6
  github.com/iancoleman/strcase v0.3.0
7
7
  github.com/stretchr/testify v1.8.4
8
- google.golang.org/genproto/googleapis/api v0.0.0-20240228224816-df926f6c8641
9
- google.golang.org/protobuf v1.32.0
8
+ google.golang.org/genproto/googleapis/api v0.0.0-20240820151423-278611b39280
9
+ google.golang.org/protobuf v1.34.2
10
10
  )
11
11
 
12
12
  require (
13
13
  github.com/davecgh/go-spew v1.1.1 // indirect
14
14
  github.com/google/go-cmp v0.6.0 // indirect
15
+ github.com/grpc-ecosystem/grpc-gateway/v2 v2.22.0 // indirect
15
16
  github.com/kr/pretty v0.3.1 // indirect
16
17
  github.com/pmezard/go-difflib v1.0.0 // indirect
17
18
  github.com/rogpeppe/go-internal v1.12.0 // indirect
19
+ golang.org/x/text v0.17.0 // indirect
18
20
  google.golang.org/genproto v0.0.0-20240116215550-a9fa1716bcac // indirect
21
+ google.golang.org/genproto/googleapis/rpc v0.0.0-20240820151423-278611b39280 // indirect
22
+ google.golang.org/grpc v1.65.0 // indirect
19
23
  gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect
20
24
  gopkg.in/yaml.v3 v3.0.1 // indirect
21
25
  )
@@ -3,6 +3,8 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c
3
3
  github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
4
4
  github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
5
5
  github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
6
+ github.com/grpc-ecosystem/grpc-gateway/v2 v2.22.0 h1:asbCHRVmodnJTuQ3qamDwqVOIjwqUPTYmYuemVOx+Ys=
7
+ github.com/grpc-ecosystem/grpc-gateway/v2 v2.22.0/go.mod h1:ggCgvZ2r7uOoQjOyu2Y1NhHmEPPzzuhWgcza5M1Ji1I=
6
8
  github.com/iancoleman/strcase v0.3.0 h1:nTXanmYxhfFAMjZL34Ov6gkzEsSJZ5DbhxWjvSASxEI=
7
9
  github.com/iancoleman/strcase v0.3.0/go.mod h1:iwCmte+B7n89clKwxIoIXy/HfoL7AsD47ZCWhYzw7ho=
8
10
  github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI=
@@ -20,14 +22,26 @@ github.com/rogpeppe/go-internal v1.12.0 h1:exVL4IDcn6na9z1rAb56Vxr+CgyK3nn3O+epU
20
22
  github.com/rogpeppe/go-internal v1.12.0/go.mod h1:E+RYuTGaKKdloAfM02xzb0FW3Paa99yedzYV+kq4uf4=
21
23
  github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
22
24
  github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
25
+ golang.org/x/text v0.17.0 h1:XtiM5bkSOt+ewxlOE/aE/AKEHibwj/6gvWMl9Rsh0Qc=
26
+ golang.org/x/text v0.17.0/go.mod h1:BuEKDfySbSR4drPmRPG/7iBdf8hvFMuRexcpahXilzY=
23
27
  google.golang.org/genproto v0.0.0-20240116215550-a9fa1716bcac h1:ZL/Teoy/ZGnzyrqK/Optxxp2pmVh+fmJ97slxSRyzUg=
24
28
  google.golang.org/genproto v0.0.0-20240116215550-a9fa1716bcac/go.mod h1:+Rvu7ElI+aLzyDQhpHMFMMltsD6m7nqpuWDd2CwJw3k=
25
29
  google.golang.org/genproto/googleapis/api v0.0.0-20240125205218-1f4bbc51befe h1:0poefMBYvYbs7g5UkjS6HcxBPaTRAmznle9jnxYoAI8=
26
30
  google.golang.org/genproto/googleapis/api v0.0.0-20240125205218-1f4bbc51befe/go.mod h1:4jWUdICTdgc3Ibxmr8nAJiiLHwQBY0UI0XZcEMaFKaA=
27
31
  google.golang.org/genproto/googleapis/api v0.0.0-20240228224816-df926f6c8641 h1:SO1wX9btGFrwj9EzH3ocqfwiPVOxfv4ggAJajzlHA5s=
28
32
  google.golang.org/genproto/googleapis/api v0.0.0-20240228224816-df926f6c8641/go.mod h1:wLupoVsUfYPgOMwjzhYFbaVklw/INms+dqTp0tc1fv8=
33
+ google.golang.org/genproto/googleapis/api v0.0.0-20240814211410-ddb44dafa142 h1:wKguEg1hsxI2/L3hUYrpo1RVi48K+uTyzKqprwLXsb8=
34
+ google.golang.org/genproto/googleapis/api v0.0.0-20240814211410-ddb44dafa142/go.mod h1:d6be+8HhtEtucleCbxpPW9PA9XwISACu8nvpPqF0BVo=
35
+ google.golang.org/genproto/googleapis/api v0.0.0-20240820151423-278611b39280 h1:YDFM9oOjiFhaMAVgbDxfxW+66nRrsvzQzJ51wp3OxC0=
36
+ google.golang.org/genproto/googleapis/api v0.0.0-20240820151423-278611b39280/go.mod h1:fO8wJzT2zbQbAjbIoos1285VfEIYKDDY+Dt+WpTkh6g=
37
+ google.golang.org/genproto/googleapis/rpc v0.0.0-20240820151423-278611b39280 h1:XQMA2e105XNlEZ8NRF0HqnUOZzP14sUSsgL09kpdNnU=
38
+ google.golang.org/genproto/googleapis/rpc v0.0.0-20240820151423-278611b39280/go.mod h1:UqMtugtsSgubUsoxbuAoiCXvqvErP7Gf0so0mK9tHxU=
39
+ google.golang.org/grpc v1.65.0 h1:bs/cUb4lp1G5iImFFd3u5ixQzweKizoZJAwBNLR42lc=
40
+ google.golang.org/grpc v1.65.0/go.mod h1:WgYC2ypjlB0EiQi6wdKixMqukr6lBc0Vo+oOgjrM5ZQ=
29
41
  google.golang.org/protobuf v1.32.0 h1:pPC6BG5ex8PDFnkbrGU3EixyhKcQ2aDuBS36lqK/C7I=
30
42
  google.golang.org/protobuf v1.32.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos=
43
+ google.golang.org/protobuf v1.34.2 h1:6xV6lTsCfpGD21XK49h7MhtcApnLqkfYgPcdHftf6hg=
44
+ google.golang.org/protobuf v1.34.2/go.mod h1:qYOHts0dSfpeUzUFpOMr/WGzszTmLH+DiWniOlNbLDw=
31
45
  gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
32
46
  gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
33
47
  gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
@@ -0,0 +1,44 @@
1
+ syntax = "proto3";
2
+
3
+ package grpc.gateway.protoc_gen_openapiv2.options;
4
+
5
+ import "google/protobuf/descriptor.proto";
6
+ import "protoc-gen-openapiv2/options/openapiv2.proto";
7
+
8
+ option go_package = "github.com/grpc-ecosystem/grpc-gateway/v2/protoc-gen-openapiv2/options";
9
+
10
+ extend google.protobuf.FileOptions {
11
+ // ID assigned by protobuf-global-extension-registry@google.com for gRPC-Gateway project.
12
+ //
13
+ // All IDs are the same, as assigned. It is okay that they are the same, as they extend
14
+ // different descriptor messages.
15
+ Swagger openapiv2_swagger = 1042;
16
+ }
17
+ extend google.protobuf.MethodOptions {
18
+ // ID assigned by protobuf-global-extension-registry@google.com for gRPC-Gateway project.
19
+ //
20
+ // All IDs are the same, as assigned. It is okay that they are the same, as they extend
21
+ // different descriptor messages.
22
+ Operation openapiv2_operation = 1042;
23
+ }
24
+ extend google.protobuf.MessageOptions {
25
+ // ID assigned by protobuf-global-extension-registry@google.com for gRPC-Gateway project.
26
+ //
27
+ // All IDs are the same, as assigned. It is okay that they are the same, as they extend
28
+ // different descriptor messages.
29
+ Schema openapiv2_schema = 1042;
30
+ }
31
+ extend google.protobuf.ServiceOptions {
32
+ // ID assigned by protobuf-global-extension-registry@google.com for gRPC-Gateway project.
33
+ //
34
+ // All IDs are the same, as assigned. It is okay that they are the same, as they extend
35
+ // different descriptor messages.
36
+ Tag openapiv2_tag = 1042;
37
+ }
38
+ extend google.protobuf.FieldOptions {
39
+ // ID assigned by protobuf-global-extension-registry@google.com for gRPC-Gateway project.
40
+ //
41
+ // All IDs are the same, as assigned. It is okay that they are the same, as they extend
42
+ // different descriptor messages.
43
+ JSONSchema openapiv2_field = 1042;
44
+ }