grpc-rest 0.1.10 → 0.1.12

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: 7cd53f44aee783542e52eb72b647d8070a88038ae5248fda1ede02ad8c9d9fea
4
- data.tar.gz: 883a2f69f05b0e40e895fa3bd4a82f571c722ca5a2099862d767ac60ebf6ce85
3
+ metadata.gz: 8bfe3edbd1ceece344b2dff703ce619a0d829e40cec4022fe4676fe61ab77940
4
+ data.tar.gz: a86fd6b8b0fd11479510e3db9296431d4f36490ec2ad1037ce2a1e80fcac2578
5
5
  SHA512:
6
- metadata.gz: 1e252cbb74d82d8730141ac33c7284d5db40cb759c1ad5f0a19b66e2d8317c27c3678244af019f7865d97a908243c5dbd6d709f5213657868ff042cc000414e2
7
- data.tar.gz: 31478108c117b7db638bc7b75908c07aaf67664cfe8ae6d229ddc15e5c96a701e8cdb156d72ea5412e8a27e931a85981cff884afe93986c785db4b044925dc25
6
+ metadata.gz: c08004595c9f8db0c3e7f6a0f9b15c35fa91f83229ed2741a303633fd174a6f1dba521ba73fb989a17ea901fd5c46177f842449845fd5493c45182bcc232bde4
7
+ data.tar.gz: 4010b037a9bd33eb3b5b80896dbc73449f4adb2fccc51771ecec9d0bea1017365181eb9c4e23e87763c8c62cbf15a43da9e5bf2c0b2ef8ae5e6f4f6da870d1ec
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.12 - 2024-05-15
11
+ - Parse numbers into Ruby number objects.
12
+
10
13
  # 0.1.10 - 2024-04-06
11
14
  - Fix incorrect decoding of enum descriptors.
12
15
 
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- grpc-rest (0.1.9)
4
+ grpc-rest (0.1.11)
5
5
  grpc
6
6
  rails (>= 6.0)
7
7
 
@@ -1,3 +1,3 @@
1
1
  module GrpcRest
2
- VERSION = "0.1.10"
2
+ VERSION = '0.1.12'
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)
@@ -57,13 +66,19 @@ module GrpcRest
57
66
  when 'google.protobuf.ListValue'
58
67
  params[field] = Google::Protobuf::ListValue.from_a(val)
59
68
  else
60
- map_wkt(descriptor.subtype, params[field]) if descriptor.subtype
69
+ if params[field].is_a?(Array)
70
+ params[field].each do |item|
71
+ map_proto_type(descriptor.subtype, item)
72
+ end
73
+ else
74
+ map_proto_type(descriptor.subtype, params[field])
75
+ end
61
76
  end
62
77
  end
63
78
  end
64
79
 
65
80
  def init_request(request_class, params)
66
- map_wkt(request_class.descriptor, params)
81
+ map_proto_type(request_class.descriptor, params)
67
82
  request_class.new(params)
68
83
  end
69
84
 
@@ -16,6 +16,8 @@ message TestRequest {
16
16
  google.protobuf.Timestamp timestamp_field = 7;
17
17
  google.protobuf.ListValue list_value = 8;
18
18
  google.protobuf.Value bare_value = 9;
19
+ repeated SubRecord sub_records = 10;
20
+ int32 some_int = 11;
19
21
  }
20
22
 
21
23
  message SubRecord {
@@ -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: {
@@ -95,7 +96,7 @@ RSpec.describe MyServiceController, type: :request do
95
96
  expect(response).to be_successful
96
97
  expect(response.parsed_body).to eq({
97
98
  '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})
99
+ '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,\"someInt\":65})
99
100
  })
100
101
  end
101
102
  end
@@ -114,4 +115,21 @@ RSpec.describe MyServiceController, type: :request do
114
115
  end
115
116
  end
116
117
 
118
+ describe 'array of sub-records' do
119
+ it 'should be successful' do
120
+ params = {
121
+ sub_records: [{
122
+ sub_id: 'id1',
123
+ another_id: 'id2'
124
+ }]
125
+ }
126
+
127
+ post '/test4', params:, as: :json
128
+ expect(response).to be_successful
129
+ expect(response.parsed_body).to eq({
130
+ 'some_int' => 4,
131
+ 'full_response' => %({"subRecords":[{"subId":"id1","anotherId":"id2"}]})
132
+ })
133
+ end
134
+ end
117
135
  end
@@ -9,33 +9,10 @@ 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\"\xdc\x02\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\"/\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
-
16
- begin
17
- pool.add_serialized_file(descriptor_data)
18
- rescue TypeError
19
- # Compatibility code: will be removed in the next major version.
20
- require 'google/protobuf/descriptor_pb'
21
- parsed = Google::Protobuf::FileDescriptorProto.decode(descriptor_data)
22
- parsed.clear_dependency
23
- serialized = parsed.class.encode(parsed)
24
- file = pool.add_serialized_file(serialized)
25
- warn "Warning: Protobuf detected an import path issue while loading generated file #{__FILE__}"
26
- imports = [
27
- ["google.protobuf.Struct", "google/protobuf/struct.proto"],
28
- ["google.protobuf.Timestamp", "google/protobuf/timestamp.proto"],
29
- ]
30
- imports.each do |type_name, expected_filename|
31
- import_file = pool.lookup(type_name).file_descriptor
32
- if import_file.name != expected_filename
33
- warn "- #{file.name} imports #{expected_filename}, but that import was loaded as #{import_file.name}"
34
- end
35
- end
36
- warn "Each proto file must use a consistent fully-qualified name."
37
- warn "This will become an error in the next major version."
38
- end
15
+ pool.add_serialized_file(descriptor_data)
39
16
 
40
17
  module Testdata
41
18
  TestRequest = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("testdata.TestRequest").msgclass
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.10
4
+ version: 0.1.12
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-06 00:00:00.000000000 Z
11
+ date: 2024-05-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: grpc