gapic-generator 0.7.5 → 0.8.0

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: cbb07888e227a0e891359dd684e8ead50be011593929d56a929a9b1e226a8257
4
- data.tar.gz: 1ef99fe476ca10728df3997f3a01a87e12cf3f681ecb7f1c07e17facbd3ecd7a
3
+ metadata.gz: 5c8a401f416529802324b86833c5c3a9fcef01afd699439053ce868a7862c5c8
4
+ data.tar.gz: 6f794cc05eb33a4c201bdcc62dc62524406ae2fb003f0b2d9c536482517a4109
5
5
  SHA512:
6
- metadata.gz: 535fa4c595fc7c3074c9d554303f275039e8952a908f2b9295b62625f14173ed979e684fb11ed33b7dfbce751001cdb4aaa25e2d9f752252af258336a8ca45c3
7
- data.tar.gz: d36e8866f75c418520142c1b883214540b40261b06e2386ea822fef42de79ebbde38368f21b2bcf726871f64bb12b1e4b4bf8be70d043e44e026f8c41f8ccf23
6
+ metadata.gz: 536731d9a866b0c58540b6eb6f62469eef75f10f82a9fba3c45e0e5a2c5d08b7f5b97b0b385b3e6063e418e0faba687faf45c44cc700ab69da554c9d28a46049
7
+ data.tar.gz: c1b99ad4ebfae8c4085522924ba4fd11f1a2628b67d64dfc549f22df40aadf5d79ae127bcac73ca5fe2795937f29556b6f656d5b86c66aaef43c78ec644b6772
data/CHANGELOG.md CHANGED
@@ -1,5 +1,18 @@
1
1
  # Release History for gapic-generator
2
2
 
3
+ ### 0.8.0 / 2021-06-16
4
+
5
+ * Initial implementation of standalone snippet generation.
6
+ * Updated gapic-common dependencies to require at least 0.5 and to support future 1.x versions.
7
+ * Generated unit tests for REST clients.
8
+ * Generated proper x-goog-api-client headers for REST clients.
9
+ * Added generation arguments to generated repo metadata.
10
+ * Allow multiple versions in the extra-dependency command line argument.
11
+ * Fixed treatment of boolean-valued command line arguments to the generator.
12
+ * Fixed behavior of wrapper-gem-override if given an empty value.
13
+ * Fixed default env_prefix computation to avoid the version part of the proto namespace.
14
+ * Fixed Bazel front-end to preserve file permissions.
15
+
3
16
  ### 0.7.5 / 2021-05-18
4
17
 
5
18
  * Bazel jobs now provide a prebuilt ruby binary.
@@ -16,6 +16,6 @@
16
16
 
17
17
  module Gapic
18
18
  module Generator
19
- VERSION = "0.7.5"
19
+ VERSION = "0.8.0"
20
20
  end
21
21
  end
@@ -61,9 +61,17 @@ module Gapic
61
61
  files << g("service/operations.erb", "lib/#{service.operations_file_path}", service: service) if service.lro? && !@api.generate_rest_clients?
62
62
  files << g("service/rest/client.erb", "lib/#{service.rest.client_file_path}", service: service) if @api.generate_rest_clients? and service.methods_rest_bindings?
63
63
  files << g("service/rest/grpc_transcoding.erb", "lib/#{service.rest.transcoding_helper_file_path}", service: service) if @api.generate_rest_clients? and service.methods_rest_bindings?
64
+ files << g("service/rest/test/client.erb", "test/#{service.rest.test_client_file_path}", service: service) if @api.generate_rest_clients? and service.methods_rest_bindings?
64
65
  files << g("service/test/client.erb", "test/#{service.test_client_file_path}", service: service) unless @api.generate_rest_clients?
65
66
  files << g("service/test/client_paths.erb", "test/#{service.test_paths_file_path}", service: service) if service.paths?
66
67
  files << g("service/test/client_operations.erb", "test/#{service.test_client_operations_file_path}", service: service) if service.lro? && !@api.generate_rest_clients?
68
+
69
+ if @api.generate_standalone_snippets?
70
+ service.methods.each do |method|
71
+ snippet = method.snippet
72
+ files << g("snippets/standalone.erb", "snippets/#{snippet.snippet_file_path}", snippet: snippet)
73
+ end
74
+ end
67
75
  end
