gapic-generator 0.1.4 → 0.2.3

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 (44) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +48 -0
  3. data/lib/gapic/formatting_utils.rb +65 -14
  4. data/lib/gapic/generator/version.rb +1 -1
  5. data/lib/gapic/generators/base_generator.rb +0 -8
  6. data/lib/gapic/generators/default_generator.rb +2 -4
  7. data/lib/gapic/helpers/filepath_helper.rb +45 -0
  8. data/lib/gapic/helpers/namespace_helper.rb +51 -0
  9. data/lib/gapic/presenters.rb +44 -0
  10. data/{templates/default/helpers → lib/gapic}/presenters/enum_presenter.rb +19 -14
  11. data/{templates/default/helpers → lib/gapic}/presenters/enum_value_presenter.rb +19 -12
  12. data/lib/gapic/presenters/field_presenter.rb +154 -0
  13. data/lib/gapic/presenters/file_presenter.rb +59 -0
  14. data/lib/gapic/presenters/gem_presenter.rb +172 -0
  15. data/lib/gapic/presenters/message_presenter.rb +73 -0
  16. data/lib/gapic/presenters/method_presenter.rb +307 -0
  17. data/lib/gapic/presenters/package_presenter.rb +72 -0
  18. data/lib/gapic/presenters/resource_presenter.rb +99 -0
  19. data/lib/gapic/presenters/sample_presenter.rb +84 -0
  20. data/lib/gapic/presenters/service_presenter.rb +298 -0
  21. data/lib/gapic/resource_lookup.rb +8 -1
  22. data/lib/gapic/schema/api.rb +24 -0
  23. data/lib/gapic/schema/wrappers.rb +25 -2
  24. data/templates/default/gem/gemspec.erb +1 -1
  25. data/templates/default/gem/readme.erb +2 -2
  26. data/templates/default/gem/rubocop.erb +2 -0
  27. data/templates/default/helpers/filepath_helper.rb +2 -21
  28. data/templates/default/helpers/namespace_helper.rb +2 -27
  29. data/templates/default/layouts/_ruby.erb +1 -3
  30. data/templates/default/service/client/_client.erb +7 -1
  31. data/templates/default/service/client/_paths.erb +1 -0
  32. data/templates/default/service/client/method/def/_options_defaults.erb +1 -1
  33. data/templates/default/service/client/method/def/_response_normal.erb +1 -1
  34. metadata +16 -14
  35. data/templates/default/helpers/presenter_helper.rb +0 -24
  36. data/templates/default/helpers/presenters/field_presenter.rb +0 -146
  37. data/templates/default/helpers/presenters/file_presenter.rb +0 -53
  38. data/templates/default/helpers/presenters/gem_presenter.rb +0 -140
  39. data/templates/default/helpers/presenters/message_presenter.rb +0 -66
  40. data/templates/default/helpers/presenters/method_presenter.rb +0 -293
  41. data/templates/default/helpers/presenters/package_presenter.rb +0 -65
  42. data/templates/default/helpers/presenters/resource_presenter.rb +0 -92
  43. data/templates/default/helpers/presenters/sample_presenter.rb +0 -74
  44. data/templates/default/helpers/presenters/service_presenter.rb +0 -276
@@ -23,7 +23,7 @@ Gem::Specification.new do |gem|
23
23
 
24
24
  gem.required_ruby_version = ">= 2.4"
25
25
 
26
- gem.add_dependency "gapic-common", "~> 0.1.0"
26
+ gem.add_dependency "gapic-common", "~> 0.2"
27
27
  <%- if gem.iam_dependency? -%>
28
28
  gem.add_dependency "grpc-google-iam-v1", "~> 0.6.9"
29
29
  <%- end -%>
@@ -1,9 +1,9 @@
1
1
  # <%= gem.title %>
2
2
 
3
- <%= gem.description %>
4
-
5
3
  <%= gem.summary %>
6
4
 
5
+ <%= gem.description %>
6
+
7
7
  <%= gem.homepage %>
8
8
 
9
9
  ## Installation
@@ -57,3 +57,5 @@ Style/CaseEquality:
57
57
  - "lib/<%= service.client_file_path.sub "client.rb", "*.rb" %>"
58
58
  <%- end -%>
59
59
  <%- end -%>
60
+ Style/ModuleFunction:
61
+ Enabled: false
@@ -14,25 +14,6 @@
14
14
  # See the License for the specific language governing permissions and
15
15
  # limitations under the License.
16
16
 
17
- require "active_support/inflector"
17
+ require "gapic/helpers/filepath_helper"
18
18
 
19
- module FilepathHelper
20
- ##
21
- # Converts a ruby namespace string to a file path string.
22
- def ruby_file_path api, namespace
23
- file_path = ruby_file_path_for_namespace namespace
24
- fix_file_path api, file_path
25
- end
26
-
27
- ##
28
- # Converts a ruby namespace string to a file path string.
29
- def ruby_file_path_for_namespace namespace
30
- ActiveSupport::Inflector.underscore namespace
31
- end
32
-
33
- ##
34
- # Corrects a namespace by replacing known bad values with good values.
35
- def fix_file_path api, file_path
36
- file_path.split("/").map { |node| api.fix_file_path node }.join("/")
37
- end
38
- end
19
+ FilepathHelper = Gapic::Helpers::FilepathHelper
@@ -14,31 +14,6 @@
14
14
  # See the License for the specific language governing permissions and
15
15
  # limitations under the License.
16
16
 
17
- require "active_support/inflector"
17
+ require "gapic/helpers/namespace_helper"
18
18
 
19
- module NamespaceHelper
20
- ##
21
- # Looks up the ruby_package for a dot-separated address string to a new string
22
- # and creates the corrected Ruby namespace
23
- def ruby_namespace api, address
24
- file = api.file_for address
25
- address = address.dup
26
- address[file.package] = file.ruby_package if file.ruby_package.present?
27
- namespace = ruby_namespace_for_address address
28
- fix_namespace api, namespace
29
- end
30
-
31
- ##
32
- # Converts an array or dot-separated address string to a new string with
33
- # Ruby double-semicolon separators.
34
- def ruby_namespace_for_address address
35
- address = address.split "." if address.is_a? String
36
- address.reject(&:empty?).map(&:camelize).join "::"
37
- end
38
-
39
- ##
40
- # Corrects a namespace by replacing known bad values with good values.
41
- def fix_namespace api, namespace
42
- namespace.split("::").map { |node| api.fix_namespace node }.join("::")
43
- end
44
- end
19
+ NamespaceHelper = Gapic::Helpers::NamespaceHelper
@@ -1,11 +1,9 @@
1
1
  <%- assert_locals namespace -%>
2
2
  <%= render partial: "shared/header" -%>
3
- <%- if instance_variable_defined? :@requires -%>
4
3
 
4
+ <%- if instance_variable_defined? :@requires -%>
5
5
  <%= @requires -%>
6
6
  <%- end -%>
7
- <%- # Two newlines here so YARD won't use the header as documentation -%>
8
-
9
7
 
10
8
  <%- namespace.split("::").each_with_index do |ns, i| -%>
11
9
  <%= indent "module #{ns}", i*2 %>
@@ -15,7 +15,13 @@ require "<%= service.paths_require %>"
15
15
  require "<%= service.operations_require %>"
16
16
  <%- end -%>
17
17
  <% end %>
18
- # Service that implements <%= service.name %> API.
18
+ ##
19
+ # Client for the <%= service.name %> service.
20
+ #
21
+ <%- if service.doc_description -%>
22
+ <%= indent service.doc_description, "# " %>
23
+ #
24
+ <%- end -%>
19
25
  class <%= service.client_name %>
20
26
  <%- if service.paths? -%>
21
27
  include <%= service.paths_name %>
@@ -5,4 +5,5 @@ module Paths
5
5
  <%= indent render(partial: "service/client/resource", locals: { resource: resource }), 2 %>
