gapic-generator 0.6.1 → 0.6.6

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: b063888cabf4893087dcefa274cb8ab5a9469a762fc3dbb34af2e143cb1bcce4
4
- data.tar.gz: 589dc9fdf67d63dc25fe62537783e6305e4441f51b5caa2c94a5b1a161e71ab7
3
+ metadata.gz: 23b2c33b7bbae1c69924aa5c4df7ce43324ba16cee3e581aa353cb4ddf961ec3
4
+ data.tar.gz: ec1125f2cf0614188c1106039c4f562602e3dff6ec574d96d0bca0b5fa904ec2
5
5
  SHA512:
6
- metadata.gz: 07a03fd0adcc1640a37fa334883838aee76c124d2e5380a00d540751b3740e1b0f13d82a981ab35297c095df38620a0895bf4bb7bb5dbf1421c659e71cd92e85
7
- data.tar.gz: 10269fc5c70542e1ae9ee1471eb6365c1669c741aa1ac03dbaf3b652cec2aee14801717589d1c45febc554b280cd8cd178ac19e02b1224b2692d1e98324142f6
6
+ metadata.gz: bbb0b136b92843f0859bd8f65b8cbf3a64e5d1e52af69aec02975fdb99ab584918152ffd00f71dc1dc4e333bb617a0975228e0f269a357c749e06b2e73b07854
7
+ data.tar.gz: 1b5481f342bc4aef038f5c2cf9fd71fb032192e7c644129f9165b59eec30137d8b75c172b679d36d2edf8740af0ee7fbf458c84a55dd180237122c7eba74461d
@@ -1,5 +1,33 @@
1
1
  # Release History for gapic-generator
2
2
 
3
+ ### 0.6.6 / 2020-08-05
4
+
5
+ * Use numeric error codes rather than strings in generated retry configs.
6
+
7
+ ### 0.6.5 / 2020-07-16
8
+
9
+ * Examples in auth, rakefile, and readme should pick a non-common service.
10
+ * Emit a warning if common_services config references a nonexistent service.
11
+
12
+ ### 0.6.4 / 2020-07-13
13
+
14
+ * Fix rubocop warning on a generated multi-path helper if it could take no arguments.
15
+ * Run the rubocop file formatting step without caching.
16
+ * Fix an issue where generating a service with no options would fail.
17
+
18
+ ### 0.6.3 / 2020-06-27
19
+
20
+ * Fixes for generated tests for some cases involving proto maps.
21
+ * Fix a Ruby 2.7 keyword arguments warning in generated tests.
22
+ * Clean up bundler references in gemspecs and Gemfiles.
23
+
24
+ ### 0.6.2 / 2020-06-18
25
+
26
+ * Support for the proto3_optional
27
+ * Fixed an issue where tests for the oneof fields were not generating correctly
28
+ * Removed ruby <2.5 pin for the protobuf dependency since new protobuf supports it again
29
+ * Generated libraries now depend on gapic-common 0.3
30
+
3
31
  ### 0.6.1 / 2020-06-16
4
32
 
5
33
  * Add auto-generated disclaimer to generated tests.
@@ -16,6 +16,7 @@ done
16
16
 
17
17
  mkdir -p /workspace/out/lib
18
18
  exec grpc_tools_ruby_protoc \
19
+ --experimental_allow_proto3_optional=1 \
19
20
  --proto_path=/workspace/common-protos/ --proto_path=/workspace/in/ \
20
21
  --ruby_out=/workspace/out/lib \
21
22
  --grpc_out=/workspace/out/lib \
@@ -29,7 +29,6 @@ Gem::Specification.new do |spec|
29
29
  spec.add_dependency "protobuf", "~> 3.8"
30
30
  spec.add_dependency "rubocop", "~> 0.61"
31
31
 
32
- spec.add_development_dependency "bundler", "~> 2.1"
33
32
  spec.add_development_dependency "minitest", "~> 5.0"
