gapic-generator 0.5.1 → 0.6.4

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.
Files changed (42) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +32 -0
  3. data/gem_templates/dockerfile.erb +1 -1
  4. data/gem_templates/entrypoint.erb +1 -0
  5. data/gem_templates/gemspec.erb +0 -1
  6. data/lib/gapic/file_formatter.rb +1 -2
  7. data/lib/gapic/generator/version.rb +1 -1
  8. data/lib/gapic/generators/default_generator.rb +3 -3
  9. data/lib/gapic/{path_template.rb → path_pattern.rb} +9 -8
  10. data/lib/gapic/path_pattern/parser.rb +146 -0
  11. data/lib/gapic/path_pattern/pattern.rb +80 -0
  12. data/lib/gapic/path_pattern/segment.rb +276 -0
  13. data/lib/gapic/presenters/field_presenter.rb +12 -0
  14. data/lib/gapic/presenters/gem_presenter.rb +39 -3
  15. data/lib/gapic/presenters/method_presenter.rb +10 -5
  16. data/lib/gapic/presenters/package_presenter.rb +4 -3
  17. data/lib/gapic/presenters/resource_presenter.rb +23 -31
  18. data/lib/gapic/presenters/service_presenter.rb +14 -7
  19. data/lib/gapic/runner.rb +3 -1
  20. data/lib/gapic/schema/wrappers.rb +24 -20
  21. data/lib/gapic/uri_template.rb +36 -0
  22. data/lib/gapic/uri_template/parser.rb +50 -0
  23. data/lib/google/protobuf/compiler/plugin.pb.rb +5 -1
  24. data/lib/google/protobuf/descriptor.pb.rb +1 -0
  25. data/templates/default/gem/gemfile.erb +0 -3
  26. data/templates/default/gem/gemspec.erb +4 -5
  27. data/templates/default/lib/_service.erb +2 -0
  28. data/templates/default/service/client/_client.erb +2 -0
  29. data/templates/default/service/client/_config.erb +1 -1
  30. data/templates/default/service/client/resource/_doc.erb +1 -1
  31. data/templates/default/service/client/resource/_multi.erb +4 -0
  32. data/templates/default/service/test/client.erb +1 -3
  33. data/templates/default/service/test/client_operations.erb +1 -3
  34. data/templates/default/service/test/client_paths.erb +1 -3
  35. data/templates/default/service/test/method/_bidi.erb +10 -2
  36. data/templates/default/service/test/method/_client.erb +10 -2
  37. data/templates/default/service/test/method/_normal.erb +6 -0
  38. data/templates/default/service/test/method/_server.erb +9 -1
  39. data/templates/default/service/test/method/_setup.erb +2 -2
  40. metadata +10 -21
  41. data/lib/gapic/path_template/parser.rb +0 -83
  42. data/lib/gapic/path_template/segment.rb +0 -74
@@ -0,0 +1,50 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Copyright 2020 Google LLC
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # https://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
16
+
17
+ module Gapic
18
+ module UriTemplate
19
+ # A URI template parser.
20
+ # see https://tools.ietf.org/html/rfc6570 URI Template
21
+ #
22
+ # @!attribute [r] path_pattern
23
+ # @return [String] The path pattern to be parsed.
24
+ # @!attribute [r] segments
25
+ # @return [Array<Segment|String>] The segments of the parsed path pattern.
26
+ module Parser
27
+ # @private
28
+ # /((?<positional>\*\*?)|{(?<name>[^\/]+?)(?:=(?<template>.+?))?})/
29
+ URI_TEMPLATE = %r{
30
+ (
31
+ (?<positional>\*\*?)
32
+ |
33
+ {(?<name>[^\/]+?)(?:=(?<template>.+?))?}
34
+ )
35
+ }x.freeze
36
+
37
+ def self.parse_arguments uri_template
38
+ arguments = []
39
+
40
+ while (match = URI_TEMPLATE.match uri_template)
41
+ # The String before the match needs to be added to the segments
42
+ arguments << match[:name] if match[:name]
43
+ uri_template = match.post_match
44
+ end
45
+
46
+ arguments
47
+ end
48
+ end
49
+ end
50
+ end
@@ -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")
@@ -12,20 +12,19 @@ Gem::Specification.new do |gem|
12
12
  gem.description = <%= gem.description.inspect %>