68
76
  end
69
77
 
@@ -82,6 +90,8 @@ module Gapic
82
90
  files << g("gem/entrypoint.erb", "lib/#{gem.name}.rb", gem: gem)
83
91
  files << g("gem/gapic_metadata_json.erb", "gapic_metadata.json", gem: gem) if @api.generate_metadata
84
92
 
93
+ files << g("snippets/gemfile.erb", "snippets/Gemfile", gem: gem) if @api.generate_standalone_snippets?
94
+
85
95
  gem.proto_files.each do |proto_file|
86
96
  files << g("proto_docs/proto_file.erb", "proto_docs/#{proto_file.docs_file_path}", file: proto_file)
87
97
  end
@@ -27,6 +27,7 @@ require "gapic/presenters/resource_presenter"
27
27
  require "gapic/presenters/sample_presenter"
28
28
  require "gapic/presenters/service_presenter"
29
29
  require "gapic/presenters/service_rest_presenter"
30
+ require "gapic/presenters/snippet_presenter"
30
31
 
31
32
  module Gapic
32
33
  ##
@@ -127,7 +127,11 @@ module Gapic
127
127
  end
128
128
 
129
129
  def env_prefix
130
- (gem_config(:env_prefix) || name.split("-").last).upcase
130
+ prefix = gem_config(:env_prefix) || begin
131
+ segs = name.split("-").reverse
132
+ segs.find { |seg| seg !~ /^v\d/ } || segs.first || "UNKNOWN"
133
+ end
134
+ prefix.upcase
131
135
  end
132
136
 
133
137
  def iam_dependency?
@@ -156,18 +160,26 @@ module Gapic
156
160
  gem_config :issue_tracker_url
157
161
  end
158
162
 
163
+ ##
164
+ # @return [Boolean]
165
+ #
159
166
  def free_tier?
160
- # Default to false unless the config is explicitly set to "true"
161
- gem_config(:free_tier) == "true"
167
+ gem_config(:free_tier) || false
162
168
  end
163
169
 
170
+ ##
171
+ # @return [Boolean]
172
+ #
164
173
  def yard_strict?
165
174
  # Default to true unless the config is explicitly set to "false"
166
- gem_config(:yard_strict) != "false"
175
+ gem_config(:yard_strict).nil? || gem_config(:yard_strict)
167
176
  end
168
177
 
178
+ ##
179
+ # @return [Boolean]
180
+ #
169
181
  def generic_endpoint?
170
- gem_config(:generic_endpoint) == "true"
182
+ gem_config(:generic_endpoint) || false
171
183
  end
172
184
 
173
185
  def entrypoint_require
@@ -183,11 +195,13 @@ module Gapic
183
195
  end
184
196
 
185
197
  def dependencies
186
- deps = { "gapic-common" => "~> 0.4" }
187
- deps["grpc-google-iam-v1"] = [">= 0.6.10", "< 2.0"] if iam_dependency?
188
- extra_deps = gem_config :extra_dependencies
189
- deps.merge! extra_deps if extra_deps
190
- deps
198
+ @dependencies ||= begin
199
+ deps = { "gapic-common" => [">= 0.5", "< 2.a"] }
200
+ deps["grpc-google-iam-v1"] = [">= 0.6.10", "< 2.a"] if iam_dependency?
201
+ extra_deps = gem_config_dependencies
202
+ deps.merge! extra_deps if extra_deps
203
+ deps
204
+ end
191
205
  end
192
206
 
193
207
  def dependency_list
@@ -225,6 +239,26 @@ module Gapic
225
239
  @api.configuration[:gem][key]
226
240
  end
227
241
 
242
+ ##
243
+ # There is a special case (from PoV of generator parameters)
244
+ # in gem dependencies where a dependency needs to be an array of strings
245
+ # e.g. ">= 1.6", "< 2.a"
246
+ # Rather than creating a special generator param case for this I will special-case it here.
247
+ # '|' is the separator.
248
+ # The above would be represented as ">= 1.6|< 2.a"
249
+ #
250
+ # @return [Hash<String, String>, Hash{String=>Array<String>}, nil]
251
+ def gem_config_dependencies
252
+ return unless gem_config :extra_dependencies
253
+ gem_config(:extra_dependencies).map do |dep_name, dep_versions|
254
+ if dep_versions.include? "|"
255
+ [dep_name, dep_versions.split("|")]
256
+ else
257
+ [dep_name, dep_versions]
258
+ end
259
+ end.to_h
260
+ end
261
+
228
262
  def blacklist_protos
