grpc-rest 0.1.14 → 0.1.16
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/protoc-gen-rails/internal/output.go +30 -28
- data/protoc-gen-rails/testdata/base/app/controllers/my_service_controller.rb +9 -5
- 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: 461dd3e8eb1185e6b30d1bfe5c62e07cf63f09d8c9d6beb3cc50d16c9a637933
|
4
|
+
data.tar.gz: d8f6683a57212a7485f06648365d76192c8910a63a7b9938ab816dd6df251944
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e37a3b27b16712f40b18207442eed3dcf176446c30951e692aedb027716f6b784dd046917a5db532e7fd313998fddcbeed41efafbbdc399a570c0fb7c380ae39
|
7
|
+
data.tar.gz: ccfa637e8573b108cdff2c713a71aa532aa074484696e53a678b37905b74f3d037b38eae22b6d1d7582c1e4faa46f9cc72330fffb496ca1d0b22bd0b7d245aae
|
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.16 - 2024-07-09
|
11
|
+
- Support requests in camel case
|
12
|
+
|
13
|
+
# 0.1.15 - 2024-06-26
|
14
|
+
- Actually emit the correct error code on failure. :(
|
15
|
+
|
10
16
|
# 0.1.14 - 2024-06-25
|
11
17
|
- Emit the correct error code on failure.
|
12
18
|
|
data/Gemfile.lock
CHANGED
data/lib/grpc_rest/version.rb
CHANGED
@@ -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
|
}
|
@@ -49,7 +50,7 @@ class {{.ControllerName}}Controller < ActionController::Base
|
|
49
50
|
render json: GrpcRest.error_msg(e), status: :internal_server_error
|
50
51
|
end
|
51
52
|
rescue_from GRPC::BadStatus do |e|
|
52
|
-
render json: GrpcRest.error_msg(e), status:
|
53
|
+
render json: GrpcRest.error_msg(e), status: GrpcRest.grpc_http_status(e.code)
|
53
54
|
end
|
54
55
|
rescue_from Google::Protobuf::TypeError do |e|
|
55
56
|
render json: GrpcRest.error_msg(e), status: :bad_request
|
@@ -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
|
|
@@ -9,7 +9,7 @@ class MyServiceController < ActionController::Base
|
|
9
9
|
render json: GrpcRest.error_msg(e), status: :internal_server_error
|
10
10
|
end
|
11
11
|
rescue_from GRPC::BadStatus do |e|
|
12
|
-
render json: GrpcRest.error_msg(e), status:
|
12
|
+
render json: GrpcRest.error_msg(e), status: GrpcRest.grpc_http_status(e.code)
|
13
13
|
end
|
14
14
|
rescue_from Google::Protobuf::TypeError do |e|
|
15
15
|
render json: GrpcRest.error_msg(e), status: :bad_request
|
@@ -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.16
|
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-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: grpc
|