13
13
  gem.summary = <%= gem.summary.inspect %>
14
14
  gem.homepage = <%= gem.homepage.inspect %>
15
- gem.license = "MIT"
15
+ gem.license = <%= gem.license_name.inspect %>
16
16
 
17
17
  gem.platform = Gem::Platform::RUBY
18
18
 
19
19
  gem.files = `git ls-files -- lib/*`.split("\n") +
20
20
  `git ls-files -- proto_docs/*`.split("\n") +
21
- ["README.md", "LICENSE.md", ".yardopts"]
21
+ <%= gem.extra_files.inspect %>
22
22
  gem.require_paths = ["lib"]
23
23
 
24
24
  gem.required_ruby_version = ">= 2.4"
25
25
 
26
- gem.add_dependency "gapic-common", "~> 0.2"
27
- <%- if gem.iam_dependency? -%>
28
- gem.add_dependency "grpc-google-iam-v1", ">= 0.6.10", "< 2.0"
26
+ <%- gem.dependency_list.each do |name, requirements| -%>
27
+ gem.add_dependency <%= name.inspect %>, <%= requirements.map { |v| v.inspect }.join ", " %>
29
28
  <%- end -%>
30
29
 
31
30
  gem.add_development_dependency "google-style", "~> 1.24.0"
@@ -6,7 +6,9 @@ require "gapic/config/method"
6
6
 
7
7
  require "<%= service.gem.version_require %>"
8
8
 
9
+ <%- unless service.generic_endpoint? -%>
9
10
  require "<%= service.credentials_require %>"
11
+ <%- end -%>
10
12
  <%- if service.paths? -%>
11
13
  require "<%= service.paths_require %>"
12
14
  <%- end -%>
@@ -96,10 +96,12 @@ class <%= service.client_name %>
96
96
 
97
97
  # Create credentials
98
98
  credentials = @config.credentials
99
+ <%- unless service.generic_endpoint? -%>
99
100
  credentials ||= Credentials.default scope: @config.scope
100
101
  if credentials.is_a?(String) || credentials.is_a?(Hash)
101
102
  credentials = Credentials.new credentials, scope: @config.scope
102
103
  end
104
+ <%- end -%>
103
105
  @quota_project_id = @config.quota_project
104
106
  @quota_project_id ||= credentials.quota_project_id if credentials.respond_to? :quota_project_id
105
107
 
@@ -115,7 +115,7 @@ class Configuration
115
115
  def rpcs
116
116
  @rpcs ||= begin
117
117
  parent_rpcs = nil
118
- parent_rpcs = @parent_config.rpcs if @parent_config&.respond_to? :rpcs
118
+ parent_rpcs = @parent_config.rpcs if defined?(@parent_config) && @parent_config&.respond_to?(:rpcs)
119
119
  Rpcs.new parent_rpcs
120
120
  end
121
121
  end
@@ -1,7 +1,7 @@
1
1
  <%- assert_locals pattern -%>
2
2
  The resource will be in the following format:
3
3
 
4
- `<%= pattern.template %>`
4
+ `<%= pattern.pattern %>`
5
5
 
6
6
  <%- pattern.arguments.each do |arg| -%>
7
7
  @param <%= arg %> [String]
@@ -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 -%>
@@ -1,7 +1,5 @@
1
1
  <%- assert_locals service -%>
2
- # frozen_string_literal: true
3
-
4
- <%= render partial: "shared/license" %>
2
+ <%= render partial: "shared/header" %>
5
3
  require "helper"
6
4
 
7
5
  require "gapic/grpc/service_stub"
@@ -1,7 +1,5 @@
1
1
  <%- assert_locals service -%>
2
- # frozen_string_literal: true
3
-
4
- <%= render partial: "shared/license" %>
2
+ <%= render partial: "shared/header" %>
5
3
  require "helper"
6
4
 
7
5
  require "gapic/grpc/service_stub"
@@ -1,7 +1,5 @@
1
1
  <%- assert_locals service -%>
2
- # frozen_string_literal: true
3
-
4
- <%= render partial: "shared/license" %>
2
+ <%= render partial: "shared/header" %>
5
3
  require "helper"
