grpc-rest 0.1.9 → 0.1.11
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG +3 -0
- data/Gemfile.lock +1 -1
- data/README.md +1 -1
- data/lib/grpc_rest/version.rb +1 -1
- data/lib/grpc_rest.rb +8 -1
- data/protoc-gen-rails/testdata/test_service.proto +1 -0
- data/spec/grpc_rest_spec.rb +17 -0
- data/spec/test_service_pb.rb +2 -25
- 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: 56ba9cbb18e3e8e94caeea9e076756289d9528ce0bbc73ef64baa54cfc931900
|
4
|
+
data.tar.gz: 757bb291af0d057ddd7f56f5408e8d72711a9aa388a95bf72aa1789dc35440ae
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 38dada65b29e6122f66dc994a0e8b2e1ce14029a736278d6a81445b4aa5877a21b8f53f7b39ec1c96b59777b5d90414379728bb35099cb237704e09ac059a925
|
7
|
+
data.tar.gz: 53e67d73074947f701c7ede6727170142d9dafb7f586156aa95a46fd35ce6e2ce87f6cb6101b80a12e732fcd5a8821815a0c48e9ac2e489131a1c41108365a20
|
data/CHANGELOG
CHANGED
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -125,7 +125,7 @@ Rails.application.routes.draw do
|
|
125
125
|
draw(:grpc) # Add this line
|
126
126
|
end
|
127
127
|
```
|
128
|
-
|
128
|
+
|
129
129
|
## Caveats
|
130
130
|
|
131
131
|
This gem does not currently support the full path expression capabilities of grpc-gateway or the Google [http proto](https://github.com/googleapis/googleapis/blob/master/google/api/http.proto). It only supports very basic single wildcard globbing (`*`). Contributions are welcome for more complex cases if they are needed.
|
data/lib/grpc_rest/version.rb
CHANGED
data/lib/grpc_rest.rb
CHANGED
@@ -41,6 +41,7 @@ module GrpcRest
|
|
41
41
|
field = descriptor.name
|
42
42
|
val = params[field]
|
43
43
|
next if val.nil?
|
44
|
+
next if descriptor.subtype.is_a?(Google::Protobuf::EnumDescriptor)
|
44
45
|
|
45
46
|
case descriptor.subtype&.name
|
46
47
|
when 'google.protobuf.Struct'
|
@@ -56,7 +57,13 @@ module GrpcRest
|
|
56
57
|
when 'google.protobuf.ListValue'
|
57
58
|
params[field] = Google::Protobuf::ListValue.from_a(val)
|
58
59
|
else
|
59
|
-
|
60
|
+
if params[field].is_a?(Array)
|
61
|
+
params[field].each do |item|
|
62
|
+
map_wkt(descriptor.subtype, item)
|
63
|
+
end
|
64
|
+
else
|
65
|
+
map_wkt(descriptor.subtype, params[field])
|
66
|
+
end
|
60
67
|
end
|
61
68
|
end
|
62
69
|
end
|
data/spec/grpc_rest_spec.rb
CHANGED
@@ -114,4 +114,21 @@ RSpec.describe MyServiceController, type: :request do
|
|
114
114
|
end
|
115
115
|
end
|
116
116
|
|
117
|
+
describe 'array of sub-records' do
|
118
|
+
it 'should be successful' do
|
119
|
+
params = {
|
120
|
+
sub_records: [{
|
121
|
+
sub_id: 'id1',
|
122
|
+
another_id: 'id2'
|
123
|
+
}]
|
124
|
+
}
|
125
|
+
|
126
|
+
post '/test4', params:, as: :json
|
127
|
+
expect(response).to be_successful
|
128
|
+
expect(response.parsed_body).to eq({
|
129
|
+
'some_int' => 4,
|
130
|
+
'full_response' => %({"subRecords":[{"subId":"id1","anotherId":"id2"}]})
|
131
|
+
})
|
132
|
+
end
|
133
|
+
end
|
117
134
|
end
|
data/spec/test_service_pb.rb
CHANGED
@@ -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\"\
|
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"
|
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.
|
4
|
+
version: 0.1.11
|
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-05-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: grpc
|