34
33
  spec.add_development_dependency "minitest-focus", "~> 1.0"
35
34
  spec.add_development_dependency "rake", "~> 10.0"
@@ -39,7 +39,7 @@ module Gapic
39
39
  write_file dir, file
40
40
  end
41
41
 
42
- system "rubocop -x #{dir} -o #{dir}/rubocop.out -c #{configuration}"
42
+ system "rubocop --cache false -x #{dir} -o #{dir}/rubocop.out -c #{configuration}"
43
43
 
44
44
  files.each do |file|
45
45
  read_file dir, file
@@ -16,6 +16,6 @@
16
16
 
17
17
  module Gapic
18
18
  module Generator
19
- VERSION = "0.6.1"
19
+ VERSION = "0.6.6"
20
20
  end
21
21
  end
@@ -40,6 +40,31 @@ module Gapic
40
40
  MULTIPLIER_JSON_KEY = "backoffMultiplier"
41
41
  STATUS_CODES_JSON_KEY = "retryableStatusCodes"
42
42
 
43
+ # See https://grpc.github.io/grpc/core/md_doc_statuscodes.html for a
44
+ # list of error codes.
45
+ ERROR_CODE_MAPPING = [
46
+ "OK",
47
+ "CANCELLED",
48
+ "UNKNOWN",
49
+ "INVALID_ARGUMENT",
50
+ "DEADLINE_EXCEEDED",
51
+ "NOT_FOUND",
52
+ "ALREADY_EXISTS",
53
+ "PERMISSION_DENIED",
54
+ "RESOURCE_EXHAUSTED",
55
+ "FAILED_PRECONDITION",
56
+ "ABORTED",
57
+ "OUT_OF_RANGE",
58
+ "UNIMPLEMENTED",
59
+ "INTERNAL",
60
+ "UNAVAILABLE",
61
+ "DATA_LOSS",
62
+ "UNAUTHENTICATED"
63
+ ].freeze
64
+
65
+ ERROR_STRING_MAPPING = ERROR_CODE_MAPPING.each_with_index.each_with_object({}) do |(str, num), hash|
66
+ hash[str] = num
67
+ end.freeze
43
68
 
44
69
  ##
45
70
  # Parses ServiceConfig from a json of a GRPC service config
@@ -146,11 +171,26 @@ module Gapic
146
171
  initial_delay_seconds = parse_interval_seconds get(retry_policy_json, INITIAL_DELAY_JSON_KEY)
147
172
  max_delay_seconds = parse_interval_seconds get(retry_policy_json, MAX_DELAY_JSON_KEY)
148
173
  multiplier = get retry_policy_json, MULTIPLIER_JSON_KEY
149
- status_codes = get retry_policy_json, STATUS_CODES_JSON_KEY
174
+ status_codes = convert_codes get retry_policy_json, STATUS_CODES_JSON_KEY
150
175
 
151
176
  RetryPolicy.new initial_delay_seconds, max_delay_seconds, multiplier, status_codes
152
177
  end
153
178
 
179
+ ##
180
+ # Interpret input status codes. Convert strings to their associated integer codes.
181
+ #
182
+ def self.convert_codes input_codes
183
+ return nil if input_codes.nil?
184
+ Array(input_codes).map do |obj|
185
+ case obj
186
+ when String
187
+ ERROR_STRING_MAPPING[obj]
188
+ when Integer
189
+ obj
190
+ end
191
+ end.compact
192
+ end
193
+
154
194
  ##
155
195
  # Parses time expressed in secondds from the GRPC service config json
156
196
  # The time is encoded is a string as float or integer with a letter 's' afterwards
@@ -212,7 +252,7 @@ module Gapic
212
252
  end
213
253
 
214
254
  private_class_method :parse_service_names, :filter_service_method_names, :parse_config,