6
4
 
7
5
  require "gapic/grpc/service_stub"
@@ -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.5.1
4
+ version: 0.6.4
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-05-25 00:00:00.000000000 Z
13
+ date: 2020-07-13 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
@@ -217,9 +203,10 @@ files:
217
203
  - lib/gapic/grpc_service_config/service_config.rb
218
204
  - lib/gapic/helpers/filepath_helper.rb
219
205
  - lib/gapic/helpers/namespace_helper.rb
220
- - lib/gapic/path_template.rb
221
- - lib/gapic/path_template/parser.rb
222
- - lib/gapic/path_template/segment.rb
206
+ - lib/gapic/path_pattern.rb
207
+ - lib/gapic/path_pattern/parser.rb
208
+ - lib/gapic/path_pattern/pattern.rb
209
+ - lib/gapic/path_pattern/segment.rb
223
210
  - lib/gapic/presenters.rb
224
211
  - lib/gapic/presenters/enum_presenter.rb
225
212
  - lib/gapic/presenters/enum_value_presenter.rb
@@ -239,6 +226,8 @@ files:
239
226
  - lib/gapic/schema/api.rb
240
227
  - lib/gapic/schema/loader.rb
241
228
  - lib/gapic/schema/wrappers.rb
229
+ - lib/gapic/uri_template.rb
230
+ - lib/gapic/uri_template/parser.rb
242
231
  - lib/google/api/annotations.pb.rb
243
232
  - lib/google/api/client.pb.rb
244
233
  - lib/google/api/field_behavior.pb.rb
@@ -1,83 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- # Copyright 2019 Google LLC
4
- #
5
- # Licensed under the Apache License, Version 2.0 (the "License");
6
- # you may not use this file except in compliance with the License.
7
- # You may obtain a copy of the License at
8
- #
9
- # https://www.apache.org/licenses/LICENSE-2.0
10
- #
11
- # Unless required by applicable law or agreed to in writing, software
12
- # distributed under the License is distributed on an "AS IS" BASIS,
13
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
- # See the License for the specific language governing permissions and
15
- # limitations under the License.
16
-
17
- require "gapic/path_template/segment"
18
-
19
- module Gapic
20
- module PathTemplate
21
- # A URI path template parser.
22
- #
23
- # @see https://tools.ietf.org/html/rfc6570 URI Template
24
- #
25
- # @!attribute [r] path_template
26
- # @return [String] The URI path template to be parsed.
27
- # @!attribute [r] segments
28
- # @return [Array<Segment|String>] The segments of the parsed URI path
29
- # template.
30
- class Parser
31
- # @private
32
- # /((?<positional>\*\*?)|{(?<name>[^\/]+?)(?:=(?<template>.+?))?})/
33
- PATH_TEMPLATE = %r{
34
- (
35
- (?<positional>\*\*?)
36
- |
37
- {(?<name>[^\/]+?)(?:=(?<template>.+?))?}
38
- )
39
- }x.freeze
40
-
41
- attr_reader :path_template, :segments
42
-
43
- # Create a new URI path template parser.
44
- #
45
- # @param path_template [String] The URI path template to be parsed.
46
- def initialize path_template
47
- @path_template = path_template
48
- @segments = parse! path_template
49
- end
50
-
51
- protected
52
-
53
- def parse! path_template
54
- # segments contain either Strings or segment objects
55
- segments = []
56
- segment_pos = 0
57
-
58
- while (match = PATH_TEMPLATE.match path_template)
59
- # The String before the match needs to be added to the segments
60
- segments << match.pre_match unless match.pre_match.empty?
61
-
62
- segment, segment_pos = segment_and_pos_from_match match, segment_pos
63
- segments << segment
64
-
65
- path_template = match.post_match
66
- end
67
-
68
- # Whatever String is unmatched needs to be added to the segments
69
- segments << path_template unless path_template.empty?
70
-
71
- segments
72
- end
73
-
74
- def segment_and_pos_from_match match, pos
75
- if match[:positional]
76
- [Segment.new(pos, match[:positional]), pos + 1]
77
- else
78
- [Segment.new(match[:name], match[:template]), pos]
79
- end
80
- end
81
- end
82
- end
83
- end