gapic-common 0.17.1 → 0.19.0

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: 508b67fe556c18e32cab88da23a0097e425df549e288b72fec7d4a891b6c06f5
4
- data.tar.gz: 29bbc436a310b93f2f043502344783835ba25ed91d5ac8523c190da0ecd019b4
3
+ metadata.gz: 8f4c41c2fffb829cfadc7792a8e1e2a15162ae960ae810f216dd4cb677dc9098
4
+ data.tar.gz: 3214f4236eb38446cf46b89d1957c659abbbb8265eecafe6275d8448dfdfabb8
5
5
  SHA512:
6
- metadata.gz: 34e4be1fc16714c9afc6bd0d9ca832ae7409521d0ec9f10c41860e817c8ee28599d6853a0c84a780dc3e3fc19d33882068d613f2691d6ee99392b68f2c5dbe04
7
- data.tar.gz: 6f130dd5c05535efc27e67f51a6b593082519a04601d69111db010d097e7c150501e9cee2845d4937c175fce79451f413b5e125e9f74d01f66634d74d6b9604a
6
+ metadata.gz: d18733e8a412ed7c366e14a253a62f460b1685503ee71bc435b35bd152263a48ace22f7d3be1da50c39da7b67bdcd720e70054154cee029c68cb670a0b79e25c
7
+ data.tar.gz: f409bbbe7036ab93a7952b5085b1bd11af4ee902afe36625fe2872bc142ced1c27f22b88d967ad4fb64d35d141af7cba678ab57bcae8f5709132db1e3e3b9c84
data/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # Release History
2
2
 
