grpc-rest 0.1.1 → 0.1.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/CI.yml +1 -1
- data/CHANGELOG +4 -0
- data/lib/grpc_rest/version.rb +1 -1
- data/lib/grpc_rest.rb +0 -5
- data/protoc-gen-rails/internal/output.go +3 -5
- data/protoc-gen-rails/main_test.go +1 -1
- data/protoc-gen-rails/testdata/base/app/controllers/my_service_controller.rb +24 -8
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b9c3044d8f6813a33030d336a91e4d86b4305a781d178d85a07e5e287ab22264
|
4
|
+
data.tar.gz: 659013b9ab51cd05f4e1b9570eeb71fb48f07992bd0f1eba80eb37aca1093921
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 04ed1b2acf85c8ec4c069195dd1cd8711e7b68209dcf24cf62a60e832c89158364946d4da72012cc2b7bc037b6f2ac06df36a33a5a43b956e12e7dfe1b9d393b
|
7
|
+
data.tar.gz: 64f846bc132c121521c4ba1c8c1189bfed3ebfc4c1ee78473fac297aba84b1254037922a08859f165569a366c23df2b6da0ea391e08ef1e50c4430db713b9f86
|
data/.github/workflows/CI.yml
CHANGED
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.4 - 2024-04-04
|
11
|
+
- Remove geo-admin hardcoded requirement.
|
12
|
+
- Use baked-in Protobuf initialization to support nested objects properly.
|
13
|
+
|
10
14
|
# 0.1.0 - 2024-03-01
|
11
15
|
|
12
16
|
* Initial release.
|
data/lib/grpc_rest/version.rb
CHANGED
data/lib/grpc_rest.rb
CHANGED
@@ -16,7 +16,6 @@ type FileResult struct {
|
|
16
16
|
|
17
17
|
type controller struct {
|
18
18
|
ControllerName string
|
19
|
-
ServiceFilePath string
|
20
19
|
Methods []method
|
21
20
|
ServiceName string
|
22
21
|
FullServiceName string
|
@@ -41,7 +40,6 @@ type Route struct {
|
|
41
40
|
|
42
41
|
var controllerTemplate = `
|
43
42
|
require 'grpc_rest'
|
44
|
-
require 'services/geo_admin/v1/test_services_pb'
|
45
43
|
class {{.ControllerName}}Controller < ActionController::Base
|
46
44
|
protect_from_forgery with: :null_session
|
47
45
|
|
@@ -60,8 +58,9 @@ class {{.ControllerName}}Controller < ActionController::Base
|
|
60
58
|
{{$fullServiceName := .FullServiceName -}}
|
61
59
|
{{range .Methods }}
|
62
60
|
def {{.Name}}
|
63
|
-
|
64
|
-
|
61
|
+
fields = {{.RequestType}}.descriptor.to_a.map(&:name)
|
62
|
+
grpc_request = {{.RequestType}}.new(request.parameters.to_h.slice(*fields))
|
63
|
+
GrpcRest.assign_params(grpc_request, METHOD_PARAM_MAP["{{.Name}}"], "{{.Body}}", request.parameters)
|
65
64
|
render json: GrpcRest.send_request("{{$fullServiceName}}", "{{.Name}}", grpc_request)
|
66
65
|
end
|
67
66
|
{{end}}
|
@@ -74,7 +73,6 @@ func ProcessService(service *descriptorpb.ServiceDescriptorProto, pkg string) (F
|
|
74
73
|
Methods: []method{},
|
75
74
|
ServiceName: Classify(service.GetName()),
|
76
75
|
ControllerName: Demodulize(service.GetName()),
|
77
|
-
ServiceFilePath: FilePathify(pkg + "." + service.GetName()),
|
78
76
|
FullServiceName: Classify(pkg + "." + service.GetName()),
|
79
77
|
}
|
80
78
|
for _, m := range service.GetMethod() {
|
@@ -78,7 +78,7 @@ func runTest(t *testing.T, directory string, options map[string]string) {
|
|
78
78
|
|
79
79
|
testDir := workdir + "/testdata/" + directory
|
80
80
|
if os.Getenv("UPDATE_SNAPSHOTS") != "" {
|
81
|
-
cmd := exec.Command("/bin/sh", "-c", fmt.Sprintf("cp %v/* %v", tmpdir, testDir))
|
81
|
+
cmd := exec.Command("/bin/sh", "-c", fmt.Sprintf("cp -R %v/* %v", tmpdir, testDir))
|
82
82
|
cmd.Run()
|
83
83
|
} else {
|
84
84
|
assertEqualFiles(t, testDir, tmpdir)
|
@@ -1,28 +1,44 @@
|
|
1
1
|
|
2
2
|
require 'grpc_rest'
|
3
|
-
require 'services/geo_admin/v1/test_services_pb'
|
4
3
|
class MyServiceController < ActionController::Base
|
5
4
|
protect_from_forgery with: :null_session
|
6
5
|
|
7
|
-
rescue_from
|
6
|
+
rescue_from StandardError do |e|
|
8
7
|
render json: GrpcRest.error_msg(e)
|
9
8
|
end
|
9
|
+
METHOD_PARAM_MAP = {
|
10
|
+
|
11
|
+
"test" => [
|
12
|
+
{name: "blah", val: "foobar/*", split_name:["blah"]},
|
13
|
+
{name: "repeated_string", val: nil, split_name:["repeated_string"]},
|
14
|
+
],
|
15
|
+
|
16
|
+
"test_2" => [
|
17
|
+
],
|
18
|
+
|
19
|
+
"test_3" => [
|
20
|
+
{name: "sub_record.sub_id", val: nil, split_name:["sub_record","sub_id"]},
|
21
|
+
],
|
22
|
+
}.freeze
|
10
23
|
|
11
24
|
def test
|
12
|
-
|
13
|
-
|
25
|
+
fields = Testdata::TestRequest.descriptor.to_a.map(&:name)
|
26
|
+
grpc_request = Testdata::TestRequest.new(request.parameters.to_h.slice(*fields))
|
27
|
+
GrpcRest.assign_params(grpc_request, METHOD_PARAM_MAP["test"], "*", request.parameters)
|
14
28
|
render json: GrpcRest.send_request("Testdata::MyService", "test", grpc_request)
|
15
29
|
end
|
16
30
|
|
17
31
|
def test_2
|
18
|
-
|
19
|
-
|
32
|
+
fields = Testdata::TestRequest.descriptor.to_a.map(&:name)
|
33
|
+
grpc_request = Testdata::TestRequest.new(request.parameters.to_h.slice(*fields))
|
34
|
+
GrpcRest.assign_params(grpc_request, METHOD_PARAM_MAP["test_2"], "second_record", request.parameters)
|
20
35
|
render json: GrpcRest.send_request("Testdata::MyService", "test_2", grpc_request)
|
21
36
|
end
|
22
37
|
|
23
38
|
def test_3
|
24
|
-
|
25
|
-
|
39
|
+
fields = Testdata::TestRequest.descriptor.to_a.map(&:name)
|
40
|
+
grpc_request = Testdata::TestRequest.new(request.parameters.to_h.slice(*fields))
|
41
|
+
GrpcRest.assign_params(grpc_request, METHOD_PARAM_MAP["test_3"], "", request.parameters)
|
26
42
|
render json: GrpcRest.send_request("Testdata::MyService", "test_3", grpc_request)
|
27
43
|
end
|
28
44
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: grpc-rest
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Daniel Orner
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-
|
11
|
+
date: 2024-04-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: grpc
|