grpc-rest 0.1.15 → 0.1.16

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: 61c130f717134177cf54979446039f2be1144a66f1fb8e0eb85b64f4bdf70bcc
4
- data.tar.gz: bf5fdf842d2f8c1aa20e45fdd88eff0f0d7cabeb8decf77c9bcb6ae7e3794a1a
3
+ metadata.gz: 461dd3e8eb1185e6b30d1bfe5c62e07cf63f09d8c9d6beb3cc50d16c9a637933
4
+ data.tar.gz: d8f6683a57212a7485f06648365d76192c8910a63a7b9938ab816dd6df251944
5
5
  SHA512:
6
- metadata.gz: 006c5943b3bc2b497fcc591527c3d14558a0a6f54922baca7d8d445248ded8718c3debb406440411c48cf869061a28dbd5b3e2135c6aee1a168dd5b149e7ee43
7
- data.tar.gz: e667e1f72ae7ba6cfea978e9e075f4758e101bfd9b8c3b07b5c4f0110d7c51b18bc1304baf923da5279a7b8d9b6a18e69e44c8918b71e746e0d8557b47095eaf
6
+ metadata.gz: e37a3b27b16712f40b18207442eed3dcf176446c30951e692aedb027716f6b784dd046917a5db532e7fd313998fddcbeed41efafbbdc399a570c0fb7c380ae39
7
+ data.tar.gz: ccfa637e8573b108cdff2c713a71aa532aa074484696e53a678b37905b74f3d037b38eae22b6d1d7582c1e4faa46f9cc72330fffb496ca1d0b22bd0b7d245aae
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.16 - 2024-07-09
11
+ - Support requests in camel case
12
+
10
13
  # 0.1.15 - 2024-06-26
11
14
  - Actually emit the correct error code on failure. :(
12
15
 
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- grpc-rest (0.1.14)
4
+ grpc-rest (0.1.15)
5
5
  grpc
6
6
  rails (>= 6.0)
7
7
 
@@ -1,3 +1,3 @@
1
1
  module GrpcRest
2
- VERSION = '0.1.15'
2
+ VERSION = '0.1.16'
3
3
  end
@@ -1,39 +1,40 @@
1
1
  package internal
2
2
 
3
3
  import (
4
- "bytes"
5
- "fmt"
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 string
14
+ Name string
14
15
  Content string
15
16
  }
16
17
 
17
18
  type controller struct {
18
- ControllerName string
19
- Methods []method
20
- ServiceName string
19
+ ControllerName string
20
+ Methods []method
21
+ ServiceName string
21
22
  FullServiceName string
22
- MethodName string
23
+ MethodName string
23
24
  }
24
25
 
25
26
  type method struct {
26
- Name string
27
+ Name string
27
28
  RequestType string
28
- Path string
29
- PathInfo []PathInfo
30
- Body string
31
- HttpMethod string
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 string
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
- grpc_request = GrpcRest.init_request({{.RequestType}}, request.parameters.to_h.slice(*fields))
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
- var routes []Route
81
+ var routes []Route
80
82
  data := controller{
81
- Methods: []method{},
82
- ServiceName: Classify(service.GetName()),
83
- ControllerName: Demodulize(service.GetName()),
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: strcase.ToSnake(m.GetName()),
99
+ Name: strcase.ToSnake(m.GetName()),
98
100
  RequestType: Classify(m.GetInputType()),
99
- Path: path,
100
- HttpMethod: httpMethod,
101
- Body: opts.Body,
102
- PathInfo: 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: SanitizePath(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: fmt.Sprintf("app/controllers/%s_controller.rb", strcase.ToSnake(data.ControllerName)),
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
- grpc_request = GrpcRest.init_request(Testdata::TestRequest, request.parameters.to_h.slice(*fields))
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
- grpc_request = GrpcRest.init_request(Testdata::TestRequest, request.parameters.to_h.slice(*fields))
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
- grpc_request = GrpcRest.init_request(Testdata::TestRequest, request.parameters.to_h.slice(*fields))
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
- grpc_request = GrpcRest.init_request(Testdata::TestRequest, request.parameters.to_h.slice(*fields))
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.15
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-06-26 00:00:00.000000000 Z
11
+ date: 2024-07-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: grpc