grpc-rest 0.1.15 → 0.1.17
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG +6 -0
- data/Gemfile.lock +1 -1
- data/lib/grpc_rest/version.rb +1 -1
- data/lib/grpc_rest.rb +1 -1
- data/protoc-gen-rails/internal/output.go +29 -27
- data/protoc-gen-rails/testdata/base/app/controllers/my_service_controller.rb +8 -4
- 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: c9364ed8060e0d6d89f6082f0da592a34adb7977c36b776be56ee8e816bf9575
|
4
|
+
data.tar.gz: 8358915b2c4cea7d0950fb9198395b11d70a94e8800e3e52f9781bfcf18707be
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cfaea51fd7addb1aedc0c3f4c7ea8450af57716c146d46342331d52c4d6df56df835609477692c3c8ec0985f5164f82be7b0261f60a7241b2723b6aa9c62f8ba
|
7
|
+
data.tar.gz: 665cf40abf886db39d3c34d253b1eeb457a3b204d8c254a0737cdb41b8e754a7c1d2f2159bccdf89a8d1efdad075d10b67982bac23d2cbf5c1238510449c1280
|
data/CHANGELOG
CHANGED
@@ -7,6 +7,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
7
7
|
|
8
8
|
## UNRELEASED
|
9
9
|
|
10
|
+
# 0.1.17 - 2024-07-30
|
11
|
+
- Ignore unknown fields in JSON decoding
|
12
|
+
|
13
|
+
# 0.1.16 - 2024-07-09
|
14
|
+
- Support requests in camel case
|
15
|
+
|
10
16
|
# 0.1.15 - 2024-06-26
|
11
17
|
- Actually emit the correct error code on failure. :(
|
12
18
|
|
data/Gemfile.lock
CHANGED
data/lib/grpc_rest/version.rb
CHANGED
data/lib/grpc_rest.rb
CHANGED
@@ -80,7 +80,7 @@ module GrpcRest
|
|
80
80
|
|
81
81
|
def init_request(request_class, params)
|
82
82
|
map_proto_type(request_class.descriptor, params)
|
83
|
-
request_class.decode_json(JSON.generate(params))
|
83
|
+
request_class.decode_json(JSON.generate(params), ignore_unknown_fields: true)
|
84
84
|
end
|
85
85
|
|
86
86
|
def assign_params(request, param_hash, body_string, params)
|
@@ -1,39 +1,40 @@
|
|
1
1
|
package internal
|
2
2
|
|
3
3
|
import (
|
4
|
-
|
5
|
-
|
6
|
-
"github.com/iancoleman/strcase"
|
7
|
-
"google.golang.org/protobuf/types/descriptorpb"
|
4
|
+
"bytes"
|
5
|
+
"fmt"
|
8
6
|
"strings"
|
9
7
|
"text/template"
|
8
|
+
|
9
|
+
"github.com/iancoleman/strcase"
|
10
|
+
"google.golang.org/protobuf/types/descriptorpb"
|
10
11
|
)
|
11
12
|
|
12
13
|
type FileResult struct {
|
13
|
-
Name
|
14
|
+
Name string
|
14
15
|
Content string
|
15
16
|
}
|
16
17
|
|
17
18
|
type controller struct {
|
18
|
-
ControllerName
|
19
|
-
Methods
|
20
|
-
ServiceName
|
19
|
+
ControllerName string
|
20
|
+
Methods []method
|
21
|
+
ServiceName string
|
21
22
|
FullServiceName string
|
22
|
-
MethodName
|
23
|
+
MethodName string
|
23
24
|
}
|
24
25
|
|
25
26
|
type method struct {
|
26
|
-
Name
|
27
|
+
Name string
|
27
28
|
RequestType string
|
28
|
-
Path
|
29
|
-
PathInfo
|
30
|
-
Body
|
31
|
-
HttpMethod
|
29
|
+
Path string
|
30
|
+
PathInfo []PathInfo
|
31
|
+
Body string
|
32
|
+
HttpMethod string
|
32
33
|
}
|
33
34
|
|
34
35
|
type Route struct {
|
35
36
|
MethodName string
|
36
|
-
Path
|
37
|
+
Path string
|
37
38
|
Controller string
|
38
39
|
HttpMethod string
|
39
40
|
}
|
@@ -67,7 +68,8 @@ class {{.ControllerName}}Controller < ActionController::Base
|
|
67
68
|
{{range .Methods }}
|
68
69
|
def {{.Name}}
|
69
70
|
fields = {{.RequestType}}.descriptor.to_a.map(&:name)
|
70
|
-
|
71
|
+
parameters = request.parameters.to_h.deep_transform_keys(&:underscore)
|
72
|
+
grpc_request = GrpcRest.init_request({{.RequestType}}, parameters.slice(*fields))
|
71
73
|
GrpcRest.assign_params(grpc_request, METHOD_PARAM_MAP["{{.Name}}"], "{{.Body}}", request.parameters)
|
72
74
|
render json: GrpcRest.send_request("{{$fullServiceName}}", "{{.Name}}", grpc_request)
|
73
75
|
end
|
@@ -76,11 +78,11 @@ end
|
|
76
78
|
`
|
77
79
|
|
78
80
|
func ProcessService(service *descriptorpb.ServiceDescriptorProto, pkg string) (FileResult, []Route, error) {
|
79
|
-
|
81
|
+
var routes []Route
|
80
82
|
data := controller{
|
81
|
-
Methods:
|
82
|
-
ServiceName:
|
83
|
-
ControllerName:
|
83
|
+
Methods: []method{},
|
84
|
+
ServiceName: Classify(service.GetName()),
|
85
|
+
ControllerName: Demodulize(service.GetName()),
|
84
86
|
FullServiceName: Classify(pkg + "." + service.GetName()),
|
85
87
|
}
|
86
88
|
for _, m := range service.GetMethod() {
|
@@ -94,17 +96,17 @@ func ProcessService(service *descriptorpb.ServiceDescriptorProto, pkg string) (F
|
|
94
96
|
return FileResult{}, routes, err
|
95
97
|
}
|
96
98
|
controllerMethod := method{
|
97
|
-
Name:
|
99
|
+
Name: strcase.ToSnake(m.GetName()),
|
98
100
|
RequestType: Classify(m.GetInputType()),
|
99
|
-
Path:
|
100
|
-
HttpMethod:
|
101
|
-
Body:
|
102
|
-
PathInfo:
|
101
|
+
Path: path,
|
102
|
+
HttpMethod: httpMethod,
|
103
|
+
Body: opts.Body,
|
104
|
+
PathInfo: pathInfo,
|
103
105
|
}
|
104
106
|
data.Methods = append(data.Methods, controllerMethod)
|
105
107
|
routes = append(routes, Route{
|
106
108
|
HttpMethod: strings.ToLower(httpMethod),
|
107
|
-
Path:
|
109
|
+
Path: SanitizePath(path),
|
108
110
|
Controller: strcase.ToSnake(data.ControllerName),
|
109
111
|
MethodName: strcase.ToSnake(m.GetName()),
|
110
112
|
})
|
@@ -120,7 +122,7 @@ func ProcessService(service *descriptorpb.ServiceDescriptorProto, pkg string) (F
|
|
120
122
|
}
|
121
123
|
return FileResult{
|
122
124
|
Content: resultContent.String(),
|
123
|
-
Name:
|
125
|
+
Name: fmt.Sprintf("app/controllers/%s_controller.rb", strcase.ToSnake(data.ControllerName)),
|
124
126
|
}, routes, nil
|
125
127
|
}
|
126
128
|
|
@@ -33,28 +33,32 @@ class MyServiceController < ActionController::Base
|
|
33
33
|
|
34
34
|
def test
|
35
35
|
fields = Testdata::TestRequest.descriptor.to_a.map(&:name)
|
36
|
-
|
36
|
+
parameters = request.parameters.to_h.deep_transform_keys(&:underscore)
|
37
|
+
grpc_request = GrpcRest.init_request(Testdata::TestRequest, parameters.slice(*fields))
|
37
38
|
GrpcRest.assign_params(grpc_request, METHOD_PARAM_MAP["test"], "", request.parameters)
|
38
39
|
render json: GrpcRest.send_request("Testdata::MyService", "test", grpc_request)
|
39
40
|
end
|
40
41
|
|
41
42
|
def test_2
|
42
43
|
fields = Testdata::TestRequest.descriptor.to_a.map(&:name)
|
43
|
-
|
44
|
+
parameters = request.parameters.to_h.deep_transform_keys(&:underscore)
|
45
|
+
grpc_request = GrpcRest.init_request(Testdata::TestRequest, parameters.slice(*fields))
|
44
46
|
GrpcRest.assign_params(grpc_request, METHOD_PARAM_MAP["test_2"], "second_record", request.parameters)
|
45
47
|
render json: GrpcRest.send_request("Testdata::MyService", "test_2", grpc_request)
|
46
48
|
end
|
47
49
|
|
48
50
|
def test_3
|
49
51
|
fields = Testdata::TestRequest.descriptor.to_a.map(&:name)
|
50
|
-
|
52
|
+
parameters = request.parameters.to_h.deep_transform_keys(&:underscore)
|
53
|
+
grpc_request = GrpcRest.init_request(Testdata::TestRequest, parameters.slice(*fields))
|
51
54
|
GrpcRest.assign_params(grpc_request, METHOD_PARAM_MAP["test_3"], "", request.parameters)
|
52
55
|
render json: GrpcRest.send_request("Testdata::MyService", "test_3", grpc_request)
|
53
56
|
end
|
54
57
|
|
55
58
|
def test_4
|
56
59
|
fields = Testdata::TestRequest.descriptor.to_a.map(&:name)
|
57
|
-
|
60
|
+
parameters = request.parameters.to_h.deep_transform_keys(&:underscore)
|
61
|
+
grpc_request = GrpcRest.init_request(Testdata::TestRequest, parameters.slice(*fields))
|
58
62
|
GrpcRest.assign_params(grpc_request, METHOD_PARAM_MAP["test_4"], "*", request.parameters)
|
59
63
|
render json: GrpcRest.send_request("Testdata::MyService", "test_4", grpc_request)
|
60
64
|
end
|
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.17
|
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-07-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: grpc
|