gapic-generator 0.9.1 → 0.11.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +57 -0
- data/lib/gapic/generator/version.rb +1 -1
- data/lib/gapic/generators/default_generator.rb +3 -1
- data/lib/gapic/generators/default_generator_parameters.rb +6 -2
- data/lib/gapic/grpc_service_config/{service_config.rb → config.rb} +2 -2
- data/lib/gapic/grpc_service_config/parser.rb +8 -8
- data/lib/gapic/model/method/http_annotation.rb +123 -0
- data/lib/gapic/model/method/lro.rb +160 -0
- data/lib/gapic/model/method/routing.rb +263 -0
- data/lib/gapic/model/mixins.rb +181 -0
- data/lib/gapic/model/model_error.rb +26 -0
- data/lib/gapic/model/service/nonstandard_lro_provider.rb +293 -0
- data/lib/gapic/model.rb +22 -0
- data/lib/gapic/path_pattern/pattern.rb +46 -0
- data/lib/gapic/path_pattern/segment.rb +97 -9
- data/lib/gapic/presenters/gem_presenter.rb +46 -3
- data/lib/gapic/presenters/{service_config_presenter.rb → grpc_service_config_presenter.rb} +1 -1
- data/lib/gapic/presenters/method/rest_pagination_info.rb +246 -0
- data/lib/gapic/presenters/method_presenter.rb +56 -5
- data/lib/gapic/presenters/method_rest_presenter.rb +99 -48
- data/lib/gapic/presenters/resource_presenter.rb +8 -0
- data/lib/gapic/presenters/service/lro_client_presenter.rb +90 -0
- data/lib/gapic/presenters/service_presenter.rb +236 -3
- data/lib/gapic/presenters/service_rest_presenter.rb +117 -10
- data/lib/gapic/presenters/snippet_presenter.rb +2 -1
- data/lib/gapic/presenters.rb +3 -1
- data/lib/gapic/schema/api.rb +61 -2
- data/lib/gapic/schema/loader.rb +4 -1
- data/lib/gapic/schema/service_config_parser.rb +118 -0
- data/lib/gapic/schema/wrappers.rb +149 -0
- data/lib/google/api/auth.pb.rb +75 -0
- data/lib/google/api/backend.pb.rb +59 -0
- data/lib/google/api/billing.pb.rb +53 -0
- data/lib/google/api/context.pb.rb +47 -0
- data/lib/google/api/control.pb.rb +38 -0
- data/lib/google/api/documentation.pb.rb +56 -0
- data/lib/google/api/endpoint.pb.rb +42 -0
- data/lib/google/api/label.pb.rb +49 -0
- data/lib/google/api/launch_stage.pb.rb +37 -0
- data/lib/google/api/log.pb.rb +47 -0
- data/lib/google/api/logging.pb.rb +48 -0
- data/lib/google/api/metric.pb.rb +90 -0
- data/lib/google/api/monitored_resource.pb.rb +68 -0
- data/lib/google/api/monitoring.pb.rb +48 -0
- data/lib/google/api/quota.pb.rb +63 -0
- data/lib/google/api/routing.pb.rb +58 -0
- data/lib/google/api/service.pb.rb +90 -0
- data/lib/google/api/source_info.pb.rb +44 -0
- data/lib/google/api/system_parameter.pb.rb +51 -0
- data/lib/google/api/usage.pb.rb +47 -0
- data/lib/google/cloud/extended_operations.pb.rb +57 -0
- data/lib/google/protobuf/any.pb.rb +1 -1
- data/lib/google/protobuf/api.pb.rb +69 -0
- data/lib/google/protobuf/descriptor.pb.rb +1 -1
- data/lib/google/protobuf/duration.pb.rb +41 -0
- data/lib/google/protobuf/source_context.pb.rb +39 -0
- data/lib/google/protobuf/struct.pb.rb +65 -0
- data/lib/google/protobuf/type.pb.rb +128 -0
- data/lib/google/protobuf/wrappers.pb.rb +80 -0
- data/templates/default/gem/yardopts.erb +1 -1
- data/templates/default/lib/_package.erb +4 -0
- data/templates/default/lib/_service.erb +6 -0
- data/templates/default/lib/rest/_rest.erb +0 -2
- data/templates/default/service/client/_client.erb +37 -27
- data/templates/default/service/client/_config.erb +13 -14
- data/templates/default/service/client/_nonstandard_lro.erb +57 -0
- 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 +4 -9
- data/templates/default/service/client/method/def/_response.erb +2 -0
- data/templates/default/service/client/method/def/_response_nonstandard_lro.erb +23 -0
- data/templates/default/service/client/method/def/_routing_params.erb +36 -0
- 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/nonstandard_lro.erb +6 -0
- data/templates/default/service/rest/client/_client.erb +45 -27
- 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_nonstandard_lro.erb +23 -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
- data/templates/default/service/test/method/_assert_response.erb +3 -0
- metadata +74 -11
- data/templates/default/service/rest/client/_requires.erb +0 -1
- data/templates/default/service/rest/grpc_transcoding/_grpc_transcoding.erb +0 -9
@@ -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
|
@@ -32,6 +32,15 @@ module Gapic
|
|
32
32
|
# @return [Gapic::Presenters::MethodRestPresenter]
|
33
33
|
attr_accessor :rest
|
34
34
|
|
35
|
+
# @return [Gapic::Model::Method::Routing]
|
36
|
+
attr_accessor :routing
|
37
|
+
|
38
|
+
# @return [Gapic::Model::Method::HttpAnnotation]
|
39
|
+
attr_accessor :http
|
40
|
+
|
41
|
+
# @return [Gapic::Model::Method::AipLro, Gapic::Model::Method::NonStandardLro, Gapic::Model::Method::NoLro]
|
42
|
+
attr_accessor :lro
|
43
|
+
|
35
44
|
##
|
36
45
|
# @param service_presenter [Gapic::Presenters::ServicePresenter]
|
37
46
|
# @param api [Gapic::Schema::Api]
|
@@ -40,7 +49,11 @@ module Gapic
|
|
40
49
|
@service_presenter = service_presenter
|
41
50
|
@api = api
|
42
51
|
@method = method
|
43
|
-
@
|
52
|
+
@http = Gapic::Model::Method::HttpAnnotation.new @method
|
53
|
+
@routing = Gapic::Model::Method::Routing.new @method.routing, http
|
54
|
+
@lro = Gapic::Model::Method.parse_lro @method, api
|
55
|
+
|
56
|
+
@rest = MethodRestPresenter.new self, api
|
44
57
|
end
|
45
58
|
|
46
59
|
##
|
@@ -50,10 +63,17 @@ module Gapic
|
|
50
63
|
@service_presenter
|
51
64
|
end
|
52
65
|
|
66
|
+
##
|
67
|
+
# @return [Gapic::Presenters::SnippetPresenter]
|
68
|
+
#
|
53
69
|
def snippet
|
54
70
|
SnippetPresenter.new self, @api
|
55
71
|
end
|
56
72
|
|
73
|
+
def generate_yardoc_snippets?
|
74
|
+
@api.generate_yardoc_snippets?
|
75
|
+
end
|
76
|
+
|
57
77
|
def name
|
58
78
|
@name ||= begin
|
59
79
|
candidate = ActiveSupport::Inflector.underscore @method.name
|
@@ -93,6 +113,13 @@ module Gapic
|
|
93
113
|
ret
|
94
114
|
end
|
95
115
|
|
116
|
+
##
|
117
|
+
# @return [Boolean]
|
118
|
+
#
|
119
|
+
def is_deprecated?
|
120
|
+
@method.is_deprecated?
|
121
|
+
end
|
122
|
+
|
96
123
|
def arguments
|
97
124
|
arguments = @method.input.fields.reject(&:output_only?)
|
98
125
|
arguments.map { |arg| FieldPresenter.new @api, @method.input, arg }
|
@@ -172,10 +199,34 @@ module Gapic
|
|
172
199
|
sample_configs.map { |sample_config| SamplePresenter.new @api, sample_config }
|
173
200
|
end
|
174
201
|
|
202
|
+
##
|
203
|
+
# Whether this method uses standard (AIP-151) LROs
|
204
|
+
#
|
205
|
+
# @return [Boolean]
|
206
|
+
#
|
175
207
|
def lro?
|
176
208
|
return paged_response_type == "::Google::Longrunning::Operation" if paged?
|
177
209
|
|
178
|
-
|
210
|
+
return_type == "::Google::Longrunning::Operation"
|
211
|
+
end
|
212
|
+
|
213
|
+
##
|
214
|
+
# Whether this method uses nonstandard LROs
|
215
|
+
#
|
216
|
+
# @return [Boolean]
|
217
|
+
#
|
218
|
+
def nonstandard_lro?
|
219
|
+
@lro.nonstandard_lro?
|
220
|
+
end
|
221
|
+
|
222
|
+
##
|
223
|
+
# The presenter for the nonstandard LRO client of the kind this method uses
|
224
|
+
#
|
225
|
+
# @return [Gapic::Presenters::Service::LroClientPresenter, nil]
|
226
|
+
#
|
227
|
+
def nonstandard_lro_client
|
228
|
+
return unless nonstandard_lro?
|
229
|
+
service.nonstandard_lros.find { |model| model.service == @lro.service_full_name }
|
179
230
|
end
|
180
231
|
|
181
232
|
def client_streaming?
|
@@ -222,7 +273,7 @@ module Gapic
|
|
222
273
|
# @return [Boolean] Whether any routing params are present
|
223
274
|
#
|
224
275
|
def routing_params?
|
225
|
-
|
276
|
+
@routing.routing_params?
|
226
277
|
end
|
227
278
|
|
228
279
|
def grpc_service_config
|
@@ -232,8 +283,8 @@ module Gapic
|
|
232
283
|
end
|
233
284
|
end
|
234
285
|
|
235
|
-
def
|
236
|
-
|
286
|
+
def grpc_service_config_presenter
|
287
|
+
GrpcServiceConfigPresenter.new grpc_service_config
|
237
288
|
end
|
238
289
|
|
239
290
|
def grpc_method_name
|
@@ -14,7 +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/
|
17
|
+
require "gapic/presenters/method/rest_pagination_info"
|
18
18
|
|
19
19
|
module Gapic
|
20
20
|
module Presenters
|
@@ -22,68 +22,62 @@ module Gapic
|
|
22
22
|
# A presenter for rpc methods (REST submethods)
|
23
23
|
#
|
24
24
|
class MethodRestPresenter
|
25
|
-
|
25
|
+
# @return [Gapic::Presenters::Method::RestPaginationInfo]
|
26
|
+
attr_reader :pagination
|
27
|
+
|
28
|
+
##
|
29
|
+
# @param main_method [Gapic::Presenters::MethodPresenter] the main presenter for this method.
|
30
|
+
# @param api [Gapic::Schema::Api]
|
31
|
+
#
|
32
|
+
def initialize main_method, api
|
33
|
+
@api = api
|
26
34
|
@main_method = main_method
|
27
35
|
@proto_method = main_method.method
|
36
|
+
@http = main_method.http
|
37
|
+
|
38
|
+
@pagination = Gapic::Presenters::Method::RestPaginationInfo.new @proto_method, api
|
28
39
|
end
|
29
40
|
|
30
41
|
##
|
31
42
|
# @return [Boolean] Whether a http verb is present for this method
|
32
43
|
#
|
33
44
|
def verb?
|
34
|
-
|
45
|
+
@http.verb?
|
35
46
|
end
|
36
47
|
|
37
48
|
##
|
38
49
|
# @return [Symbol] a http verb for this method
|
39
50
|
#
|
40
51
|
def verb
|
41
|
-
|
42
|
-
|
43
|
-
method = {
|
44
|
-
get: @proto_method.http.get,
|
45
|
-
post: @proto_method.http.post,
|
46
|
-
put: @proto_method.http.put,
|
47
|
-
patch: @proto_method.http.patch,
|
48
|
-
delete: @proto_method.http.delete
|
49
|
-
}.find { |_, value| !value.empty? }
|
50
|
-
|
51
|
-
method[0] unless method.nil?
|
52
|
+
@http.verb
|
52
53
|
end
|
53
54
|
|
54
55
|
##
|
55
56
|
# @return [Boolean] Whether a method path is present and non-empty
|
56
57
|
#
|
57
58
|
def path?
|
58
|
-
|
59
|
-
end
|
60
|
-
|
61
|
-
##
|
62
|
-
# @return [String] A method path or an empty string if not present
|
63
|
-
#
|
64
|
-
def path
|
65
|
-
return "" if @proto_method.http.nil?
|
66
|
-
|
67
|
-
verb_path = [
|
68
|
-
@proto_method.http.get, @proto_method.http.post, @proto_method.http.put,
|
69
|
-
@proto_method.http.patch, @proto_method.http.delete
|
70
|
-
].find { |x| !x.empty? }
|
71
|
-
|
72
|
-
verb_path || @proto_method.http.custom&.path || ""
|
59
|
+
@http.path?
|
73
60
|
end
|
74
61
|
|
75
62
|
##
|
76
63
|
# @return [Boolean] Whether any routing params are present
|
77
64
|
#
|
78
65
|
def routing_params?
|
79
|
-
routing_params
|
66
|
+
@http.routing_params?
|
80
67
|
end
|
81
68
|
|
82
69
|
##
|
83
70
|
# @return [Array<String>] The segment key names.
|
84
71
|
#
|
85
72
|
def routing_params
|
86
|
-
|
73
|
+
@http.routing_params
|
74
|
+
end
|
75
|
+
|
76
|
+
##
|
77
|
+
# @return [Boolean] Whether method has body specified in proto
|
78
|
+
#
|
79
|
+
def body?
|
80
|
+
@http.body?
|
87
81
|
end
|
88
82
|
|
89
83
|
##
|
@@ -103,15 +97,6 @@ module Gapic
|
|
103
97
|
end
|
104
98
|
end
|
105
99
|
|
106
|
-
##
|
107
|
-
# @return [Boolean] Whether method has body specified in proto
|
108
|
-
#
|
109
|
-
def body?
|
110
|
-
return false if @proto_method.http.nil?
|
111
|
-
|
112
|
-
!@proto_method.http.body.empty?
|
113
|
-
end
|
114
|
-
|
115
100
|
##
|
116
101
|
# Name of the variable to use for storing the body result of the transcoding call
|
117
102
|
# Normally "body" but use "_body" for discarding the result for
|
@@ -121,13 +106,6 @@ module Gapic
|
|
121
106
|
body? ? "body" : "_body"
|
122
107
|
end
|
123
108
|
|
124
|
-
##
|
125
|
-
# @return [String] A body specified for the given method in proto or an empty string if not specified
|
126
|
-
#
|
127
|
-
def body
|
128
|
-
@proto_method.http&.body || ""
|
129
|
-
end
|
130
|
-
|
131
109
|
##
|
132
110
|
# @return [Boolean] True if body contains full request object (`*` in the annotation), false otherwise
|
133
111
|
#
|
@@ -187,7 +165,80 @@ module Gapic
|
|
187
165
|
#
|
188
166
|
# @return [String]
|
189
167
|
def transcoding_helper_name
|
190
|
-
"transcode_#{
|
168
|
+
"transcode_#{name}_request"
|
169
|
+
end
|
170
|
+
|
171
|
+
##
|
172
|
+
# Method name
|
173
|
+
#
|
174
|
+
# @return [String]
|
175
|
+
#
|
176
|
+
def name
|
177
|
+
@main_method.name
|
178
|
+
end
|
179
|
+
|
180
|
+
##
|
181
|
+
# Full class name of the request type
|
182
|
+
#
|
183
|
+
# @return [String]
|
184
|
+
#
|
185
|
+
def request_type
|
186
|
+
@main_method.request_type
|
187
|
+
end
|
188
|
+
|
189
|
+
##
|
190
|
+
# Full class name of the raw return type of the RPC
|
191
|
+
#
|
192
|
+
# @return [String]
|
193
|
+
#
|
194
|
+
def return_type
|
195
|
+
@main_method.return_type
|
196
|
+
end
|
197
|
+
|
198
|
+
##
|
199
|
+
# Full class name of the return type of the method
|
200
|
+
# (including LRO and Paged cases)
|
201
|
+
#
|
202
|
+
# @return [String]
|
203
|
+
#
|
204
|
+
def doc_response_type
|
205
|
+
return "::Gapic::Rest::PagedEnumerable<#{pagination.paged_element_doc_type}>" if paged?
|
206
|
+
return "::Gapic::GenericLRO::Operation" if nonstandard_lro?
|
207
|
+
return_type
|
208
|
+
end
|
209
|
+
|
210
|
+
##
|
211
|
+
# Whether the REGAPIC method should be rendered as paged
|
212
|
+
#
|
213
|
+
# @return [Boolean]
|
214
|
+
#
|
215
|
+
def paged?
|
216
|
+
@pagination.paged?
|
217
|
+
end
|
218
|
+
|
219
|
+
##
|
220
|
+
# Whether this method uses nonstandard LROs
|
221
|
+
#
|
222
|
+
# @return [Boolean]
|
223
|
+
#
|
224
|
+
def nonstandard_lro?
|
225
|
+
@main_method.nonstandard_lro?
|
226
|
+
end
|
227
|
+
|
228
|
+
private
|
229
|
+
|
230
|
+
##
|
231
|
+
# @return [String] A method path or an empty string if not present
|
232
|
+
#
|
233
|
+
def path
|
234
|
+
@http.path
|
235
|
+
end
|
236
|
+
|
237
|
+
##
|
238
|
+
# @return [String] A body specified for the given method in proto or an empty string if not specified
|
239
|
+
#
|
240
|
+
def body
|
241
|
+
@http.body
|
191
242
|
end
|
192
243
|
end
|
193
244
|
end
|
@@ -33,6 +33,10 @@ module Gapic
|
|
33
33
|
@patterns.filter!(&:useful_for_helpers?)
|
34
34
|
end
|
35
35
|
|
36
|
+
def dup
|
37
|
+
ResourcePresenter.new @resource
|
38
|
+
end
|
39
|
+
|
36
40
|
def name
|
37
41
|
@resource.type.split("/").delete_if(&:empty?).last
|
38
42
|
end
|
@@ -62,6 +66,10 @@ module Gapic
|
|
62
66
|
attr_reader :pattern
|
63
67
|
attr_reader :path_string
|
64
68
|
|
69
|
+
def pattern_template
|
70
|
+
@parsed_pattern.template
|
71
|
+
end
|
72
|
+
|
65
73
|
def useful_for_helpers?
|
66
74
|
!@parsed_pattern.positional_segments? && !@parsed_pattern.nontrivial_pattern_segments?
|
67
75
|
end
|
@@ -0,0 +1,90 @@
|
|
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 Service
|
20
|
+
##
|
21
|
+
# Presenter for the generation of the client for nonstandard LROs
|
22
|
+
#
|
23
|
+
# @!attribute [r] service
|
24
|
+
# Full name of the service providing the nonstandard LRO functionality
|
25
|
+
# @return [String]
|
26
|
+
# @!attribute [r] client_class_name
|
27
|
+
# Full name of the class of the client of the service
|
28
|
+
# @return [String]
|
29
|
+
# @!attribute [r] client_class_docname
|
30
|
+
# Name of the class as it should appear in the documentation
|
31
|
+
# @return [String]
|
32
|
+
# @!attribute [r] client_var_name
|
33
|
+
# Name for the variable for the client of the service
|
34
|
+
# @return [String]
|
35
|
+
# @!attribute [r] require_str
|
36
|
+
# Path to `require` the client of the service
|
37
|
+
# @return [String]
|
38
|
+
# @!attribute [r] service_description
|
39
|
+
# The description to place in the comments to this client's
|
40
|
+
# attribute in the library services's client class
|
41
|
+
# @return [String]
|
42
|
+
# @!attribute [r] helper_type
|
43
|
+
# The type of a helper generated for this service if any
|
44
|
+
# @return [String. nil]
|
45
|
+
#
|
46
|
+
class LroClientPresenter
|
47
|
+
attr_reader :service
|
48
|
+
attr_reader :client_class_name
|
49
|
+
attr_reader :client_class_docname
|
50
|
+
attr_reader :client_var_name
|
51
|
+
attr_reader :require_str
|
52
|
+
attr_reader :service_description
|
53
|
+
attr_reader :helper_type
|
54
|
+
|
55
|
+
##
|
56
|
+
# @param service [String]
|
57
|
+
# Full name of the service providing the nonstandard LRO functionality
|
58
|
+
# @param client_class_name [String]
|
59
|
+
# Full name of the class of the client of the service
|
60
|
+
# @param client_class_docname [String]
|
61
|
+
# Name of the class as it should appear in the documentation
|
62
|
+
# @param client_var_name [String]
|
63
|
+
# Name for the variable for the client of the service
|
64
|
+
# @param require_str [String]
|
65
|
+
# Path to `require` the client of the service
|
66
|
+
# @param service_description [String]
|
67
|
+
# The description to place in the comments to this client's
|
68
|
+
# attribute in the library services's client class
|
69
|
+
# @param helper_type [String, nil]
|
70
|
+
# The type of a helper generated for this service if any
|
71
|
+
#
|
72
|
+
def initialize service:,
|
73
|
+
client_class_name:,
|
74
|
+
client_class_docname:,
|
75
|
+
client_var_name:,
|
76
|
+
require_str:,
|
77
|
+
service_description:,
|
78
|
+
helper_type: nil
|
79
|
+
@service = service
|
80
|
+
@client_class_name = client_class_name
|
81
|
+
@client_class_docname = client_class_docname
|
82
|
+
@client_var_name = client_var_name
|
83
|
+
@require_str = require_str
|
84
|
+
@service_description = service_description
|
85
|
+
@helper_type = helper_type
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|