grpc-rest 0.1.4 → 0.1.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3ed7db60b29738e635e7b776539fc8207a5ec264e43912cb83562b1a44efdc58
|
4
|
+
data.tar.gz: a1653a18dab17be5abad7968ae405254ccc23973f799f9c7def7cd318b485681
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 04b70b84065aa66b4441a4987519a351e0cafca0b58d5392a4e3a5a3b64429ca6bc4d6be877dfcf28f3c34fd77b04f7592500d89989737eab513b7c40591580f
|
7
|
+
data.tar.gz: fd35771ff21bbd7dc98550633a0eb96cb44b518f3356f792ce92dc02e9655f2683d0eab08bc1d36a1f8abf36f23fbabdd68e8bdb7f0dd4423ad311a27e7f80e6
|
data/CHANGELOG
CHANGED
@@ -7,6 +7,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
7
7
|
|
8
8
|
## UNRELEASED
|
9
9
|
|
10
|
+
# 0.1.5 - 2024-04-04
|
11
|
+
- Parse Google Well Known Types (WKT) in request.
|
12
|
+
|
10
13
|
# 0.1.4 - 2024-04-04
|
11
14
|
- Remove geo-admin hardcoded requirement.
|
12
15
|
- Use baked-in Protobuf initialization to support nested objects properly.
|
data/lib/grpc_rest/version.rb
CHANGED
data/lib/grpc_rest.rb
CHANGED
@@ -33,6 +33,29 @@ module GrpcRest
|
|
33
33
|
proto.public_send(:"#{tokens.last}=", value) if proto.respond_to?(:"#{tokens.last}=")
|
34
34
|
end
|
35
35
|
|
36
|
+
def map_wkt(proto, params)
|
37
|
+
proto.to_a.each do |descriptor|
|
38
|
+
field = descriptor.name
|
39
|
+
case descriptor.subtype&.name
|
40
|
+
when 'google.protobuf.Struct'
|
41
|
+
params[field] = Google::Protobuf::Struct.from_hash(params[field])
|
42
|
+
when 'google.protobuf.Timestamp'
|
43
|
+
params[field] = Google::Protobuf::Timestamp.from_time(Time.new(params[field]))
|
44
|
+
when 'google.protobuf.Value'
|
45
|
+
params[field] = Google::Protobuf::Value.from_ruby(params[field])
|
46
|
+
when 'google.protobuf.ListValue'
|
47
|
+
params[field] = Google::Protobuf::ListValue.from_a(params[field])
|
48
|
+
else
|
49
|
+
map_wkt(descriptor.subtype, params[field]) if descriptor.subtype
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
def init_request(request_class, params)
|
55
|
+
map_wkt(request_class.descriptor, params)
|
56
|
+
request_class.new(params)
|
57
|
+
end
|
58
|
+
|
36
59
|
def assign_params(request, param_hash, body_string, params)
|
37
60
|
parameters = params.to_h.deep_dup
|
38
61
|
# each instance of {variable} means that we set the corresponding param variable into the
|
@@ -59,7 +59,7 @@ class {{.ControllerName}}Controller < ActionController::Base
|
|
59
59
|
{{range .Methods }}
|
60
60
|
def {{.Name}}
|
61
61
|
fields = {{.RequestType}}.descriptor.to_a.map(&:name)
|
62
|
-
grpc_request = {{.RequestType}}
|
62
|
+
grpc_request = GrpcRest.init_request({{.RequestType}}, request.parameters.to_h.slice(*fields))
|
63
63
|
GrpcRest.assign_params(grpc_request, METHOD_PARAM_MAP["{{.Name}}"], "{{.Body}}", request.parameters)
|
64
64
|
render json: GrpcRest.send_request("{{$fullServiceName}}", "{{.Name}}", grpc_request)
|
65
65
|
end
|
@@ -23,21 +23,21 @@ class MyServiceController < ActionController::Base
|
|
23
23
|
|
24
24
|
def test
|
25
25
|
fields = Testdata::TestRequest.descriptor.to_a.map(&:name)
|
26
|
-
grpc_request = Testdata::TestRequest
|
26
|
+
grpc_request = GrpcRest.init_request(Testdata::TestRequest, request.parameters.to_h.slice(*fields))
|
27
27
|
GrpcRest.assign_params(grpc_request, METHOD_PARAM_MAP["test"], "*", request.parameters)
|
28
28
|
render json: GrpcRest.send_request("Testdata::MyService", "test", grpc_request)
|
29
29
|
end
|
30
30
|
|
31
31
|
def test_2
|
32
32
|
fields = Testdata::TestRequest.descriptor.to_a.map(&:name)
|
33
|
-
grpc_request = Testdata::TestRequest
|
33
|
+
grpc_request = GrpcRest.init_request(Testdata::TestRequest, request.parameters.to_h.slice(*fields))
|
34
34
|
GrpcRest.assign_params(grpc_request, METHOD_PARAM_MAP["test_2"], "second_record", request.parameters)
|
35
35
|
render json: GrpcRest.send_request("Testdata::MyService", "test_2", grpc_request)
|
36
36
|
end
|
37
37
|
|
38
38
|
def test_3
|
39
39
|
fields = Testdata::TestRequest.descriptor.to_a.map(&:name)
|
40
|
-
grpc_request = Testdata::TestRequest
|
40
|
+
grpc_request = GrpcRest.init_request(Testdata::TestRequest, request.parameters.to_h.slice(*fields))
|
41
41
|
GrpcRest.assign_params(grpc_request, METHOD_PARAM_MAP["test_3"], "", request.parameters)
|
42
42
|
render json: GrpcRest.send_request("Testdata::MyService", "test_3", grpc_request)
|
43
43
|
end
|