gapic-generator 0.8.0 → 0.10.1
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 +4 -4
- data/CHANGELOG.md +37 -0
- data/lib/gapic/generator/version.rb +1 -1
- data/lib/gapic/generators/default_generator.rb +1 -1
- data/lib/gapic/generators/default_generator_parameters.rb +3 -1
- data/lib/gapic/presenters/gem_presenter.rb +25 -6
- data/lib/gapic/presenters/method/rest_pagination_info.rb +246 -0
- data/lib/gapic/presenters/method_presenter.rb +17 -2
- data/lib/gapic/presenters/method_rest_presenter.rb +75 -2
- data/lib/gapic/presenters/resource_presenter.rb +8 -0
- data/lib/gapic/presenters/service_config_presenter.rb +48 -0
- data/lib/gapic/presenters/service_presenter.rb +69 -0
- data/lib/gapic/presenters/service_rest_presenter.rb +42 -16
- data/lib/gapic/presenters/snippet_presenter.rb +1 -1
- data/lib/gapic/presenters.rb +1 -0
- data/lib/gapic/schema/api.rb +17 -7
- data/lib/gapic/schema/wrappers.rb +26 -0
- data/templates/default/gem/readme.erb +3 -3
- data/templates/default/lib/rest/_rest.erb +0 -2
- data/templates/default/service/client/_client.erb +18 -20
- data/templates/default/service/client/_config.erb +13 -14
- data/templates/default/service/client/_credentials.erb +2 -0
- data/templates/default/service/client/_operations.erb +1 -1
- data/templates/default/service/client/_paths.erb +1 -1
- data/templates/default/service/client/_self_configure_defaults.erb +2 -2
- data/templates/default/service/client/method/_def.erb +2 -0
- data/templates/default/service/client/method/def/_options_defaults.erb +3 -1
- data/templates/default/service/client/method/docs/_deprecated.erb +5 -0
- data/templates/default/service/client/method/docs/_snippets.erb +6 -0
- data/templates/default/service/rest/client/_client.erb +15 -24
- data/templates/default/service/rest/client/_config.erb +48 -0
- data/templates/default/service/rest/client/method/_def.erb +1 -1
- data/templates/default/service/rest/client/method/def/_options_defaults.erb +5 -2
- data/templates/default/service/rest/client/method/def/_response.erb +8 -0
- data/templates/default/service/rest/client/method/def/_response_lro.erb +7 -0
- data/templates/default/service/rest/client/method/def/_response_normal.erb +4 -15
- data/templates/default/service/rest/client/method/def/_response_paged.erb +7 -0
- data/templates/default/service/rest/client/method/docs/_result.erb +3 -3
- data/templates/default/service/rest/service_stub/_service_stub.erb +25 -0
- data/templates/default/service/rest/{grpc_transcoding/method → service_stub/grpc_transcoding_method}/_def.erb +4 -1
- data/templates/default/service/rest/{grpc_transcoding/method → service_stub/grpc_transcoding_method}/def/_query_string_param.erb +0 -0
- data/templates/default/service/rest/service_stub/method/_def.erb +20 -0
- data/templates/default/service/rest/service_stub/method/def/_request.erb +2 -0
- data/templates/default/service/rest/service_stub/method/def/_response.erb +17 -0
- data/templates/default/service/rest/service_stub.erb +6 -0
- data/templates/default/service/rest/test/client.erb +1 -1
- data/templates/default/service/test/client_paths.erb +1 -1
- metadata +17 -8
- data/templates/default/service/client/_self_configure_retry_policy.erb +0 -15
- data/templates/default/service/rest/client/_requires.erb +0 -1
- data/templates/default/service/rest/grpc_transcoding/_grpc_transcoding.erb +0 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8fa15ffab6c84ed42f1e5801ba4481fa755040e69ead95a652a2ab7e611c44e6
|
4
|
+
data.tar.gz: 8290eb8ae3394afe98876ae03b0ca74b6ef51ca4af9d74537b177c472a44402f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6a3d25f24e6c43fd8b52b8ade6b520109b854660ea1d5aa9bdf8afa14802be85de8d47357deb9a5039a34c0e3b466d4228d05da5d5dbb78981065c46270ff682
|
7
|
+
data.tar.gz: 31c64a0bccabf7a9077c720185b425ac77e443b17cc86ea78ae222e82d0b3237a607ca744ee3488aede394dcf1446dd5da4ad58cb2be3c8a76942905a6e34b7f
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,42 @@
|
|
1
1
|
# Release History for gapic-generator
|
2
2
|
|
3
|
+
### 0.10.1 / 2021-08-27
|
4
|
+
|
5
|
+
* New: Compute REST libraries are now generated with LRO wrappers
|
6
|
+
* Fixed: Rubocop is disabled for sample tests in generated versioned libraries
|
7
|
+
|
8
|
+
### 0.10.0 / 2021-08-09
|
9
|
+
|
10
|
+
* New: Enabled per-RPC configuration for generated REST libraries
|
11
|
+
* New: Generated docs include the deprecated YARD tag for deprecated protos
|
12
|
+
* New: Scopes can be passed to self-signed JWTs
|
13
|
+
* Fixed: Generated gRPC clients honor the client-default timeout config
|
14
|
+
* Fixed: Generated docs now use YARD example tags for inline samples related to configuration
|
15
|
+
* Fixed: Generated REST clients now require google/cloud/errors
|
16
|
+
* Generated libraries now require gapic-common 0.7.0 or later
|
17
|
+
|
18
|
+
### 0.9.2 / 2021-07-27
|
19
|
+
|
20
|
+
* REST libraries are now generated with pagination hepers
|
21
|
+
* REST libraries are now generated with correct examples in README.md and other documentation files
|
22
|
+
* It is now possible to generate inline snippets in yardocs
|
23
|
+
* Fixed the require path in the generated standalone snippets so it reflects the recommended require root rather than the service-specific require path.
|
24
|
+
* Prevent "duplicate" resources (with the same name but different namespaces) from producing duplicate helper methods.
|
25
|
+
|
26
|
+
### 0.9.1 / 2021-07-07
|
27
|
+
|
28
|
+
* Detect multiple resource parents for patterns used by multiple resources
|
29
|
+
|
30
|
+
### 0.9.0 / 2021-06-29
|
31
|
+
|
32
|
+
* Support for configuring the service/method used for the quickstart example
|
33
|
+
* Allow generation of libraries with no custom env prefix
|
34
|
+
* Add service override setting to the repo metadata
|
35
|
+
* Wrapper gem dependencies on pre-GA versioned gems now allow both 0.x and 1.x versions
|
36
|
+
* Scoped some String and Hash references to the global scope to avoid name collisions
|
37
|
+
* Reformat some config code to avoid rubocop indentation churn
|
38
|
+
* Bazel: Replace monolith deps with rules_gapic
|
39
|
+
|
3
40
|
### 0.8.0 / 2021-06-16
|
4
41
|
|
5
42
|
* Initial implementation of standalone snippet generation.
|
@@ -60,7 +60,7 @@ module Gapic
|
|
60
60
|
files << g("service/paths.erb", "lib/#{service.paths_file_path}", service: service) if service.paths?
|
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
|
-
files << g("service/rest/
|
63
|
+
files << g("service/rest/service_stub.erb", "lib/#{service.rest.service_stub_file_path}", service: service) if @api.generate_rest_clients? and service.methods_rest_bindings?
|
64
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?
|
65
65
|
files << g("service/test/client.erb", "test/#{service.test_client_file_path}", service: service) unless @api.generate_rest_clients?
|
66
66
|
files << g("service/test/client_paths.erb", "test/#{service.test_paths_file_path}", service: service) if service.paths?
|
@@ -127,11 +127,7 @@ module Gapic
|
|
127
127
|
end
|
128
128
|
|
129
129
|
def env_prefix
|
130
|
-
|
131
|
-
segs = name.split("-").reverse
|
132
|
-
segs.find { |seg| seg !~ /^v\d/ } || segs.first || "UNKNOWN"
|
133
|
-
end
|
134
|
-
prefix.upcase
|
130
|
+
gem_config(:env_prefix)&.upcase
|
135
131
|
end
|
136
132
|
|
137
133
|
def iam_dependency?
|
@@ -196,7 +192,7 @@ module Gapic
|
|
196
192
|
|
197
193
|
def dependencies
|
198
194
|
@dependencies ||= begin
|
199
|
-
deps = { "gapic-common" => [">= 0.
|
195
|
+
deps = { "gapic-common" => [">= 0.7", "< 2.a"] }
|
200
196
|
deps["grpc-google-iam-v1"] = [">= 0.6.10", "< 2.a"] if iam_dependency?
|
201
197
|
extra_deps = gem_config_dependencies
|
202
198
|
deps.merge! extra_deps if extra_deps
|
@@ -231,6 +227,29 @@ module Gapic
|
|
231
227
|
JSON.pretty_generate first_package_drift_manifest
|
232
228
|
end
|
233
229
|
|
230
|
+
##
|
231
|
+
# The service to use for quick start samples. Normally this is simply the
|
232
|
+
# {#first_non_common_service}, but it can be overridden via a gem config.
|
233
|
+
#
|
234
|
+
# @return [Gapic::Presenters::ServicePresenter]
|
235
|
+
#
|
236
|
+
def quick_start_service
|
237
|
+
preferred_service = gem_config :quick_start_service
|
238
|
+
result = services.find { |svc| svc.name == preferred_service } if preferred_service
|
239
|
+
result || first_non_common_service
|
240
|
+
end
|
241
|
+
|
242
|
+
##
|
243
|
+
# Whether the "Enabling (gRPC) Logging" section of the readme should
|
244
|
+
# appear. This is true if there is a quick-start service displayed in the
|
245
|
+
# readme, AND it uses gRPC.
|
246
|
+
#
|
247
|
+
# @return [Boolean]
|
248
|
+
#
|
249
|
+
def show_grpc_logging_docs?
|
250
|
+
packages? && quick_start_service.usable_service_presenter.is_a?(ServicePresenter)
|
251
|
+
end
|
252
|
+
|
234
253
|
private
|
235
254
|
|
236
255
|
def gem_config key
|
@@ -0,0 +1,246 @@
|
|
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
|
+
module Gapic
|
18
|
+
module Presenters
|
19
|
+
module Method
|
20
|
+
##
|
21
|
+
# Pagination info determined from the proto method
|
22
|
+
#
|
23
|
+
class RestPaginationInfo
|
24
|
+
include Gapic::Helpers::NamespaceHelper
|
25
|
+
##
|
26
|
+
# @param proto_method [Gapic::Schema::Method] the method to derive pagination info from
|
27
|
+
# @param api [Gapic::Schema::Api]
|
28
|
+
#
|
29
|
+
def initialize proto_method, api
|
30
|
+
@api = api
|
31
|
+
@request = proto_method.input
|
32
|
+
@response = proto_method.output
|
33
|
+
@server_streaming = proto_method.server_streaming
|
34
|
+
end
|
35
|
+
|
36
|
+
##
|
37
|
+
# Whether the method should be generated as paged
|
38
|
+
#
|
39
|
+
# @return [Boolean]
|
40
|
+
def paged?
|
41
|
+
!server_streaming? && paged_request? && paged_response?
|
42
|
+
end
|
43
|
+
|
44
|
+
##
|
45
|
+
# Name of the request's field used for page size
|
46
|
+
# For Regapic can be either `page_size` or `max_results`
|
47
|
+
#
|
48
|
+
# @return [String, nil]
|
49
|
+
def request_page_size_name
|
50
|
+
request_page_size_field&.name
|
51
|
+
end
|
52
|
+
|
53
|
+
##
|
54
|
+
# Name of the repeated field in the response message
|
55
|
+
# For REST gapics can be either a vanilla repeated field or a map
|
56
|
+
#
|
57
|
+
# @return [String, nil]
|
58
|
+
def response_repeated_field_name
|
59
|
+
response_results_field&.name
|
60
|
+
end
|
61
|
+
|
62
|
+
##
|
63
|
+
# Whether the repeated field in the response message is a map
|
64
|
+
#
|
65
|
+
# @return [Boolean, nil]
|
66
|
+
def repeated_field_is_a_map?
|
67
|
+
response_results_field&.map?
|
68
|
+
end
|
69
|
+
|
70
|
+
##
|
71
|
+
# Proto type of the repeated field in the response message
|
72
|
+
#
|
73
|
+
# @return [String, nil]
|
74
|
+
def paged_element_doc_type
|
75
|
+
return nil if response_results_field.nil?
|
76
|
+
field_paginated_elem_doc_type response_results_field
|
77
|
+
end
|
78
|
+
|
79
|
+
private
|
80
|
+
|
81
|
+
# Whether the underlying proto rpc is a server streaming rpc
|
82
|
+
# @return [Boolean]
|
83
|
+
attr_accessor :server_streaming
|
84
|
+
|
85
|
+
##
|
86
|
+
# Whether the underlying proto rpc is a server streaming rpc
|
87
|
+
#
|
88
|
+
# @return [Boolean]
|
89
|
+
def server_streaming?
|
90
|
+
@server_streaming
|
91
|
+
end
|
92
|
+
|
93
|
+
##
|
94
|
+
# Whether the request message for the REGAPIC rpc satisfies the criteria
|
95
|
+
# for the rpc to be classified and implemented as paged
|
96
|
+
#
|
97
|
+
# @return [Boolean]
|
98
|
+
def paged_request?
|
99
|
+
# Has a String page_token field which specifies the actual (next) page to retrieve.
|
100
|
+
# Has an int32 page_size or int32 max_results field
|
101
|
+
# which defines the maximum number of paginated resources to return in the response.
|
102
|
+
!request_page_token_field.nil? && !request_page_size_field.nil?
|
103
|
+
end
|
104
|
+
|
105
|
+
##
|
106
|
+
# The field in the request that holds a page_token
|
107
|
+
#
|
108
|
+
# @return[Gapic::Schema::Field, nil]
|
109
|
+
def request_page_token_field
|
110
|
+
# Has a String page_token field which specifies the actual (next) page to retrieve.
|
111
|
+
@request_page_token_field ||= @request.fields.find do |f|
|
112
|
+
f.name == "page_token" && f.type == Google::Protobuf::FieldDescriptorProto::Type::TYPE_STRING
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
##
|
117
|
+
# The field in the request that holds a page_size
|
118
|
+
# For Regapic can have a name of either `page_size` or `max_results`
|
119
|
+
#
|
120
|
+
# @return[Gapic::Schema::Field, nil]
|
121
|
+
def request_page_size_field
|
122
|
+
@request_page_size_field ||=
|
123
|
+
begin
|
124
|
+
page_size_names = ["page_size", "max_results"]
|
125
|
+
|
126
|
+
# Has the int32 page_size or int32 max_results field
|
127
|
+
# which defines the maximum number of paginated resources to return in the response.
|
128
|
+
page_size_types = [
|
129
|
+
Google::Protobuf::FieldDescriptorProto::Type::TYPE_UINT32,
|
130
|
+
Google::Protobuf::FieldDescriptorProto::Type::TYPE_INT32
|
131
|
+
]
|
132
|
+
|
133
|
+
field = @request.fields.find do |f|
|
134
|
+
page_size_names.include?(f.name) && page_size_types.include?(f.type)
|
135
|
+
end
|
136
|
+
|
137
|
+
field
|
138
|
+
end
|
139
|
+
end
|
140
|
+
|
141
|
+
##
|
142
|
+
# Whether the response message for the REGAPIC rpc satisfies the criteria
|
143
|
+
# for the rpc to be classified and implemented as paged
|
144
|
+
#
|
145
|
+
# @return [Boolean]
|
146
|
+
def paged_response?
|
147
|
+
# Has the string next_page_token field to be used in the next request as page_token to retrieve the next page.
|
148
|
+
# Has only one repeated or map<string, ?> field containing a list of paginated resources.
|
149
|
+
!response_next_page_token_field.nil? && !response_results_field.nil?
|
150
|
+
end
|
151
|
+
|
152
|
+
##
|
153
|
+
# The field in the response that holds a next page_token
|
154
|
+
#
|
155
|
+
# @return[Gapic::Schema::Field, nil]
|
156
|
+
def response_next_page_token_field
|
157
|
+
# Has the string next_page_token field to be used in the next request as page_token to retrieve the next page.
|
158
|
+
@response_next_page_token_field ||= @response.fields.find do |f|
|
159
|
+
f.name == "next_page_token" && f.type == Google::Protobuf::FieldDescriptorProto::Type::TYPE_STRING
|
160
|
+
end
|
161
|
+
end
|
162
|
+
|
163
|
+
##
|
164
|
+
# The field in the response that holds the results
|
165
|
+
# For Regapic can be either a vanilla repeated field or a map
|
166
|
+
#
|
167
|
+
# @return [Gapic::Schema::Field, nil]
|
168
|
+
def response_results_field
|
169
|
+
@response_results_field ||= begin
|
170
|
+
map_fields = @response.fields.find_all(&:map?)
|
171
|
+
repeated_fields = @response.fields.find_all do |f|
|
172
|
+
!f.map? &&
|
173
|
+
f.label == Google::Protobuf::FieldDescriptorProto::Label::LABEL_REPEATED
|
174
|
+
end
|
175
|
+
|
176
|
+
if map_fields.count == 1
|
177
|
+
# If the response message has only one map<string, ?> field
|
178
|
+
# treat it as the one with paginated resources (i.e. ignore the repeated fields if any).
|
179
|
+
map_fields.first
|
180
|
+
elsif repeated_fields.count == 1 && map_fields.empty?
|
181
|
+
# If the response message contains only one repeated field,
|
182
|
+
# treat that field as the one containing the paginated resources.
|
183
|
+
repeated_fields.first
|
184
|
+
end
|
185
|
+
# If the response message contains more than one repeated field or does not have repeated fields at all
|
186
|
+
# but has more than one map<string, ?> field, do not generate any paginated methods for such rpc.
|
187
|
+
end
|
188
|
+
end
|
189
|
+
|
190
|
+
##
|
191
|
+
# A helper to get a Ruby doc-type for a paginated element.
|
192
|
+
#
|
193
|
+
# @param field [Gapic::Schema::Field]
|
194
|
+
#
|
195
|
+
# @return [String]
|
196
|
+
def field_paginated_elem_doc_type field
|
197
|
+
return field_paginated_elem_map_type field if field.map?
|
198
|
+
if field.message?
|
199
|
+
message_ruby_type field.message
|
200
|
+
elsif field.enum?
|
201
|
+
# TODO: handle when arg message is nil and enum is the type
|
202
|
+
message_ruby_type field.enum
|
203
|
+
else
|
204
|
+
case field.type
|
205
|
+
when 1, 2 then "::Float"
|
206
|
+
when 3, 4, 5, 6, 7, 13, 15, 16, 17, 18 then "::Integer"
|
207
|
+
when 9, 12 then "::String"
|
208
|
+
when 8 then "::Boolean"
|
209
|
+
else
|
210
|
+
"::Object"
|
211
|
+
end
|
212
|
+
end
|
213
|
+
end
|
214
|
+
|
215
|
+
##
|
216
|
+
# A helper to get a Ruby doc-type for a proto map's paginated element.
|
217
|
+
#
|
218
|
+
# @param field [Gapic::Schema::Field]
|
219
|
+
#
|
220
|
+
# @return [String]
|
221
|
+
def field_paginated_elem_map_type field
|
222
|
+
key_field = field.map_key_field
|
223
|
+
value_field = field.map_val_field
|
224
|
+
|
225
|
+
if key_field && value_field
|
226
|
+
key_type = field_paginated_elem_doc_type key_field
|
227
|
+
value_type = field_paginated_elem_doc_type value_field
|
228
|
+
"#{key_type}, #{value_type}"
|
229
|
+
else
|
230
|
+
class_name
|
231
|
+
end
|
232
|
+
end
|
233
|
+
|
234
|
+
##
|
235
|
+
# A helper to get a Ruby type for a proto message.
|
236
|
+
#
|
237
|
+
# @param message [Gapic::Schema::Message]
|
238
|
+
#
|
239
|
+
# @return [String]
|
240
|
+
def message_ruby_type message
|
241
|
+
ruby_namespace @api, message.address.join(".")
|
242
|
+
end
|
243
|
+
end
|
244
|
+
end
|
245
|
+
end
|
246
|
+
end
|
@@ -40,7 +40,7 @@ module Gapic
|
|
40
40
|
@service_presenter = service_presenter
|
41
41
|
@api = api
|
42
42
|
@method = method
|
43
|
-
@rest = MethodRestPresenter.new self
|
43
|
+
@rest = MethodRestPresenter.new self, api
|
44
44
|
end
|
45
45
|
|
46
46
|
##
|
@@ -54,6 +54,10 @@ module Gapic
|
|
54
54
|
SnippetPresenter.new self, @api
|
55
55
|
end
|
56
56
|
|
57
|
+
def generate_yardoc_snippets?
|
58
|
+
@api.generate_yardoc_snippets?
|
59
|
+
end
|
60
|
+
|
57
61
|
def name
|
58
62
|
@name ||= begin
|
59
63
|
candidate = ActiveSupport::Inflector.underscore @method.name
|
@@ -93,6 +97,13 @@ module Gapic
|
|
93
97
|
ret
|
94
98
|
end
|
95
99
|
|
100
|
+
##
|
101
|
+
# @return [Boolean]
|
102
|
+
#
|
103
|
+
def is_deprecated?
|
104
|
+
@method.is_deprecated?
|
105
|
+
end
|
106
|
+
|
96
107
|
def arguments
|
97
108
|
arguments = @method.input.fields.reject(&:output_only?)
|
98
109
|
arguments.map { |arg| FieldPresenter.new @api, @method.input, arg }
|
@@ -175,7 +186,7 @@ module Gapic
|
|
175
186
|
def lro?
|
176
187
|
return paged_response_type == "::Google::Longrunning::Operation" if paged?
|
177
188
|
|
178
|
-
|
189
|
+
return_type == "::Google::Longrunning::Operation"
|
179
190
|
end
|
180
191
|
|
181
192
|
def client_streaming?
|
@@ -232,6 +243,10 @@ module Gapic
|
|
232
243
|
end
|
233
244
|
end
|
234
245
|
|
246
|
+
def service_config_presenter
|
247
|
+
ServiceConfigPresenter.new grpc_service_config
|
248
|
+
end
|
249
|
+
|
235
250
|
def grpc_method_name
|
236
251
|
@method.name
|
237
252
|
end
|
@@ -14,6 +14,7 @@
|
|
14
14
|
# See the License for the specific language governing permissions and
|
15
15
|
# limitations under the License.
|
16
16
|
|
17
|
+
require "gapic/presenters/method/rest_pagination_info"
|
17
18
|
require "gapic/uri_template"
|
18
19
|
|
19
20
|
module Gapic
|
@@ -22,9 +23,19 @@ module Gapic
|
|
22
23
|
# A presenter for rpc methods (REST submethods)
|
23
24
|
#
|
24
25
|
class MethodRestPresenter
|
25
|
-
|
26
|
+
# @return [Gapic::Presenters::Method::RestPaginationInfo]
|
27
|
+
attr_reader :pagination
|
28
|
+
|
29
|
+
##
|
30
|
+
# @param main_method [Gapic::Presenters::MethodPresenter] the main presenter for this method.
|
31
|
+
# @param api [Gapic::Schema::Api]
|
32
|
+
#
|
33
|
+
def initialize main_method, api
|
34
|
+
@api = api
|
26
35
|
@main_method = main_method
|
27
36
|
@proto_method = main_method.method
|
37
|
+
|
38
|
+
@pagination = Gapic::Presenters::Method::RestPaginationInfo.new @proto_method, api
|
28
39
|
end
|
29
40
|
|
30
41
|
##
|
@@ -187,7 +198,69 @@ module Gapic
|
|
187
198
|
#
|
188
199
|
# @return [String]
|
189
200
|
def transcoding_helper_name
|
190
|
-
"transcode_#{
|
201
|
+
"transcode_#{name}_request"
|
202
|
+
end
|
203
|
+
|
204
|
+
##
|
205
|
+
# Method name
|
206
|
+
#
|
207
|
+
# @return [String]
|
208
|
+
#
|
209
|
+
def name
|
210
|
+
@main_method.name
|
211
|
+
end
|
212
|
+
|
213
|
+
##
|
214
|
+
# Full class name of the request type
|
215
|
+
#
|
216
|
+
# @return [String]
|
217
|
+
#
|
218
|
+
def request_type
|
219
|
+
@main_method.request_type
|
220
|
+
end
|
221
|
+
|
222
|
+
##
|
223
|
+
# Full class name of the raw return type of the RPC
|
224
|
+
#
|
225
|
+
# @return [String]
|
226
|
+
#
|
227
|
+
def return_type
|
228
|
+
@main_method.return_type
|
229
|
+
end
|
230
|
+
|
231
|
+
##
|
232
|
+
# Full class name of the return type of the method
|
233
|
+
# (including LRO and Paged cases)
|
234
|
+
#
|
235
|
+
# @return [String]
|
236
|
+
#
|
237
|
+
def doc_response_type
|
238
|
+
return "::Gapic::Rest::PagedEnumerable<#{pagination.paged_element_doc_type}>" if paged?
|
239
|
+
return "::Gapic::Rest::BaseOperation" if lro?
|
240
|
+
return_type
|
241
|
+
end
|
242
|
+
|
243
|
+
##
|
244
|
+
# Whether the REGAPIC method should be rendered as paged
|
245
|
+
#
|
246
|
+
# @return [Boolean]
|
247
|
+
#
|
248
|
+
def paged?
|
249
|
+
@pagination.paged?
|
250
|
+
end
|
251
|
+
|
252
|
+
##
|
253
|
+
# Whether the REGAPIC method should be rendered as LRO
|
254
|
+
# [TODO (virost, 2021-08) Update this when DiReGapic LRO annotations are added to the Compute protos]
|
255
|
+
#
|
256
|
+
# @return [Boolean]
|
257
|
+
#
|
258
|
+
def lro?
|
259
|
+
return_type == "::Google::Cloud::Compute::V1::Operation" &&
|
260
|
+
@main_method.service.name != "ZoneOperations" &&
|
261
|
+
@main_method.service.name != "RegionOperations" &&
|
262
|
+
@main_method.service.name != "GlobalOperations" &&
|
263
|
+
@main_method.service.name != "GlobalOrganizationOperations"
|
191
264
|
end
|
192
265
|
end
|
193
266
|
end
|