3
+ ### 0.19.0 (2023-05-26)
4
+
5
+ #### Features
6
+
7
+ * Compatibility with protobuf v23 generated map fields ([#948](https://github.com/googleapis/gapic-generator-ruby/issues/948))
8
+
9
+ ### 0.18.0 (2023-02-27)
10
+
11
+ #### Features
12
+
13
+ * add alias for details field in Rest Error ([#928](https://github.com/googleapis/gapic-generator-ruby/issues/928))
14
+
3
15
  ### 0.17.1 (2023-02-09)
4
16
 
5
17
  #### Bug Fixes
@@ -14,6 +14,6 @@
14
14
 
15
15
  module Gapic
16
16
  module Common
17
- VERSION = "0.17.1".freeze
17
+ VERSION = "0.19.0".freeze
18
18
  end
19
19
  end
@@ -16,7 +16,8 @@ require "google/protobuf/timestamp_pb"
16
16
 
17
17
  module Gapic
18
18
  ##
19
- # TODO: Describe Protobuf
19
+ # A set of internal utilities for coercing data to protobuf messages.
20
+ #
20
21
  module Protobuf
21
22
  ##
22
23
  # Creates an instance of a protobuf message from a hash that may include nested hashes. `google/protobuf` allows
@@ -31,10 +32,13 @@ module Gapic
31
32
  def self.coerce hash, to:
32
33
  return hash if hash.is_a? to
33
34
 
35
+ # Special case handling of certain types
36
+ return time_to_timestamp hash if to == Google::Protobuf::Timestamp && hash.is_a?(Time)
37
+
34
38
  # Sanity check: input must be a Hash
35
39
  raise ArgumentError, "Value #{hash} must be a Hash or a #{to.name}" unless hash.is_a? Hash
36
40
 
37
- hash = coerce_submessages hash, to
41
+ hash = coerce_submessages hash, to.descriptor
38
42
  to.new hash
39
43
  end
40
44
 
@@ -44,89 +48,58 @@ module Gapic
44
48
  # @private
45
49
  #
46
50
  # @param hash [Hash] The hash whose nested hashes will be coerced.
47
- # @param message_class [Class] The corresponding protobuf message class of the given hash.
51
+ # @param message_descriptor [Google::Protobuf::Descriptor] The protobuf descriptor for the message.
48
52
  #
49
53
  # @return [Hash] A hash whose nested hashes have been coerced.
50
- def self.coerce_submessages hash, message_class
54
+ def self.coerce_submessages hash, message_descriptor
51
55
  return nil if hash.nil?
52
56
  coerced = {}
53
- message_descriptor = message_class.descriptor
54
57
  hash.each do |key, val|
55
58
  field_descriptor = message_descriptor.lookup key.to_s
56
- coerced[key] = if field_descriptor && field_descriptor.type == :message
57
- coerce_submessage val, field_descriptor
58
- elsif field_descriptor && field_descriptor.type == :bytes &&
59
- (val.is_a?(IO) || val.is_a?(StringIO))
60
- val.binmode.read
61
- else
62
- # `google/protobuf` should throw an error if no field descriptor is
63
- # found. Simply pass through.
64
- val
65
- end
59
+ coerced[key] =
60
+ if field_descriptor&.type == :message
61
+ coerce_submessage val, field_descriptor
62
+ elsif field_descriptor&.type == :bytes && (val.is_a?(IO) || val.is_a?(StringIO))
63
+ val.binmode.read
64
+ else
65
+ # For non-message fields, just pass the scalar value through.
66
+ # Note: if field_descriptor is not found, we just pass the value
67
+ # through and let protobuf raise an error.
68
+ val
69
+ end
66
70
  end
67
71
  coerced
68
72
  end
69
73
 
70
74
  ##
71
- # Coerces the value of a field to be acceptable by the instantiation method of the wrapping message.
75
+ # Coerces a message-typed field.
76
+ # The field can be a normal single message, a repeated message, or a map.
72
77
  #
73
78
  # @private
74
79
  #
75
- # @param val [Object] The value to be coerced.
76
- # @param field_descriptor [Google::Protobuf::FieldDescriptor] The field descriptor of the value.
80
+ # @param val [Object] The value to coerce
81
+ # @param field_descriptor [Google::Protobuf::FieldDescriptor] The field descriptor.
77
82
  #
78
- # @return [Object] The coerced version of the given value.
79
83
  def self.coerce_submessage val, field_descriptor
80
- if (field_descriptor.label == :repeated) && !(map_field? field_descriptor)
81
- coerce_array val, field_descriptor
82
- elsif field_descriptor.subtype.msgclass == Google::Protobuf::Timestamp && val.is_a?(Time)
83
- time_to_timestamp val
84
+ if val.is_a? Array
85
+ # Assume this is a repeated message field, iterate over it and coerce
86
+ # each to the message class.
87
+ # Protobuf will raise an error if this assumption is incorrect.
88
+ val.map do |elem|
89
+ coerce elem, to: field_descriptor.subtype.msgclass
90
+ end
91
+ elsif field_descriptor.label == :repeated
92
+ # Non-array passed to a repeated field: assume this is a map, and that
93
+ # a hash is being passed, and let protobuf handle the conversion.
94
+ # Protobuf will raise an error if this assumption is incorrect.
95
+ val
84
96
  else
85
- coerce_value val, field_descriptor
86
- end
87
- end
88
-
89
- ##
90
- # Coerces the values of an array to be acceptable by the instantiation method the wrapping message.
91
- #
92
- # @private
93
- #
94
- # @param array [Array<Object>] The values to be coerced.
95
- # @param field_descriptor [Google::Protobuf::FieldDescriptor] The field descriptor of the values.
96
- #
97
- # @return [Array<Object>] The coerced version of the given values.
98
- def self.coerce_array array, field_descriptor
99
- raise ArgumentError, "Value #{array} must be an array" unless array.is_a? Array
100
- array.map do |val|
101
- coerce_value val, field_descriptor
97
+ # Assume this is a normal single message, and coerce to the message
98
+ # class.
99
+ coerce val, to: field_descriptor.subtype.msgclass
102
100
  end
103
101
  end
104
102
 
105
- ##
106
- # Hack to determine if field_descriptor is for a map.
107
- #
108
- # TODO(geigerj): Remove this once protobuf Ruby supports an official way
109
- # to determine if a FieldDescriptor represents a map.
110
- # See: https://github.com/google/protobuf/issues/3425
111
- def self.map_field? field_descriptor
112
- (field_descriptor.label == :repeated) &&
113
- (field_descriptor.subtype.name.include? "_MapEntry_")
114
- end
115
-
116
- ##
117
- # Coerces the value of a field to be acceptable by the instantiation method of the wrapping message.
118
- #
119
- # @private
120
- #
121
- # @param val [Object] The value to be coerced.
122
- # @param field_descriptor [Google::Protobuf::FieldDescriptor] The field descriptor of the value.
123
- #
124
- # @return [Object] The coerced version of the given value.
125
- def self.coerce_value val, field_descriptor
126
- return val unless (val.is_a? Hash) && !(map_field? field_descriptor)
127
- coerce val, to: field_descriptor.subtype.msgclass
128
- end
129
-
130
103
  ##
131
104
  # Utility for converting a Google::Protobuf::Timestamp instance to a Ruby time.
132
105
  #
@@ -147,6 +120,6 @@ module Gapic
147
120
  Google::Protobuf::Timestamp.new seconds: time.to_i, nanos: time.nsec
148
121
  end
149
122
 
150
- private_class_method :coerce_submessages, :coerce_submessage, :coerce_array, :coerce_value, :map_field?
123
+ private_class_method :coerce_submessages, :coerce_submessage
151
124
  end
152
125
  end
@@ -14,6 +14,9 @@
14
14
 
15
15
  require "json"
16
16
  require "gapic/common/error"
17
+ require "google/protobuf/well_known_types"
18
+ # Not technically required but GRPC counterpart loads it and so should we for test parity
19
+ require "google/rpc/error_details_pb"
17
20
 
18
21
  module Gapic
19
22
  module Rest
@@ -25,6 +28,8 @@ module Gapic
25
28
  attr_reader :status
26
29
  # @return [Object, nil] the details as parsed from the response body
27
30
  attr_reader :details
31
+ # The Cloud error wrapper expect to see a `status_details` property
32
+ alias status_details details
28
33
  # @return [Object, nil] the headers of the REST error
29
34
  attr_reader :headers
30
35
  # The Cloud error wrapper expect to see a `header` property
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gapic-common
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.17.1
4
+ version: 0.19.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Google API Authors
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-02-09 00:00:00.000000000 Z
11
+ date: 2023-05-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday