gapic-generator 0.1.4 → 0.2.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +48 -0
- data/lib/gapic/formatting_utils.rb +65 -14
- data/lib/gapic/generator/version.rb +1 -1
- data/lib/gapic/generators/base_generator.rb +0 -8
- data/lib/gapic/generators/default_generator.rb +2 -4
- data/lib/gapic/helpers/filepath_helper.rb +45 -0
- data/lib/gapic/helpers/namespace_helper.rb +51 -0
- data/lib/gapic/presenters.rb +44 -0
- data/{templates/default/helpers → lib/gapic}/presenters/enum_presenter.rb +19 -14
- data/{templates/default/helpers → lib/gapic}/presenters/enum_value_presenter.rb +19 -12
- data/lib/gapic/presenters/field_presenter.rb +154 -0
- data/lib/gapic/presenters/file_presenter.rb +59 -0
- data/lib/gapic/presenters/gem_presenter.rb +172 -0
- data/lib/gapic/presenters/message_presenter.rb +73 -0
- data/lib/gapic/presenters/method_presenter.rb +307 -0
- data/lib/gapic/presenters/package_presenter.rb +72 -0
- data/lib/gapic/presenters/resource_presenter.rb +99 -0
- data/lib/gapic/presenters/sample_presenter.rb +84 -0
- data/lib/gapic/presenters/service_presenter.rb +298 -0
- data/lib/gapic/resource_lookup.rb +8 -1
- data/lib/gapic/schema/api.rb +24 -0
- data/lib/gapic/schema/wrappers.rb +25 -2
- data/templates/default/gem/gemspec.erb +1 -1
- data/templates/default/gem/readme.erb +2 -2
- data/templates/default/gem/rubocop.erb +2 -0
- data/templates/default/helpers/filepath_helper.rb +2 -21
- data/templates/default/helpers/namespace_helper.rb +2 -27
- data/templates/default/layouts/_ruby.erb +1 -3
- data/templates/default/service/client/_client.erb +7 -1
- data/templates/default/service/client/_paths.erb +1 -0
- data/templates/default/service/client/method/def/_options_defaults.erb +1 -1
- data/templates/default/service/client/method/def/_response_normal.erb +1 -1
- metadata +16 -14
- data/templates/default/helpers/presenter_helper.rb +0 -24
- data/templates/default/helpers/presenters/field_presenter.rb +0 -146
- data/templates/default/helpers/presenters/file_presenter.rb +0 -53
- data/templates/default/helpers/presenters/gem_presenter.rb +0 -140
- data/templates/default/helpers/presenters/message_presenter.rb +0 -66
- data/templates/default/helpers/presenters/method_presenter.rb +0 -293
- data/templates/default/helpers/presenters/package_presenter.rb +0 -65
- data/templates/default/helpers/presenters/resource_presenter.rb +0 -92
- data/templates/default/helpers/presenters/sample_presenter.rb +0 -74
- data/templates/default/helpers/presenters/service_presenter.rb +0 -276
@@ -1,74 +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 "active_support/inflector"
|
18
|
-
|
19
|
-
class SamplePresenter
|
20
|
-
def initialize api, sample_config
|
21
|
-
@api = api
|
22
|
-
@sample_config = sample_config
|
23
|
-
end
|
24
|
-
|
25
|
-
def description
|
26
|
-
@sample_config["description"]
|
27
|
-
end
|
28
|
-
|
29
|
-
def input_parameters
|
30
|
-
@sample_config["request"].select { |f| f.key? "input_parameter" }.map { |f| RequestField.new f }
|
31
|
-
end
|
32
|
-
|
33
|
-
def fields
|
34
|
-
dotted_hash = @sample_config["request"].each_with_object({}) do |f, memo|
|
35
|
-
memo[f["field"]] = f
|
36
|
-
end
|
37
|
-
dotted_hash.each_with_object({}) do |(path, f), memo|
|
38
|
-
parts = path.split "."
|
39
|
-
leaf_hash = parts[0...-1].inject(memo) { |h, k| h[k] ||= {} }
|
40
|
-
leaf_hash[parts.last] = RequestField.new f
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
|
-
def kwargs
|
45
|
-
fields.keys.map { |k| "#{k}: #{k}" }.join ", "
|
46
|
-
end
|
47
|
-
|
48
|
-
def response_raw
|
49
|
-
@sample_config["response"]
|
50
|
-
end
|
51
|
-
|
52
|
-
class RequestField
|
53
|
-
attr_reader :field, :value, :input_parameter, :comment, :value_is_file
|
54
|
-
def initialize field
|
55
|
-
@field = field["field"]
|
56
|
-
@value = convert field["value"]
|
57
|
-
@input_parameter = field["input_parameter"]
|
58
|
-
@comment = field["comment"]
|
59
|
-
@comment = nil if @comment&.empty?
|
60
|
-
@value_is_file = field["value_is_file"]
|
61
|
-
end
|
62
|
-
|
63
|
-
protected
|
64
|
-
|
65
|
-
def convert val
|
66
|
-
if val.is_a? String
|
67
|
-
return ":#{val}" if val =~ /\A[A-Z_0-9]+\z/ # print constants as symbols
|
68
|
-
val.inspect
|
69
|
-
else
|
70
|
-
val.to_s
|
71
|
-
end
|
72
|
-
end
|
73
|
-
end
|
74
|
-
end
|
@@ -1,276 +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 "active_support/inflector"
|
18
|
-
require_relative "gem_presenter"
|
19
|
-
require_relative "package_presenter"
|
20
|
-
require_relative "resource_presenter"
|
21
|
-
require_relative "method_presenter"
|
22
|
-
|
23
|
-
class ServicePresenter
|
24
|
-
include FilepathHelper
|
25
|
-
include NamespaceHelper
|
26
|
-
|
27
|
-
def initialize api, service
|
28
|
-
@api = api
|
29
|
-
@service = service
|
30
|
-
end
|
31
|
-
|
32
|
-
def gem
|
33
|
-
GemPresenter.new @api
|
34
|
-
end
|
35
|
-
|
36
|
-
def file
|
37
|
-
FilePresenter.new @api, @service.parent
|
38
|
-
end
|
39
|
-
|
40
|
-
def package
|
41
|
-
PackagePresenter.new @api, @service.parent.package
|
42
|
-
end
|
43
|
-
|
44
|
-
def methods
|
45
|
-
@methods ||= begin
|
46
|
-
@service.methods.map { |m| MethodPresenter.new @api, m }
|
47
|
-
end
|
48
|
-
end
|
49
|
-
|
50
|
-
def address
|
51
|
-
@service.address
|
52
|
-
end
|
53
|
-
|
54
|
-
def namespace
|
55
|
-
return @service.ruby_package if @service.ruby_package.present?
|
56
|
-
|
57
|
-
namespace = ruby_namespace_for_address @service.address[0...-1]
|
58
|
-
fix_namespace @api, namespace
|
59
|
-
end
|
60
|
-
|
61
|
-
def version
|
62
|
-
ActiveSupport::Inflector.camelize @service.address[-2]
|
63
|
-
end
|
64
|
-
|
65
|
-
def name
|
66
|
-
@service.name
|
67
|
-
end
|
68
|
-
|
69
|
-
def proto_service_name_full
|
70
|
-
fix_namespace @api, "#{namespace}::#{name}"
|
71
|
-
end
|
72
|
-
|
73
|
-
def proto_service_file_path
|
74
|
-
@service.parent.name.sub ".proto", "_pb.rb"
|
75
|
-
end
|
76
|
-
|
77
|
-
def proto_service_file_name
|
78
|
-
proto_service_file_path.split("/").last
|
79
|
-
end
|
80
|
-
|
81
|
-
def proto_service_require
|
82
|
-
proto_service_file_path.sub ".rb", ""
|
83
|
-
end
|
84
|
-
|
85
|
-
def proto_services_file_path
|
86
|
-
@service.parent.name.sub ".proto", "_services_pb.rb"
|
87
|
-
end
|
88
|
-
|
89
|
-
def proto_services_file_name
|
90
|
-
proto_services_file_path.split("/").last
|
91
|
-
end
|
92
|
-
|
93
|
-
def proto_services_require
|
94
|
-
proto_services_file_path.sub ".rb", ""
|
95
|
-
end
|
96
|
-
|
97
|
-
def proto_service_stub_name_full
|
98
|
-
"#{proto_service_name_full}::Stub"
|
99
|
-
end
|
100
|
-
|
101
|
-
def service_file_path
|
102
|
-
service_require + ".rb"
|
103
|
-
end
|
104
|
-
|
105
|
-
def service_file_name
|
106
|
-
service_file_path.split("/").last
|
107
|
-
end
|
108
|
-
|
109
|
-
def service_require
|
110
|
-
ruby_file_path @api, proto_service_name_full
|
111
|
-
end
|
112
|
-
|
113
|
-
def client_name
|
114
|
-
"Client"
|
115
|
-
end
|
116
|
-
|
117
|
-
def client_name_full
|
118
|
-
fix_namespace @api, "#{proto_service_name_full}::#{client_name}"
|
119
|
-
end
|
120
|
-
|
121
|
-
def client_require
|
122
|
-
ruby_file_path @api, client_name_full
|
123
|
-
end
|
124
|
-
|
125
|
-
def client_file_path
|
126
|
-
client_require + ".rb"
|
127
|
-
end
|
128
|
-
|
129
|
-
def client_file_name
|
130
|
-
client_file_path.split("/").last
|
131
|
-
end
|
132
|
-
|
133
|
-
def client_endpoint
|
134
|
-
@service.host || default_config(:default_host) || "localhost"
|
135
|
-
end
|
136
|
-
|
137
|
-
def client_scopes
|
138
|
-
@service.scopes || default_config(:oauth_scopes)
|
139
|
-
end
|
140
|
-
|
141
|
-
def client_proto_name
|
142
|
-
@service.address.join "."
|
143
|
-
end
|
144
|
-
|
145
|
-
def credentials_name
|
146
|
-
"Credentials"
|
147
|
-
end
|
148
|
-
|
149
|
-
def credentials_name_full
|
150
|
-
fix_namespace @api, "#{proto_service_name_full}::#{credentials_name}"
|
151
|
-
end
|
152
|
-
|
153
|
-
def credentials_file_path
|
154
|
-
credentials_require + ".rb"
|
155
|
-
end
|
156
|
-
|
157
|
-
def credentials_file_name
|
158
|
-
credentials_file_path.split("/").last
|
159
|
-
end
|
160
|
-
|
161
|
-
def credentials_require
|
162
|
-
ruby_file_path @api, credentials_name_full
|
163
|
-
end
|
164
|
-
|
165
|
-
def helpers_file_path
|
166
|
-
helpers_require + ".rb"
|
167
|
-
end
|
168
|
-
|
169
|
-
def helpers_file_name
|
170
|
-
"helpers.rb"
|
171
|
-
end
|
172
|
-
|
173
|
-
def helpers_require
|
174
|
-
ruby_file_path @api, "#{proto_service_name_full}::Helpers"
|
175
|
-
end
|
176
|
-
|
177
|
-
def references
|
178
|
-
@references ||= @service.resources.map { |resource| ResourcePresenter.new resource }.sort_by(&:name)
|
179
|
-
end
|
180
|
-
|
181
|
-
def paths?
|
182
|
-
references.any?
|
183
|
-
end
|
184
|
-
|
185
|
-
def paths_name
|
186
|
-
"Paths"
|
187
|
-
end
|
188
|
-
|
189
|
-
def paths_name_full
|
190
|
-
fix_namespace @api, "#{proto_service_name_full}::#{paths_name}"
|
191
|
-
end
|
192
|
-
|
193
|
-
def paths_file_path
|
194
|
-
paths_require + ".rb"
|
195
|
-
end
|
196
|
-
|
197
|
-
def paths_file_name
|
198
|
-
paths_file_path.split("/").last
|
199
|
-
end
|
200
|
-
|
201
|
-
def paths_require
|
202
|
-
ruby_file_path @api, "#{proto_service_name_full}::#{paths_name}"
|
203
|
-
end
|
204
|
-
|
205
|
-
def test_client_file_path
|
206
|
-
service_file_path.sub ".rb", "_test.rb"
|
207
|
-
end
|
208
|
-
|
209
|
-
def test_client_operations_file_path
|
210
|
-
service_file_path.sub ".rb", "_operations_test.rb"
|
211
|
-
end
|
212
|
-
|
213
|
-
def stub_name
|
214
|
-
"#{ActiveSupport::Inflector.underscore name}_stub"
|
215
|
-
end
|
216
|
-
|
217
|
-
def lro?
|
218
|
-
methods.find(&:lro?)
|
219
|
-
end
|
220
|
-
|
221
|
-
def lro_client_var
|
222
|
-
"operations_client"
|
223
|
-
end
|
224
|
-
|
225
|
-
def lro_client_ivar
|
226
|
-
"@#{lro_client_var}"
|
227
|
-
end
|
228
|
-
|
229
|
-
def operations_name
|
230
|
-
"Operations"
|
231
|
-
end
|
232
|
-
|
233
|
-
def operations_name_full
|
234
|
-
fix_namespace @api, "#{proto_service_name_full}::#{operations_name}"
|
235
|
-
end
|
236
|
-
|
237
|
-
def operations_file_path
|
238
|
-
operations_require + ".rb"
|
239
|
-
end
|
240
|
-
|
241
|
-
def operations_file_name
|
242
|
-
operations_file_path.split("/").last
|
243
|
-
end
|
244
|
-
|
245
|
-
def operations_require
|
246
|
-
ruby_file_path @api, "#{proto_service_name_full}::#{operations_name}"
|
247
|
-
end
|
248
|
-
|
249
|
-
def lro_service
|
250
|
-
lro = @service.parent.parent.files.find { |file| file.name == "google/longrunning/operations.proto" }
|
251
|
-
|
252
|
-
return ServicePresenter.new @api, lro.services.first unless lro.nil?
|
253
|
-
end
|
254
|
-
|
255
|
-
def config_channel_args
|
256
|
-
{ "grpc.service_config_disable_resolution" => 1 }
|
257
|
-
end
|
258
|
-
|
259
|
-
def grpc_service_config
|
260
|
-
return unless @api.grpc_service_config&.service_level_configs&.key? grpc_full_name
|
261
|
-
@api.grpc_service_config.service_level_configs[grpc_full_name]
|
262
|
-
end
|
263
|
-
|
264
|
-
def grpc_full_name
|
265
|
-
@service.address.join "."
|
266
|
-
end
|
267
|
-
|
268
|
-
private
|
269
|
-
|
270
|
-
def default_config key
|
271
|
-
return unless @service.parent.parent.configuration[:defaults]
|
272
|
-
return unless @service.parent.parent.configuration[:defaults][:service]
|
273
|
-
|
274
|
-
@service.parent.parent.configuration[:defaults][:service][key]
|
275
|
-
end
|
276
|
-
end
|