229
263
  blacklist = gem_config :blacklist
230
264
 
@@ -50,6 +50,10 @@ module Gapic
50
50
  @service_presenter
51
51
  end
52
52
 
53
+ def snippet
54
+ SnippetPresenter.new self, @api
55
+ end
56
+
53
57
  def name
54
58
  @name ||= begin
55
59
  candidate = ActiveSupport::Inflector.underscore @method.name
@@ -128,6 +128,13 @@ module Gapic
128
128
  @proto_method.http&.body || ""
129
129
  end
130
130
 
131
+ ##
132
+ # @return [Boolean] True if body contains full request object (`*` in the annotation), false otherwise
133
+ #
134
+ def body_is_request_object?
135
+ body == "*"
136
+ end
137
+
131
138
  ##
132
139
  # Performs a limited version of grpc transcoding to create a string that will interpolate
133
140
  # the values from the request object to create a request body at runtime.
@@ -142,7 +149,7 @@ module Gapic
142
149
  def body_interpolated request_obj_name = "request_pb"
143
150
  return "\"\"" unless body?
144
151
 
145
- return "#{request_obj_name}.to_json" if body == "*"
152
+ return "#{request_obj_name}.to_json" if body_is_request_object?
146
153
 
147
154
  "#{request_obj_name}.#{body}.to_json"
148
155
  end
@@ -156,11 +163,12 @@ module Gapic
156
163
 
157
164
  # @return [Array<String>]
158
165
  def query_string_params
159
- return [] if body?
166
+ return [] if body_is_request_object?
160
167
 
161
168
  routing_params_set = routing_params.to_set
162
169
  @main_method.arguments
163
170
  .reject { |arg| routing_params_set.include? arg.name }
171
+ .reject { |arg| body == arg.name }
164
172
  .reject(&:message?)
165
173
  .reject { |arg| arg.default_value_for_type.nil? }
166
174
  end
@@ -71,36 +71,11 @@ module Gapic
71
71
  "#{client_require}.rb"
72
72
  end
73
73
 
74
- def create_client_call
75
- "#{client_name_full}.new"
76
- end
77
-
78
- ##
79
- # @return [String]
80
- #
81
- def service_stub_name
82
- "ServiceStub"
83
- end
84
-
85
- ##
86
- # @return [String]
87
- #
88
- def service_stub_name_full
89
- fix_namespace api, "#{service_name_full}::#{service_stub_name}"
90
- end
91
-
92
74
  ##
93
75
  # @return [String]
94
76
  #
95
- def service_stub_require
96
- ruby_file_path api, service_stub_name_full
97
- end
98
-
99
- ##
100
- # @return [String]
101
- #
102
- def service_stub_file_path
103
- "#{service_stub_require}.rb"
77
+ def create_client_call
78
+ "#{client_name_full}.new"
104
79
  end
105
80
 
106
81
  ##
@@ -145,6 +120,13 @@ module Gapic
145
120
  "#{transcoding_helper_require}.rb"
146
121
  end
147
122
 
123
+ ##
124
+ # @return [String]
125
+ #
126
+ def test_client_file_path
127
+ main_service.service_file_path.sub ".rb", "_test.rb"
128
+ end
129
+
148
130
 
149
131
  private
150
132
 