215
- :parse_retry_policy, :parse_interval_seconds, :valid_float?
255
+ :parse_retry_policy, :parse_interval_seconds, :valid_float?, :convert_codes
216
256
  end
217
257
  end
218
258
  end
@@ -80,6 +80,10 @@ module Gapic
80
80
  @field.enum?
81
81
  end
82
82
 
83
+ def proto3_optional?
84
+ @field.proto3_optional?
85
+ end
86
+
83
87
  def repeated?
84
88
  @field.repeated?
85
89
  end
@@ -88,6 +92,14 @@ module Gapic
88
92
  @field.map?
89
93
  end
90
94
 
95
+ def oneof?
96
+ @field.oneof?
97
+ end
98
+
99
+ def oneof_name
100
+ @message.oneof_decl[@field.oneof_index].name
101
+ end
102
+
91
103
  protected
92
104
 
93
105
  def field_doc_types field, output
@@ -48,6 +48,10 @@ module Gapic
48
48
  end
49
49
  end
50
50
 
51
+ def first_non_common_service
52
+ services.find { |service| service.common_service_delegate.nil? }
53
+ end
54
+
51
55
  def proto_files
52
56
  @proto_files ||= begin
53
57
  files = @api.files
@@ -174,7 +178,7 @@ module Gapic
174
178
  end
175
179
 
176
180
  def dependencies
177
- deps = { "gapic-common" => "~> 0.2" }
181
+ deps = { "gapic-common" => "~> 0.3" }
178
182
  deps["grpc-google-iam-v1"] = [">= 0.6.10", "< 2.0"] if iam_dependency?
179
183
  extra_deps = gem_config :extra_dependencies
180
184
  deps.merge! extra_deps if extra_deps
@@ -92,6 +92,11 @@ module Gapic
92
92
  have_oneof = []
93
93
 
94
94
  @method.input.fields.each do |field|
95
+ unless field.oneof?
96
+ selected_fields << field
97
+ next
98
+ end
99
+
95
100
  idx = field.oneof_index
96
101
  selected_fields << field unless have_oneof.include? idx
97
102
  have_oneof << idx
@@ -203,7 +203,8 @@ module Gapic
203
203
  def client_scopes
204
204
  common_service_delegate&.client_scopes ||
205
205
  @service.scopes ||
206
- default_config(:oauth_scopes)
206
+ default_config(:oauth_scopes) ||
207
+ []
207
208
  end
208
209
 
209
210
  def credentials_name
@@ -48,8 +48,10 @@ module Gapic
48
48
  output_files = generator.new(api).generate
49
49
 
50
50
  # Create and write the response
51
- Google::Protobuf::Compiler::CodeGeneratorResponse.new \
51
+ response = Google::Protobuf::Compiler::CodeGeneratorResponse.new \
52
52
  file: output_files
53
+ response.supported_features = Google::Protobuf::Compiler::CodeGeneratorResponse::FEATURE_PROTO3_OPTIONAL
54
+ response
53
55
  end
54
56
 
55
57
  # Run protoc generation.
@@ -44,14 +44,18 @@ module Gapic
44
44
  #
45
45
  # @param request [Google::Protobuf::Compiler::CodeGeneratorRequest]
46
46
  # The request object.
47
- def initialize request
47
+ # @param error_output [IO] An IO to write any errors/warnings to.
48
+ # @param configuration [Hash] Optional override of configuration.
49
+ def initialize request, error_output: STDERR, configuration: nil
48
50
  @request = request
49
51
  loader = Loader.new
50
52
  @files = request.proto_file.map do |fd|
51
53
  loader.load_file fd, request.file_to_generate.include?(fd.name)
52
54
  end
53
55
  @files.each { |f| f.parent = self }
56
+ @configuration = configuration
54
57
  @resource_types = analyze_resources
58
+ sanity_checks error_output
55
59
  end
56
60
 
57
61
  def containing_api
@@ -295,6 +299,18 @@ module Gapic
295
299
 