6
6
 
7
7
  <%- end %>
8
+ extend self
8
9
  end
@@ -1,6 +1,6 @@
1
1
  <%- assert_locals method -%>
2
2
  # Converts hash and nil to an options object
3
- options = Gapic::CallOptions.new options.to_h if options.respond_to? :to_h
3
+ options = Gapic::CallOptions.new(**options.to_h) if options.respond_to? :to_h
4
4
 
5
5
  # Customize the options with defaults
6
6
  metadata = @config.rpcs.<%= method.name %>.metadata.to_h
@@ -1,7 +1,7 @@
1
1
  <%- assert_locals method -%>
2
2
  @<%= method.service.stub_name %>.call_rpc :<%= method.name %>, request, options: options do |response, operation|
3
3
  <%- if method.lro? -%>
4
- response = Gapic::Operation.new response, <%= method.service.lro_client_ivar %>
4
+ response = Gapic::Operation.new response, <%= method.service.lro_client_ivar %>, options: options
5
5
  <%- end -%>
6
6
  yield response, operation if block_given?
7
7
  return response
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.1.4
4
+ version: 0.2.3
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-03-12 00:00:00.000000000 Z
13
+ date: 2020-04-06 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: actionpack
@@ -215,9 +215,23 @@ files:
215
215
  - lib/gapic/grpc_service_config/parsing_error.rb
216
216
  - lib/gapic/grpc_service_config/retry_policy.rb
217
217
  - lib/gapic/grpc_service_config/service_config.rb
218
+ - lib/gapic/helpers/filepath_helper.rb
219
+ - lib/gapic/helpers/namespace_helper.rb
218
220
  - lib/gapic/path_template.rb
219
221
  - lib/gapic/path_template/parser.rb
220
222
  - lib/gapic/path_template/segment.rb
223
+ - lib/gapic/presenters.rb
224
+ - lib/gapic/presenters/enum_presenter.rb
225
+ - lib/gapic/presenters/enum_value_presenter.rb
226
+ - lib/gapic/presenters/field_presenter.rb
227
+ - lib/gapic/presenters/file_presenter.rb
228
+ - lib/gapic/presenters/gem_presenter.rb
229
+ - lib/gapic/presenters/message_presenter.rb
230
+ - lib/gapic/presenters/method_presenter.rb
231
+ - lib/gapic/presenters/package_presenter.rb
232
+ - lib/gapic/presenters/resource_presenter.rb
233
+ - lib/gapic/presenters/sample_presenter.rb
234
+ - lib/gapic/presenters/service_presenter.rb
221
235
  - lib/gapic/resource_lookup.rb
222
236
  - lib/gapic/runner.rb
223
237
  - lib/gapic/schema.rb
@@ -249,18 +263,6 @@ files:
249
263
  - templates/default/helpers/default_helper.rb
250
264
  - templates/default/helpers/filepath_helper.rb
251
265
  - templates/default/helpers/namespace_helper.rb
252
- - templates/default/helpers/presenter_helper.rb
253
- - templates/default/helpers/presenters/enum_presenter.rb
254
- - templates/default/helpers/presenters/enum_value_presenter.rb
255
- - templates/default/helpers/presenters/field_presenter.rb
256
- - templates/default/helpers/presenters/file_presenter.rb
257
- - templates/default/helpers/presenters/gem_presenter.rb
258
- - templates/default/helpers/presenters/message_presenter.rb
259
- - templates/default/helpers/presenters/method_presenter.rb
260
- - templates/default/helpers/presenters/package_presenter.rb
261
- - templates/default/helpers/presenters/resource_presenter.rb
262
- - templates/default/helpers/presenters/sample_presenter.rb
263
- - templates/default/helpers/presenters/service_presenter.rb
264
266
  - templates/default/layouts/_ruby.erb
265
267
  - templates/default/package.erb
266
268
  - templates/default/proto_docs/_enum.erb
