grpc-rest 0.1.11 → 0.1.13

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: 56ba9cbb18e3e8e94caeea9e076756289d9528ce0bbc73ef64baa54cfc931900
4
- data.tar.gz: 757bb291af0d057ddd7f56f5408e8d72711a9aa388a95bf72aa1789dc35440ae
3
+ metadata.gz: 1cb358eab4313d2e6f4bc27e6e6e7f41694c4828bc176f91430696cc3153fabf
4
+ data.tar.gz: f73e835ef854696b65e2d92f2d650748f25e5d7ce2a16c9bcc397cfc4d96686d
5
5
  SHA512:
6
- metadata.gz: 38dada65b29e6122f66dc994a0e8b2e1ce14029a736278d6a81445b4aa5877a21b8f53f7b39ec1c96b59777b5d90414379728bb35099cb237704e09ac059a925
7
- data.tar.gz: 53e67d73074947f701c7ede6727170142d9dafb7f586156aa95a46fd35ce6e2ce87f6cb6101b80a12e732fcd5a8821815a0c48e9ac2e489131a1c41108365a20
6
+ metadata.gz: dc94a596a11a98b0bf69fa2f3215139d555429b1208d2c91c52266dfad9ddd2e867a1e40de258c8fc2f414b0234decfc5c00c17758291c2ac87d160c8d0c5b10
7
+ data.tar.gz: 95f30263280cf09bc426843c27a41afaf35c009079d238c3b611a20fc766b53cc57c16c566f94f3f526b31356cf8509bf1548be2e12322791773594e37699e71
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.13 - 2024-06-24
11
+ - Use JSON parsing / generation to fix inaccurate transformations (e.g. Timestamp).
12
+
13
+ # 0.1.12 - 2024-05-15
14
+ - Parse numbers into Ruby number objects.
15
+
10
16
  # 0.1.10 - 2024-04-06
11
17
  - Fix incorrect decoding of enum descriptors.
12
18
 
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- grpc-rest (0.1.11)
4
+ grpc-rest (0.1.12)
5
5
  grpc
6
6
  rails (>= 6.0)
7
7
 
@@ -1,3 +1,3 @@
1
1
  module GrpcRest
2
- VERSION = '0.1.11'
2
+ VERSION = '0.1.13'
3
3
  end
data/lib/grpc_rest.rb CHANGED
@@ -36,13 +36,22 @@ module GrpcRest
36
36
  proto.public_send(:"#{tokens.last}=", value) if proto.respond_to?(:"#{tokens.last}=")
37
37
  end
38
38
 
39
- def map_wkt(proto, params)
39
+ def map_proto_type(proto, params)
40
40
  proto.to_a.each do |descriptor|
41
41
  field = descriptor.name
42
42
  val = params[field]
43
43
  next if val.nil?
44
44
  next if descriptor.subtype.is_a?(Google::Protobuf::EnumDescriptor)
45
45
 
46
+ case descriptor.type
47
+ when *%i(int32 int64 uint32 uint64 sint32 sint64 fixed32 fixed64 sfixed32 sfixed64)
48
+ params[field] = val.to_i
49
+ when *%i(float double)
50
+ params[field] = val.to_f
51
+ when :bool
52
+ params[field] = !!val
53
+ end
54
+
46
55
  case descriptor.subtype&.name
47
56
  when 'google.protobuf.Struct'
48
57
  params[field] = Google::Protobuf::Struct.from_hash(val)
@@ -59,18 +68,18 @@ module GrpcRest
59
68
  else
60
69
  if params[field].is_a?(Array)
61
70
  params[field].each do |item|
62
- map_wkt(descriptor.subtype, item)
71
+ map_proto_type(descriptor.subtype, item)
63
72
  end
64
73
  else
65
- map_wkt(descriptor.subtype, params[field])
74
+ map_proto_type(descriptor.subtype, params[field])
66
75
  end
67
76
  end
68
77
  end