296
300
  private
297
301
 
302
+ # Perform a variety of sanity checks on the data, and prints errors to
303
+ # the given output as appropriate.
304
+ #
305
+ # @param output [IO] Stream to write outputs to.
306
+ def sanity_checks output
307
+ addrs = services.map { |service| service.address.join "." }
308
+ configuration[:common_services]&.each do |k, v|
309
+ output.puts "WARNING: configured common service #{k} is not present" unless addrs.include? k
310
+ output.puts "WARNING: configured common service delegate #{v} is not present" unless addrs.include? v
311
+ end
312
+ end
313
+
298
314
  # Does a pre-analysis of all resources defined in the job. This has
299
315
  # two effects:
300
316
  # * Side effect: each resource has its parent_resources field set.
@@ -655,6 +655,15 @@ module Gapic
655
655
  field_behavior.include? Google::Api::FieldBehavior::OPTIONAL
656
656
  end
657
657
 
658
+ # Denotes a field as a part of oneof.
659
+ # oneof_index is an int field so it'll be 0 by default for every field
660
+ # and an index in the message's oneof table for the oneof fields
661
+ # but since the indexes in the message's oneof table start with 0 as well
662
+ # we need this to determine whether the field is a part of the oneof
663
+ def oneof?
664
+ @descriptor.field? :oneof_index
665
+ end
666
+
658
667
  # Denotes a field as required. This indicates that the field **must** be
659
668
  # provided as part of the request, and failure to do so will cause an
660
669
  # error (usually `INVALID_ARGUMENT`).
@@ -731,7 +740,8 @@ module Gapic
731
740
  :default_value,
732
741
  :oneof_index,
733
742
  :json_name,
734
- :options
743
+ :options,
744
+ :proto3_optional?
735
745
  )
736
746
  end
737
747
 
@@ -1,7 +1,8 @@
1
1
  # encoding: utf-8
2
2
 
3
3
  ##
4
- # This file is auto-generated. DO NOT EDIT!
4
+ # This file was auto-generated initially but now is hand-edited to add support
5
+ # for response features and proto3_optional
5
6
  #
6
7
  require 'protobuf'
7
8
 
@@ -54,6 +55,8 @@ module Google
54
55
  end
55
56
 
56
57
  class CodeGeneratorResponse
58
+ FEATURE_PROTO3_OPTIONAL = 1
59
+
57
60
  class File
58
61
  optional :string, :name, 1
59
62
  optional :string, :insertion_point, 2
@@ -61,6 +64,7 @@ module Google
61
64
  end
62
65
 
63
66
  optional :string, :error, 1
67
+ optional :int32, :supported_features, 2
64
68
  repeated ::Google::Protobuf::Compiler::CodeGeneratorResponse::File, :file, 15
65
69
  end
66
70
 
@@ -190,6 +190,7 @@ module Google
190
190
  optional :int32, :oneof_index, 9
191
191
  optional :string, :json_name, 10
192
192
  optional ::Google::Protobuf::FieldOptions, :options, 8
193
+ optional :bool, :proto3_optional, 17
193
194
  end
194
195
 
195
196
  class OneofDescriptorProto
@@ -2,6 +2,3 @@
2
2
  source "https://rubygems.org"
3
3
 
4
4
  gemspec
5
-
6
- # google-protobuf 3.12.0 requires Ruby 2.5 or later, so pin to 3.11 on older Rubies
7
- gem "google-protobuf", (RUBY_VERSION < "2.5" ? "~> 3.11.4" : "~> 3.12")
@@ -16,7 +16,7 @@ $ gem install <%= gem.name %>
16
16
 