@@ -0,0 +1,103 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Copyright 2021 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 "active_support/inflector"
18
+
19
+ module Gapic
20
+ module Presenters
21
+ ##
22
+ # A presenter for snippets.
23
+ #
24
+ class SnippetPresenter
25
+ def initialize method_presenter, api
26
+ @method_presenter = method_presenter
27
+ @api = api
28
+ end
29
+
30
+ def client_streaming?
31
+ @method_presenter.client_streaming?
32
+ end
33
+
34
+ def bidi_streaming?
35
+ @method_presenter.client_streaming? && @method_presenter.server_streaming?
36
+ end
37
+
38
+ def response_kind
39
+ if @method_presenter.server_streaming?
40
+ :streaming
41
+ elsif @method_presenter.paged?
42
+ :paged
43
+ elsif @method_presenter.lro?
44
+ :lro
45
+ else
46
+ :simple
47
+ end
48
+ end
49
+
50
+ def snippet_file_path
51
+ "#{@method_presenter.service.service_require.split('/').last}/#{@method_presenter.name}.rb"
52
+ end
53
+
54
+ def require_path
55
+ @method_presenter.service.service_require
56
+ end
57
+
58
+ def client_type
59
+ @method_presenter.service.client_name_full.sub(/^::/, "")
60
+ end
61
+
62
+ def request_type
63
+ @method_presenter.request_type.sub(/^::/, "")
64
+ end
65
+
66
+ def return_type
67
+ base_type = @method_presenter.return_type.sub(/^::/, "")
68
+ @method_presenter.server_streaming? ? "Enumerable<#{base_type}>" : base_type
69
+ end
70
+
71
+ def paged_response_type
72
+ @method_presenter.paged_response_type
73
+ end
74
+
75
+ def base_response_type
76
+ @method_presenter.return_type
77
+ end
78
+
79
+ # TODO: Determine type of LRO response
80
+
81
+ def method_name
82
+ @method_presenter.name
83
+ end
84
+
85
+ def region_tag
86
+ gem_presenter = @method_presenter.service.gem
87
+ api_id = gem_presenter.api_shortname || gem_presenter.api_id&.split(".")&.first
88
+ names = gem_presenter.name.split "-"
89
+ final_name = names.pop
90
+ if final_name =~ /^v\d/
91
+ api_version = final_name
92
+ api_id ||= names.last
93
+ else
94
+ api_id ||= final_name
95
+ api_version = "v0"
96
+ end
97
+ service_name = @method_presenter.service.module_name
98
+ method_name = @method_presenter.method.name
99
+ "#{api_id}_#{api_version}_generated_#{service_name}_#{method_name}_sync"
100
+ end
101
+ end
102
+ end
103
+ end
@@ -89,6 +89,10 @@ module Gapic
89
89
  matching_files.first
90
90
  end
91
91
 
92
+ def overrides_of key
93
+ configuration&.fetch(:overrides, nil)&.fetch(key, nil) || {}
94
+ end
95
+
92
96
  def fix_file_path str
93
97
  str = String str
94
98
  return str if configuration[:overrides].nil?
@@ -241,6 +245,11 @@ module Gapic
241
245
  configuration[:transports].include? "grpc"
242
246
  end
243
247
 
248
+ # Whether to generate standalone snippets
249
+ def generate_standalone_snippets?
250
+ configuration[:generate_standalone_snippets] ||= false
251
+ end
252
+
244
253
  # Whether to generate gapic metadata (drift manifest) file
245
254
  # @return [Boolean]
246
255
  def generate_metadata
@@ -317,7 +326,12 @@ module Gapic
317
326
  # @return [String, Nil]
318
327
  def wrapper_gem_name_override
319
328
  return nil unless wrapper_gem_name_override?
320
- configuration[:overrides][:wrapper_gem_name]
329
+ return nil if configuration[:overrides][:wrapper_gem_name].nil?
330
+
331
+ wrapper_name_config = configuration[:overrides][:wrapper_gem_name].strip
332
+ return nil if wrapper_name_config.empty?
333
+
334
+ wrapper_name_config
321
335
  end
322
336
 
323
337
  private
@@ -75,7 +75,7 @@ module Gapic
75
75
  error_output
76
76
  )
77
77
 
78
- if param_value
78
+ unless param_value.nil?
79
79
  RequestParameter.new param_val_input_str, param_name_input_esc, value_str, param_config_name, param_value
80
80
  end
81
81
  end.compact # known bool parameters with invalid values will not be added so we have to compact
@@ -148,7 +148,7 @@ module Gapic
148
148
  when :bool
149
149
  # bools should be either `true` or `false`
150
150
  unesc_val = unescape value_str
151
- unesc_val if ["true", "false"].include? unesc_val
151
+ (unesc_val == "true") if ["true", "false"].include? unesc_val
152
152
  else
153
153
  # if it's an unknown type, just escape it without attempting to parse anything
154
154
  unescape value_str
@@ -8,7 +8,8 @@ call_metadata = {}
8
8
  # Set x-goog-api-client header
9
9
  call_metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \
10
10
  lib_name: @config.lib_name, lib_version: @config.lib_version,
11
- gapic_version: ::<%= method.service.gem.version_name_full %>
11
+ gapic_version: ::<%= method.service.gem.version_name_full %>,
12
+ transports_version_send: [:rest]
12
13
 
13
14
  options.apply_defaults timeout: @config.timeout,
14
15
  metadata: call_metadata
@@ -0,0 +1,18 @@
1
+ <%- assert_locals service -%>
2
+ <%= render partial: "shared/header" %>
3
+ require "helper"
4
+
5
+ require "<%= service.proto_service_require %>"
6
+ require "<%= service.service_require %>"
7
+
8
+
9
+ class <%= service.client_name_full %>Test < Minitest::Test
10
+ <%= indent render(partial: "service/rest/test/method/setup"), 2 %>
11
+
12
+ <% service.methods.each do |method| %>
13
+ <%= indent render(partial: "service/rest/test/method/#{method.kind}",
14
+ locals: { method: method }), 2 %>
15
+
16
+ <% end %>
17
+ <%= indent render(partial: "service/rest/test/method/configure", locals: { service: service }), 2 %>
18
+ end
@@ -0,0 +1,2 @@
1
+ <%- assert_locals method -%>
2
+ assert_equal http_response, response
@@ -0,0 +1,19 @@
1
+ <%- assert_locals service -%>
2
+ <%- full_client_name = defined?(client_name_full) ? client_name_full : service.rest.client_name_full -%>
3
+ def test_configure
4
+ credentials_token = :dummy_value
5
+
6
+ client = block_config = config = nil
7
+ Gapic::Rest::ClientStub.stub :new, nil do
8
+ client = <%= full_client_name =%>.new do |config|
9
+ config.credentials = credentials_token
10
+ end
11
+ end
12
+
13
+ config = client.configure do |c|
14
+ block_config = c
15
+ end
16
+
17
+ assert_same block_config, config
18
+ assert_kind_of <%= full_client_name %>::Configuration, config
19
+ end
@@ -0,0 +1,71 @@
1
+ <%- assert_locals method -%>
2
+ <%- full_client_name = defined?(client_name_full) ? client_name_full : method.service.rest.client_name_full -%>
3
+ <%- fields = method.fields_with_first_oneof -%>
4
+ def test_<%= method.name %>
5
+ # Create test objects.
6
+ client_result = <%= method.return_type %>.new
7
+ http_response = OpenStruct.new body: client_result.to_json
8
+
9
+ call_options = {}
10
+
11
+ # Create request parameters for a unary method.
12
+ <%- fields.each do |field| -%>
13
+ <%= field.name %> = <%= field.default_value %>
14
+ <%- end -%>
15
+
16
+ <%= method.name %>_client_stub = ClientStub.new http_response do |verb, uri:, body:, params:, options:|
17
+ assert_equal :<%= method.rest.verb %>, verb
18
+
19
+ assert options.metadata.key? :"x-goog-api-client"
20
+ assert options.metadata[:"x-goog-api-client"].include? "rest"
21
+ refute options.metadata[:"x-goog-api-client"].include? "grpc"
22
+
23
+ <%- if method.rest.query_string_params? -%>
24
+ <%- method.rest.query_string_params.each do |field| -%>
25
+ assert params.key? "<%= field.camel_name %>"
26
+ <%- end -%>
27
+ <%- end -%>
28
+ <%- if method.rest.body? %>
29
+ refute_nil body
30
+ <%- else -%>
31
+ assert_nil body
32
+ <%- end -%>
33
+ end
34
+
35
+ Gapic::Rest::ClientStub.stub :new, <%= method.name %>_client_stub do
36
+ # Create client
37
+ client = <%= full_client_name %>.new do |config|
38
+ config.credentials = :dummy_value
39
+ end
40
+
41
+ # Use hash object
42
+ client.<%= method.name %>({ <%= fields.map(&:as_kwarg).join ", " %> }) do |result, response|
43
+ <%= indent_tail render(partial: "service/rest/test/method/assert_response", locals: { method: method }), 6 %>
44
+ end
45
+
46
+ <%- if fields.any? -%>
47
+ # Use named arguments
48
+ client.<%= method.name %> <%= fields.map(&:as_kwarg).join ", " %> do |result, response|
49
+ <%= indent_tail render(partial: "service/rest/test/method/assert_response", locals: { method: method }), 6 %>
50
+ end
51
+
52
+ <%- end -%>
53
+ # Use protobuf object
54
+ client.<%= method.name %> <%= method.request_type %>.new(<%= fields.map(&:as_kwarg).join ", " %>) do |result, response|
55
+ <%= indent_tail render(partial: "service/rest/test/method/assert_response", locals: { method: method }), 6 %>
56
+ end
57
+
58
+ # Use hash object with options
59
+ client.<%= method.name %>({ <%= fields.map(&:as_kwarg).join ", " %> }, call_options) do |result, response|
60
+ <%= indent_tail render(partial: "service/rest/test/method/assert_response", locals: { method: method }), 6 %>
61
+ end
62
+
63
+ # Use protobuf object with options
64
+ client.<%= method.name %>(<%= method.request_type %>.new(<%= fields.map(&:as_kwarg).join ", " %>), call_options) do |result, response|
65
+ <%= indent_tail render(partial: "service/rest/test/method/assert_response", locals: { method: method }), 6 %>
66
+ end
67
+
68
+ # Verify method calls
69
+ assert_equal <%= fields.any? ? 5 : 4 %>, <%= method.name %>_client_stub.call_count
70
+ end
71
+ end
@@ -0,0 +1,38 @@
1
+ class ClientStub
2
+ attr_accessor :call_count, :requests
3
+
4
+ def initialize response, &block
5
+ @response = response
6
+ @block = block
7
+ @call_count = 0
8
+ @requests = []
9
+ end
10
+
11
+ def make_get_request uri:, params: {}, options: {}
12
+ make_http_request :get, uri: uri, body: nil, params: params, options: options
13
+ end
14
+
15
+ def make_delete_request uri:, params: {}, options: {}
16
+ make_http_request :delete, uri: uri, body: nil, params: params, options: options
17
+ end
18
+
19
+ def make_post_request uri:, body: nil, params: {}, options: {}
20
+ make_http_request :post, uri: uri, body: body, params: params, options: options
21
+ end
22
+
23
+ def make_patch_request uri:, body:, params: {}, options: {}
24
+ make_http_request :patch, uri: uri, body: body, params: params, options: options
25
+ end
26
+
27
+ def make_put_request uri:, body:, params: {}, options: {}
28
+ make_http_request :put, uri: uri, body: body, params: params, options: options
29
+ end
30
+
31
+ def make_http_request *args, **kwargs
32
+ @call_count += 1
33
+
34
+ @requests << @block&.call(*args, **kwargs)
35
+
36
+ @response
37
+ end
38
+ end
@@ -0,0 +1,17 @@
1
+ <%- assert_locals gem -%>
2
+ <%= render partial: "shared/header" -%>
3
+
4
+ source "https://rubygems.org"
5
+
6
+ if ENV["GOOGLE_CLOUD_SAMPLES_TEST"] == "master"
7
+ gem "<%= gem.name %>", path: "../"
8
+ else
9
+ gem "<%= gem.name %>"
10
+ end
11
+
12
+ group :test do
13
+ gem "google-style", "~> 1.25.1"
14
+ gem "minitest", "~> 5.14"
15
+ gem "minitest-focus", "~> 1.1"
16
+ gem "minitest-hooks", "~> 1.5"
17
+ end
@@ -0,0 +1,71 @@
1
+ <%- assert_locals snippet -%>
2
+ require "<%= snippet.require_path %>"
3
+
4
+ # Create a client object. The client can be reused for multiple calls.
5
+ client = <%= snippet.client_type %>.new
6
+
7
+ <%- if snippet.bidi_streaming? -%>
8
+ # Create an input stream
9
+ input = Gapic::StreamInput.new
10
+
11
+ # Call the <%= snippet.method_name %> method to start streaming.
12
+ output = client.<%= snippet.method_name %> input
13
+
14
+ # Send requests on the stream. For each request, pass in keyword
15
+ # arguments to set fields. Be sure to close the stream when done.
16
+ input << <%= snippet.request_type %>.new
17
+ input << <%= snippet.request_type %>.new
18
+ input.close
19
+
20
+ # Handle streamed responses. These may be interleaved with inputs.
21
+ # Each response is of type <%= snippet.base_response_type %>.
22
+ output.each do |response|
23
+ p response
24
+ end
25
+ <%- else -%>
26
+ <%- if snippet.client_streaming? -%>
27
+ # Create a stream of requests, as an Enumerator.
28
+ # For each request, pass in keyword arguments to set fields.
29
+ request = [
30
+ <%= snippet.request_type %>.new,
31
+ <%= snippet.request_type %>.new
32
+ ].to_enum
33
+ <%- else -%>
34
+ # Create a request. To set request fields, pass in keyword arguments.
35
+ request = <%= snippet.request_type %>.new
36
+ <%- end -%>
37
+
38
+ # Call the <%= snippet.method_name %> method.
39
+ result = client.<%= snippet.method_name %> request
40
+
41
+ <%- case snippet.response_kind -%>
42
+ <%- when :lro -%>
43
+ # The returned object is of type Gapic::Operation. You can use this
44
+ # object to check the status of an operation, cancel it, or wait
45
+ # for results. Here is how to block until completion:
46
+ result.wait_until_done! timeout: 60
47
+ if result.response?
48
+ p result.response
49
+ else
50
+ puts "Error!"
51
+ end
52
+ <%- when :paged -%>
53
+ # The returned object is of type Gapic::PagedEnumerable. You can
54
+ # iterate over all elements by calling #each, and the enumerable
55
+ # will lazily make API calls to fetch subsequent pages. Other
56
+ # methods are also available for managing paging directly.
57
+ result.each do |response|
58
+ # Each element is of type <%= snippet.paged_response_type %>.
59
+ p response
60
+ end
61
+ <%- when :streaming -%>
62
+ # The returned object is a streamed enumerable yielding elements of
63
+ # type <%= snippet.base_response_type %>.
64
+ result.each do |response|
65
+ p response
66
+ end
67
+ <%- else -%>
68
+ # The returned object is of type <%= snippet.return_type %>.
69
+ p result
70
+ <%- end -%>
71
+ <%- end -%>
@@ -0,0 +1,6 @@
1
+ <%- assert_locals snippet -%>
2
+ <%= render partial: "shared/header" -%>
3
+
4
+ # [START <%= snippet.region_tag %>]
5
+ <%= render partial: "snippets/snippet/structure", locals: { snippet: snippet} -%>
6
+ # [END <%= snippet.region_tag %>]
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.7.5
4
+ version: 0.8.0
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: 2021-05-18 00:00:00.000000000 Z
13
+ date: 2021-06-16 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: actionpack
@@ -222,6 +222,7 @@ files:
222
222
  - lib/gapic/presenters/sample_presenter.rb