@@ -1,24 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- # Copyright 2018 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 "presenters/gem_presenter"
19
-
20
- module PresenterHelper
21
- def gem_presenter api
22
- GemPresenter.new api
23
- end
24
- end
@@ -1,146 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- # Copyright 2018 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 FieldPresenter
20
- include NamespaceHelper
21
-
22
- def initialize api, message, field
23
- @api = api
24
- @message = message
25
- @field = field
26
- end
27
-
28
- def name
29
- @field.name
30
- end
31
-
32
- def doc_types
33
- field_doc_types @field, false
34
- end
35
-
36
- def doc_attribute_type
37
- mode = @field.output_only? ? "r" : "rw"
38
- "@!attribute [#{mode}] #{@field.name}"
39
- end
40
-
41
- def output_doc_types
42
- field_doc_types @field, true
43
- end
44
-
45
- def doc_description
46
- @field.docs_leading_comments
47
- end
48
-
49
- def default_value
50
- single = default_singular_value
51
- return "[#{single}]" if @field.repeated? && !@field.map?
52
- single
53
- end
54
-
55
- def as_kwarg value: nil
56
- "#{name}: #{value || name}"
57
- end
58
-
59
- # TODO: remove, only used in tests
60
- def type_name
61
- @field.type_name
62
- end
63
-
64
- def type_name_full
65
- return nil if type_name.blank?
66
- ruby_namespace @api, type_name
67
- end
68
-
69
- def message?
70
- @field.message?
71
- end
72
-
73
- def enum?
74
- @field.enum?
75
- end
76
-
77
- def repeated?
78
- @field.repeated?
79
- end
80
-
81
- def map?
82
- @field.map?
83
- end
84
-
85
- protected
86
-
87
- def field_doc_types field, output
88
- return field_map_type field.message, output if field.map?
89
- base_type =
90
- if field.message?
91
- type = message_ruby_type field.message
92
- output ? type : "#{type} | Hash"
93
- elsif field.enum?
94
- # TODO: handle when arg message is nil and enum is the type
95
- message_ruby_type field.enum
96
- else
97
- case field.type
98
- when 1, 2 then "Float"
99
- when 3, 4, 5, 6, 7, 13, 15, 16, 17, 18 then "Integer"
100
- when 9, 12 then "String"
101
- when 8 then "Boolean"
102
- else
103
- "Object"
104
- end
105
- end
106
- field.repeated? ? "Array<#{base_type}>" : base_type
107
- end
108
-
109
- def field_map_type entry_message, output
110
- key_field = value_field = nil
111
- entry_message.fields.each do |field|
112
- key_field = field if field.name == "key"
113
- value_field = field if field.name == "value"
114
- end
115
- class_name = output ? "Google::Protobuf::Map" : "Hash"
116
- if key_field && value_field
117
- key_type = field_doc_types key_field, output
118
- value_type = field_doc_types value_field, output
119
- "#{class_name}{#{key_type} => #{value_type}}"
120
- else
121
- class_name
122
- end
123
- end
124
-
125
- def default_singular_value
126
- if @field.message?
127
- "{}"
128
- elsif @field.enum?
129
- # TODO: select the first non-0 enum value
130
- ":#{@field.enum.values.first.name}"
131
- else
132
- case @field.type
133
- when 1, 2 then "3.5"
134
- when 3, 4, 5, 6, 7, 13, 15, 16, 17, 18 then "42"
135
- when 9, 12 then "\"hello world\""
136
- when 8 then "true"
137
- else
138
- "Object"
139
- end
140
- end
141
- end
142
-
143
- def message_ruby_type message
144
- ruby_namespace @api, message.address.join(".")
145
- end
146
- end
@@ -1,53 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- # Copyright 2018 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_relative "enum_presenter"
18
- require_relative "message_presenter"
19
-
20
- class FilePresenter
21
- include NamespaceHelper
22
-
23
- # @param file [Gapic::Schema::File] the file to present
24
- def initialize api, file
25
- @api = api
26
- @file = file
27
- end
28
-
29
- def name
30
- @file.name
31
- end
32
-
33
- def address
34
- @file.address
35
- end
36
-
37
- def namespace
38
- return @file.ruby_package if @file.ruby_package.present?
39
- ruby_namespace_for_address address
40
- end
41
-
42
- def messages
43
- @messages ||= @file.messages.map { |m| MessagePresenter.new @api, m }
44
- end
45
-
46
- def enums
47
- @enums ||= @file.enums.map { |e| EnumPresenter.new e }
48
- end
49
-
50
- def docs_file_path
51
- @file.name.gsub ".proto", ".rb"
52
- end
53
- end
@@ -1,140 +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_relative "file_presenter"
18
- require_relative "package_presenter"
19
- require_relative "service_presenter"
20
-
21
- class GemPresenter
22
- include FilepathHelper
23
- include NamespaceHelper
24
-
25
- def initialize api
26
- @api = api
27
- end
28
-
29
- def packages
30
- @packages ||= begin
31
- packages = @api.generate_files.map(&:package).uniq.sort
32
- packages.map { |p| PackagePresenter.new @api, p }.delete_if(&:empty?)
33
- end
34
- end
35
-
36
- def services
37
- @services ||= begin
38
- files = @api.generate_files
39
- files.map(&:services).flatten.map { |s| ServicePresenter.new @api, s }
40
- end
41
- end
42
-
43
- def proto_files
44
- @proto_files ||= begin
45
- files = @api.files
46
- files = files.reject { |f| blacklist_protos.include? f.name }
47
- files = files.reject { |f| f.messages.empty? && f.enums.empty? }
48
- files.map { |f| FilePresenter.new @api, f }
49
- end
50
- end
51
-
52
- def address
53
- name.split("-").map(&:camelize)
54
- end
55
-
56
- def name
57
- gem_config :name
58
- end
59
-
60
- def namespace
61
- gem_config(:namespace) ||
62
- fix_namespace(@api, name.split("-").map(&:camelize).join("::"))
63
- end
64
-
65
- def title
66
- gem_config(:title) ||
67
- namespace.split("::").join(" ")
68
- end
69
-
70
- def version
71
- gem_config(:version) ||
72
- "0.0.1"
73
- end
74
-
75
- def version_require
76
- ruby_file_path @api, version_name_full
77
- end
78
-
79
- def version_file_path
80
- "#{version_require}.rb"
81
- end
82
-
83
- def version_name_full
84
- "#{namespace}::VERSION"
85
- end
86
-
87
- def authors
88
- gem_config(:authors) ||
89
- ["Google LLC"]
90
- end
91
-
92
- def email
93
- gem_config(:email) ||
94
- "googleapis-packages@google.com"
95
- end
96
-
97
- def description
98
- gem_config(:description) ||
99
- "#{name} is the official library for #{title} API."
100
- end
101
-
102
- def summary
103
- gem_config(:summary) ||
104
- "API Client library for #{title} API"
105
- end
106
-
107
- def homepage
108
- gem_config(:homepage) ||
109
- "https://github.com/googleapis/googleapis"
110
- end
111
-
112
- def env_prefix
113
- (gem_config(:env_prefix) || name.split("-").last).upcase
114
- end
115
-
116
- def iam_dependency?
117
- @api.files.map(&:name).include? "google/iam/v1/iam_policy.proto"
118
- end
119
-
120
- private
121
-
122
- def gem_config key
123
- return unless @api.configuration[:gem]
124
-
125
- @api.configuration[:gem][key]
126
- end
127
-
128
- def blacklist_protos
129
- blacklist = gem_config :blacklist
130
-
131
- return default_blacklist_protos if blacklist.nil?
132
- return default_blacklist_protos if blacklist[:protos].nil?
133
-
134
- default_blacklist_protos[:protos]
135
- end
136
-
137
- def default_blacklist_protos
138
- ["google/api/http.proto", "google/protobuf/descriptor.proto"]
139
- end
140
- end