17
17
  ```ruby
18
18
  require "<%= gem.entrypoint_require %>"
19
- <%- service = gem.packages.first&.services.first -%>
19
+ <%- service = gem.first_non_common_service -%>
20
20
  <%- method = service&.methods.first -%>
21
21
  <%- if service && method -%>
22
22
 
@@ -13,7 +13,11 @@ def <%= resource.path_helper %> **args
13
13
  <%- last_pattern_index = resource.patterns.count - 1 -%>
14
14
  <%- resource.patterns.each_with_index do |pattern, index| -%>
15
15
  <%- comma = last_pattern_index == index ? "" : "," -%>
16
+ <%- if pattern.formal_arguments.empty? -%>
17
+ <%= pattern.arguments_key.inspect %> => (proc do
18
+ <%- else -%>
16
19
  <%= pattern.arguments_key.inspect %> => (proc do |<%= pattern.formal_arguments %>|
20
+ <%- end -%>
17
21
  <%= indent render(partial: "service/client/resource/def", locals: { pattern: pattern }), 6 %>
18
22
  end)<%= comma %>
19
23
  <%- end -%>
@@ -86,13 +86,21 @@ def test_<%= method.name %>
86
86
  request.to_a.each do |r|
87
87
  assert_kind_of <%= method.request_type %>, r
88
88
  <%- fields.each do |field| -%>
89
- <%- if field.message? && field.repeated? -%>
90
- assert_kind_of <%= field.type_name_full %>, request.<%= field.name %>.first
89
+ <%- if field.message? && field.repeated? && !field.map? -%>
90
+ assert_kind_of <%= field.type_name_full %>, r.<%= field.name %>.first
91
+ <%- elsif field.map? -%>
92
+ assert_equal(<%= field.default_value %>, r.<%= field.name %>.to_h)
91
93
  <%- elsif field.message? -%>
92
94
  assert_equal Gapic::Protobuf.coerce(<%= field.default_value %>, to: <%= field.type_name_full %>), r.<%= field.name %>
93
95
  <%- else -%>
94
96
  assert_equal <%= field.default_value %>, r.<%= field.name %>
95
97
  <%- end -%>
98
+ <%- if field.oneof? && !field.proto3_optional? -%>
99
+ assert_equal :<%= field.name %>, r.<%= field.oneof_name %>
100
+ <%- end -%>
101
+ <%- if field.proto3_optional? -%>
102
+ assert r.has_<%= field.name %>?
103
+ <%- end -%>
96
104
  <%- end -%>
97
105
  end
98
106
  end
@@ -70,13 +70,21 @@ def test_<%= method.name %>
70
70
  request.to_a.each do |r|
71
71
  assert_kind_of <%= method.request_type %>, r
72
72
  <%- fields.each do |field| -%>
73
- <%- if field.message? && field.repeated? -%>
74
- assert_kind_of <%= field.type_name_full %>, request.<%= field.name %>.first
73
+ <%- if field.message? && field.repeated? && !field.map? -%>
74
+ assert_kind_of <%= field.type_name_full %>, r.<%= field.name %>.first
75
+ <%- elsif field.map? -%>
76
+ assert_equal(<%= field.default_value %>, r.<%= field.name %>.to_h)
75
77
  <%- elsif field.message? -%>
76
78
  assert_equal Gapic::Protobuf.coerce(<%= field.default_value %>, to: <%= field.type_name_full %>), r.<%= field.name %>
77
79
  <%- else -%>
78
80
  assert_equal <%= field.default_value %>, r.<%= field.name %>
79
81
  <%- end -%>
82
+ <%- if field.oneof? && !field.proto3_optional? -%>
83
+ assert_equal :<%= field.name %>, r.<%= field.oneof_name %>
84
+ <%- end -%>
85
+ <%- if field.proto3_optional? -%>
86
+ assert r.has_<%= field.name %>?
87
+ <%- end -%>
80
88
  <%- end -%>
81
89
  end
82
90
  end
@@ -26,6 +26,12 @@ def test_<%= method.name %>
26
26
  <%- else -%>
27
27
  assert_equal <%= field.default_value %>, request.<%= field.name %>
28
28
  <%- end -%>
29
+ <%- if field.oneof? && !field.proto3_optional? -%>
30
+ assert_equal :<%= field.name %>, request.<%= field.oneof_name %>
31
+ <%- end -%>
32
+ <%- if field.proto3_optional? -%>
33
+ assert request.has_<%= field.name %>?
34
+ <%- end -%>
29
35
  <%- end -%>
30
36
  refute_nil options
31
37
  end
@@ -17,13 +17,21 @@ def test_<%= method.name %>
17
17
  assert_equal :<%= method.name %>, name
18
18
  assert_kind_of <%= method.request_type %>, request
19
19
  <%- fields.each do |field| -%>
20
- <%- if field.message? && field.repeated? -%>
20
+ <%- if field.message? && field.repeated? && !field.map? -%>
21
21
  assert_kind_of <%= field.type_name_full %>, request.<%= field.name %>.first
22
+ <%- elsif field.map? -%>
23
+ assert_equal(<%= field.default_value %>, request.<%= field.name %>.to_h)
22
24
  <%- elsif field.message? -%>
23
25
  assert_equal Gapic::Protobuf.coerce(<%= field.default_value %>, to: <%= field.type_name_full %>), request.<%= field.name %>
24
26
  <%- else -%>
25
27
  assert_equal <%= field.default_value %>, request.<%= field.name %>
26
28
  <%- end -%>
29
+ <%- if field.oneof? && !field.proto3_optional? -%>
30
+ assert_equal :<%= field.name %>, request.<%= field.oneof_name %>
31
+ <%- end -%>
32
+ <%- if field.proto3_optional? -%>
33
+ assert request.has_<%= field.name %>?
34
+ <%- end -%>
27
35
  <%- end -%>
28
36
  refute_nil options
29
37
  end
@@ -9,10 +9,10 @@ class ClientStub
9
9
  @requests = []
10
10
  end
11
11
 
12
- def call_rpc *args
12
+ def call_rpc *args, **kwargs
13
13
  @call_rpc_count += 1
14
14
 
15
- @requests << @block&.call(*args)
15
+ @requests << @block&.call(*args, **kwargs)
16
16
 
17
17
  yield @response, @operation if block_given?
18
18
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gapic-generator
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.1
4
+ version: 0.6.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ernest Landrito
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2020-06-18 00:00:00.000000000 Z
13
+ date: 2020-08-05 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: actionpack
@@ -40,20 +40,6 @@ dependencies:
40
40
  - - "~>"
41
41
  - !ruby/object:Gem::Version
42
42
  version: '3.8'
43
- - !ruby/object:Gem::Dependency
44
- name: bundler
45
- requirement: !ruby/object:Gem::Requirement
46
- requirements:
47
- - - "~>"
48
- - !ruby/object:Gem::Version
49
- version: '2.1'
50
- type: :development
51
- prerelease: false
52
- version_requirements: !ruby/object:Gem::Requirement
53
- requirements:
54
- - - "~>"
55
- - !ruby/object:Gem::Version
56
- version: '2.1'
57
43
  - !ruby/object:Gem::Dependency
58
44
  name: google-style
59
45
  requirement: !ruby/object:Gem::Requirement
@@ -74,14 +60,14 @@ dependencies:
74
60
  requirements:
75
61
  - - "~>"
76
62
  - !ruby/object:Gem::Version
77
- version: '1.19'
63
+ version: 1.30.1
78
64
  type: :development
79
65
  prerelease: false
80
66
  version_requirements: !ruby/object:Gem::Requirement
81
67
  requirements:
82
68
  - - "~>"
83
69
  - !ruby/object:Gem::Version
84
- version: '1.19'
70
+ version: 1.30.1
85
71
  - !ruby/object:Gem::Dependency
86
72
  name: minitest
87
73
  requirement: !ruby/object:Gem::Requirement