223
223
  - lib/gapic/presenters/service_presenter.rb
224
224
  - lib/gapic/presenters/service_rest_presenter.rb
225
+ - lib/gapic/presenters/snippet_presenter.rb
225
226
  - lib/gapic/resource_lookup.rb
226
227
  - lib/gapic/ruby_info.rb
227
228
  - lib/gapic/runner.rb
@@ -333,6 +334,11 @@ files:
333
334
  - templates/default/service/rest/grpc_transcoding/_grpc_transcoding.erb
334
335
  - templates/default/service/rest/grpc_transcoding/method/_def.erb
335
336
  - templates/default/service/rest/grpc_transcoding/method/def/_query_string_param.erb
337
+ - templates/default/service/rest/test/client.erb
338
+ - templates/default/service/rest/test/method/_assert_response.erb
339
+ - templates/default/service/rest/test/method/_configure.erb
340
+ - templates/default/service/rest/test/method/_normal.erb
341
+ - templates/default/service/rest/test/method/_setup.erb
336
342
  - templates/default/service/test/_resource.erb
337
343
  - templates/default/service/test/client.erb
338
344
  - templates/default/service/test/client_operations.erb
@@ -348,6 +354,9 @@ files:
348
354
  - templates/default/shared/_header.erb
349
355
  - templates/default/shared/_license.erb
350
356
  - templates/default/shared/_warning.erb
357
+ - templates/default/snippets/gemfile.erb
358
+ - templates/default/snippets/snippet/_structure.erb
359
+ - templates/default/snippets/standalone.erb
351
360
  homepage: https://github.com/googleapis/gapic-generator-ruby
352
361
  licenses:
353
362
  - Apache-2.0