gapic-generator 0.1.7 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (39) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +19 -0
  3. data/lib/gapic/formatting_utils.rb +9 -4
  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 +170 -0
  15. data/lib/gapic/presenters/message_presenter.rb +73 -0
  16. data/lib/gapic/presenters/method_presenter.rb +298 -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 +297 -0
  21. data/lib/gapic/resource_lookup.rb +8 -1
  22. data/lib/gapic/schema/api.rb +16 -0
  23. data/lib/gapic/schema/wrappers.rb +9 -2
  24. data/templates/default/gem/readme.erb +2 -2
  25. data/templates/default/helpers/filepath_helper.rb +2 -21
  26. data/templates/default/helpers/namespace_helper.rb +2 -27
  27. data/templates/default/layouts/_ruby.erb +1 -3
  28. data/templates/default/service/client/_client.erb +7 -1
  29. metadata +16 -14
  30. data/templates/default/helpers/presenter_helper.rb +0 -24
  31. data/templates/default/helpers/presenters/field_presenter.rb +0 -146
  32. data/templates/default/helpers/presenters/file_presenter.rb +0 -53
  33. data/templates/default/helpers/presenters/gem_presenter.rb +0 -140
  34. data/templates/default/helpers/presenters/message_presenter.rb +0 -66
  35. data/templates/default/helpers/presenters/method_presenter.rb +0 -293
  36. data/templates/default/helpers/presenters/package_presenter.rb +0 -65
  37. data/templates/default/helpers/presenters/resource_presenter.rb +0 -92
  38. data/templates/default/helpers/presenters/sample_presenter.rb +0 -74
  39. data/templates/default/helpers/presenters/service_presenter.rb +0 -276
@@ -42,7 +42,14 @@ module Gapic
42
42
  def service_resource_types
43
43
  @service_resource_types ||= begin
44
44
  @service.methods.flat_map do |method|
45
- message_resource_types method.input
45
+ input_resource_types = message_resource_types method.input
46
+
47
+ if @api.generate_path_helpers_output?
48
+ output_resource_types = message_resource_types method.output
49
+ input_resource_types + output_resource_types
50
+ else
51
+ input_resource_types
52
+ end
46
53
  end.uniq
47
54
  end
48
55
  end
@@ -208,6 +208,22 @@ module Gapic
208
208
  end
209
209
  end
210
210
 
211
+ # Whether the generate_path_helpers_output parameter was given in the configuration
212
+ def generate_path_helpers_output_defined?
213
+ configuration.key? :generate_path_helpers_output
214
+ end
215
+
216
+ # Sets the generate_path_helpers_output parameter in the configuration
217
+ def generate_path_helpers_output= value
218
+ configuration[:generate_path_helpers_output] = value
219
+ end
220
+
221
+ # Whether to generate path helpers for output as well as input messages
222
+ def generate_path_helpers_output?
223
+ # if not set in configuration, false by default
224
+ configuration[:generate_path_helpers_output] ||= false
225
+ end
226
+
211
227
  # Raw parsed json of the combined grpc service config files if provided
212
228
  # or an empty hash if no config was provided
213
229
  def grpc_service_config_raw
@@ -107,14 +107,21 @@ module Gapic
107
107
  parent&.containing_file
108
108
  end
109
109
 
110
+ ##
110
111
  # Gets the cleaned up leading comments documentation
111
- def docs_leading_comments
112
+ #
113
+ # @param disable_xrefs [Boolean] (default is `false`) Disable linking to
114
+ # cross-references, and render them simply as text. This can be used if
115
+ # it is known that the targets are not present in the current library.
116
+ # @return [String]
117
+ #
118
+ def docs_leading_comments disable_xrefs: false
112
119
  return nil if @docs.nil?
113
120
  return nil if @docs.leading_comments.empty?
114
121
 
115
122
  lines = @docs.leading_comments.each_line.to_a
116
123
  lines.map! { |line| line.start_with?(" ") ? line[1..-1] : line }
117
- lines = FormattingUtils.format_doc_lines containing_api, lines
124
+ lines = FormattingUtils.format_doc_lines containing_api, lines, disable_xrefs: disable_xrefs
118
125
  lines.join
119
126
  end
120
127
 
@@ -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
@@ -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 %>
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.7
4
+ version: 0.2.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: 2020-03-18 00:00:00.000000000 Z
13
+ date: 2020-03-23 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