69
78
  end
70
79
 
71
80
  def init_request(request_class, params)
72
- map_wkt(request_class.descriptor, params)
73
- request_class.new(params)
81
+ map_proto_type(request_class.descriptor, params)
82
+ request_class.decode_json(JSON.generate(params))
74
83
  end
75
84
 
76
85
  def assign_params(request, param_hash, body_string, params)
@@ -132,10 +141,10 @@ module GrpcRest
132
141
  k.bound_service == service_obj
133
142
  end
134
143
  if klass
135
- return send_gruf_request(klass, service_obj, method, request).to_h
144
+ return send_gruf_request(klass, service_obj, method, request)
136
145
  end
137
146
  end
138
- send_grpc_request(service, method, request).to_h
147
+ send_grpc_request(service, method, request)
139
148
  end
140
149
  end
141
150
 
@@ -17,6 +17,7 @@ message TestRequest {
17
17
  google.protobuf.ListValue list_value = 8;
18
18
  google.protobuf.Value bare_value = 9;
19
19
  repeated SubRecord sub_records = 10;
20
+ int32 some_int = 11;
20
21
  }
21
22
 
22
23
  message SubRecord {
@@ -28,8 +28,8 @@ RSpec.describe MyServiceController, type: :request do
28
28
  get "/test/blah/xyz?test_id=abc"
29
29
  expect(response).to be_successful
30
30
  expect(response.parsed_body).to eq({
31
- 'some_int' => 1,
32
- 'full_response' => %({"testId":"abc","foobar":"xyz"})
31
+ 'someInt' => 1,
32
+ 'fullResponse' => %({"testId":"abc","foobar":"xyz"})
33
33
  })
34
34
  end
35
35
  end
@@ -44,8 +44,8 @@ RSpec.describe MyServiceController, type: :request do
44
44
  post '/test2?test_id=abc&foobar=xyz&timestamp_field=2024-04-03+01:02:03+UTC', params: params, as: :json
45
45
  expect(response).to be_successful
46
46
  expect(response.parsed_body).to eq({
47
- 'some_int' => 2,
48
- 'full_response' => %({"testId":"abc","foobar":"xyz","secondRecord":{"subId":"id1","anotherId":"id2"},"timestampField":"2024-04-03T01:02:03Z"})
47
+ 'someInt' => 2,
48
+ 'fullResponse' => %({"testId":"abc","foobar":"xyz","secondRecord":{"subId":"id1","anotherId":"id2"},"timestampField":"2024-04-03T01:02:03Z"})
49
49
  })
50
50
  end
51
51
 
@@ -56,8 +56,8 @@ RSpec.describe MyServiceController, type: :request do
56
56
  post '/test3/xyz?test_id=abc'
57
57
  expect(response).to be_successful
58
58
  expect(response.parsed_body).to eq({
59
- 'some_int' => 3,
60
- 'full_response' => %({"testId":"abc","subRecord":{"subId":"xyz"}})
59
+ 'someInt' => 3,
60
+ 'fullResponse' => %({"testId":"abc","subRecord":{"subId":"xyz"}})
61
61
  })
62
62
  end
63
63
  end
@@ -66,6 +66,7 @@ RSpec.describe MyServiceController, type: :request do
66
66
  it 'should be successful' do
67
67
  params = {
68
68
  test_id: 'abc',
69
+ some_int: "65",
69
70
  foobar: 'xyz',
70
71
  repeated_string: ['W', 'T', 'F'],
71
72
  sub_record: {
@@ -94,8 +95,8 @@ RSpec.describe MyServiceController, type: :request do
94
95
  post '/test4', params: params, as: :json
95
96
  expect(response).to be_successful
96
97
  expect(response.parsed_body).to eq({
97
- 'some_int' => 4,
98
- 'full_response' => %({"testId":"abc","foobar":"xyz","repeatedString":["W","T","F"],"subRecord":{"subId":"id1","anotherId":"id2"},"secondRecord":{"subId":"id3","anotherId":"id4"},"structField":{"bool_key":true,"str_key":"val","nil_key":null,"list_key":[{"inner_key":"inner_val"}],"int_key":123},"timestampField":"2024-04-03T01:02:03Z","listValue":["F","Y","I"],"bareValue":45})
98
+ 'someInt' => 4,
99
+ 'fullResponse' => %({"testId":"abc","foobar":"xyz","repeatedString":["W","T","F"],"subRecord":{"subId":"id1","anotherId":"id2"},"secondRecord":{"subId":"id3","anotherId":"id4"},"structField":{"bool_key":true,"str_key":"val","nil_key":null,"list_key":[{"inner_key":"inner_val"}],"int_key":123},"timestampField":"2024-04-03T01:02:03Z","listValue":["F","Y","I"],"bareValue":45,\"someInt\":65})
99
100
  })
100
101
  end
101
102
  end
@@ -108,8 +109,8 @@ RSpec.describe MyServiceController, type: :request do
108
109
  post "/test4", params: params, as: :json
109
110
  expect(response).to be_successful
110
111
  expect(response.parsed_body).to eq({
111
- 'some_int' => 4,
112
- 'full_response' => %({"timestampField":"2024-04-09T19:54:12Z"})
112
+ 'someInt' => 4,
113
+ 'fullResponse' => %({"timestampField":"2024-04-09T19:54:12Z"})
113
114
  })
114
115
  end
115
116
  end
@@ -126,8 +127,8 @@ RSpec.describe MyServiceController, type: :request do
126
127
  post '/test4', params:, as: :json
127
128
  expect(response).to be_successful
128
129
  expect(response.parsed_body).to eq({
129
- 'some_int' => 4,
130
- 'full_response' => %({"subRecords":[{"subId":"id1","anotherId":"id2"}]})
130
+ 'someInt' => 4,
131
+ 'fullResponse' => %({"subRecords":[{"subId":"id1","anotherId":"id2"}]})
131
132
  })
132
133
  end
133
134
  end
@@ -9,7 +9,7 @@ require 'google/protobuf/struct_pb'
9
9
  require 'google/protobuf/timestamp_pb'
10
10
 
11
11
 
12
- descriptor_data = "\n\x12test_service.proto\x12\x08testdata\x1a\x1cgoogle/api/annotations.proto\x1a\x1cgoogle/protobuf/struct.proto\x1a\x1fgoogle/protobuf/timestamp.proto\"\x86\x03\n\x0bTestRequest\x12\x0f\n\x07test_id\x18\x01 \x01(\t\x12\x0e\n\x06\x66oobar\x18\x02 \x01(\t\x12\x17\n\x0frepeated_string\x18\x03 \x03(\t\x12\'\n\nsub_record\x18\x04 \x01(\x0b\x32\x13.testdata.SubRecord\x12*\n\rsecond_record\x18\x05 \x01(\x0b\x32\x13.testdata.SubRecord\x12-\n\x0cstruct_field\x18\x06 \x01(\x0b\x32\x17.google.protobuf.Struct\x12\x33\n\x0ftimestamp_field\x18\x07 \x01(\x0b\x32\x1a.google.protobuf.Timestamp\x12.\n\nlist_value\x18\x08 \x01(\x0b\x32\x1a.google.protobuf.ListValue\x12*\n\nbare_value\x18\t \x01(\x0b\x32\x16.google.protobuf.Value\x12(\n\x0bsub_records\x18\n \x03(\x0b\x32\x13.testdata.SubRecord\"/\n\tSubRecord\x12\x0e\n\x06sub_id\x18\x01 \x01(\t\x12\x12\n\nanother_id\x18\x02 \x01(\t\"7\n\x0cTestResponse\x12\x10\n\x08some_int\x18\x01 \x01(\x05\x12\x15\n\rfull_response\x18\x02 \x01(\t2\xdf\x02\n\tMyService\x12T\n\x04Test\x12\x15.testdata.TestRequest\x1a\x16.testdata.TestResponse\"\x1d\x82\xd3\xe4\x93\x02\x17\x12\x15/test/{foobar=blah/*}\x12U\n\x05Test2\x12\x15.testdata.TestRequest\x1a\x16.testdata.TestResponse\"\x1d\x82\xd3\xe4\x93\x02\x17\"\x06/test2:\rsecond_record\x12Z\n\x05Test3\x12\x15.testdata.TestRequest\x1a\x16.testdata.TestResponse\"\"\x82\xd3\xe4\x93\x02\x1c\"\x1a/test3/{sub_record.sub_id}\x12I\n\x05Test4\x12\x15.testdata.TestRequest\x1a\x16.testdata.TestResponse\"\x11\x82\xd3\xe4\x93\x02\x0b\"\x06/test4:\x01*b\x06proto3"
12
+ descriptor_data = "\n\x12test_service.proto\x12\x08testdata\x1a\x1cgoogle/api/annotations.proto\x1a\x1cgoogle/protobuf/struct.proto\x1a\x1fgoogle/protobuf/timestamp.proto\"\x98\x03\n\x0bTestRequest\x12\x0f\n\x07test_id\x18\x01 \x01(\t\x12\x0e\n\x06\x66oobar\x18\x02 \x01(\t\x12\x17\n\x0frepeated_string\x18\x03 \x03(\t\x12\'\n\nsub_record\x18\x04 \x01(\x0b\x32\x13.testdata.SubRecord\x12*\n\rsecond_record\x18\x05 \x01(\x0b\x32\x13.testdata.SubRecord\x12-\n\x0cstruct_field\x18\x06 \x01(\x0b\x32\x17.google.protobuf.Struct\x12\x33\n\x0ftimestamp_field\x18\x07 \x01(\x0b\x32\x1a.google.protobuf.Timestamp\x12.\n\nlist_value\x18\x08 \x01(\x0b\x32\x1a.google.protobuf.ListValue\x12*\n\nbare_value\x18\t \x01(\x0b\x32\x16.google.protobuf.Value\x12(\n\x0bsub_records\x18\n \x03(\x0b\x32\x13.testdata.SubRecord\x12\x10\n\x08some_int\x18\x0b \x01(\x05\"/\n\tSubRecord\x12\x0e\n\x06sub_id\x18\x01 \x01(\t\x12\x12\n\nanother_id\x18\x02 \x01(\t\"7\n\x0cTestResponse\x12\x10\n\x08some_int\x18\x01 \x01(\x05\x12\x15\n\rfull_response\x18\x02 \x01(\t2\xdf\x02\n\tMyService\x12T\n\x04Test\x12\x15.testdata.TestRequest\x1a\x16.testdata.TestResponse\"\x1d\x82\xd3\xe4\x93\x02\x17\x12\x15/test/{foobar=blah/*}\x12U\n\x05Test2\x12\x15.testdata.TestRequest\x1a\x16.testdata.TestResponse\"\x1d\x82\xd3\xe4\x93\x02\x17\"\x06/test2:\rsecond_record\x12Z\n\x05Test3\x12\x15.testdata.TestRequest\x1a\x16.testdata.TestResponse\"\"\x82\xd3\xe4\x93\x02\x1c\"\x1a/test3/{sub_record.sub_id}\x12I\n\x05Test4\x12\x15.testdata.TestRequest\x1a\x16.testdata.TestResponse\"\x11\x82\xd3\xe4\x93\x02\x0b\"\x06/test4:\x01*b\x06proto3"
13
13
 
14
14
  pool = Google::Protobuf::DescriptorPool.generated_pool
15
15
  pool.add_serialized_file(descriptor_data)
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.11
4
+ version: 0.1.13
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-05-10 00:00:00.000000000 Z
11
+ date: 2024-06-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: grpc