gapic-generator 0.1.5 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (55) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +55 -0
  3. data/lib/gapic/formatting_utils.rb +63 -12
  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 +13 -14
  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 +176 -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 +80 -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 +306 -0
  21. data/lib/gapic/resource_lookup.rb +23 -38
  22. data/lib/gapic/schema/api.rb +70 -0
  23. data/lib/gapic/schema/loader.rb +9 -2
  24. data/lib/gapic/schema/wrappers.rb +134 -24
  25. data/templates/default/gem/entrypoint.erb +8 -0
  26. data/templates/default/gem/gemspec.erb +2 -2
  27. data/templates/default/gem/readme.erb +17 -3
  28. data/templates/default/gem/rubocop.erb +13 -41
  29. data/templates/default/helpers/filepath_helper.rb +2 -21
  30. data/templates/default/helpers/namespace_helper.rb +2 -27
  31. data/templates/default/layouts/_ruby.erb +1 -3
  32. data/templates/default/lib/_package.erb +17 -0
  33. data/templates/default/lib/_service.erb +32 -0
  34. data/templates/default/package.erb +5 -5
  35. data/templates/default/service.erb +5 -7
  36. data/templates/default/service/_helpers.erb +3 -0
  37. data/templates/default/service/client/_client.erb +7 -17
  38. data/templates/default/service/client/_operations.erb +0 -4
  39. data/templates/default/service/client/_paths.erb +1 -0
  40. data/templates/default/service/client/method/def/_options_defaults.erb +1 -1
  41. data/templates/default/service/client/method/def/_response_normal.erb +1 -1
  42. data/templates/default/service/client/method/docs/_request_normal.erb +10 -5
  43. data/templates/default/service/client/method/docs/_request_streaming.erb +1 -1
  44. metadata +20 -15
  45. data/templates/default/helpers/presenter_helper.rb +0 -24
  46. data/templates/default/helpers/presenters/field_presenter.rb +0 -146
  47. data/templates/default/helpers/presenters/file_presenter.rb +0 -53
  48. data/templates/default/helpers/presenters/gem_presenter.rb +0 -140
  49. data/templates/default/helpers/presenters/message_presenter.rb +0 -66
  50. data/templates/default/helpers/presenters/method_presenter.rb +0 -293
  51. data/templates/default/helpers/presenters/package_presenter.rb +0 -65
  52. data/templates/default/helpers/presenters/resource_presenter.rb +0 -92
  53. data/templates/default/helpers/presenters/sample_presenter.rb +0 -74
  54. data/templates/default/helpers/presenters/service_presenter.rb +0 -276
  55. data/templates/default/service/client/_helpers.erb +0 -9
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 87900df01c425c43c7c7ac1a46965b2324af78eb6c56b91e6cfe36eb0abf3d56
4
- data.tar.gz: 3f72d4b99665d5e235332854e4bbd4cc69f181e08e66fff9a2444cdbd9f44693
3
+ metadata.gz: c3adc22eae54587c0d4ddebad747dc1efb90ed8973c6a617a4df8f3120cee027
4
+ data.tar.gz: c7c531f3e6e0da489acc866000007bdcd7001e585f98763cf4eeeb68c677c627
5
5
  SHA512:
6
- metadata.gz: 89550d2af9728e7efdb9a3813fa50bf237dc8322057fce25653fba88aae3871672e50af88d0844e4c2ff34d725734236500e5c17cf0db889e0d517a67852760e
7
- data.tar.gz: 653271d51b4f3142d99b21cee2dff0146ddea8768a3d2d128cad0fc3914a498cac532223b53773145a33c57d5167059d1d2c8fd29b17b66d51bf7cb7c1d792d8
6
+ metadata.gz: 7c9181069a5107c008cb3c276420f0f36421e0ef3fe37ac63f10fc3c00a87bb7c80444c371a084c3b8dfcf19f79b5e32939f6c8a611a1956e9837e4d421296fb
7
+ data.tar.gz: 648db155b410c7613a8f67d53b9f1319b4e784e54baf4d3f238221b4de0526438d6279af3fc14a53d2f5e5bfd8d85f5a0eeefc6542d8d92fc502870ec9a4ad8d
@@ -1,5 +1,60 @@
1
1
  # Release History for gapic-generator
2
2
 
3
+ ### 0.3.0 / 2020-04-10
4
+
5
+ * Detect when a resource is referenced implicitly via child_type, and generate path helpers.
6
+ * Update grpc-google-iam-v1 dependency to require the latest version.
7
+ * Generated require graph is more sane and does not include cycles.
8
+ * The bundler entrypoint now loads the entire gem for wrapper gems.
9
+ * Generated readmes are more useful and include a quickstart.
10
+ * Package and service modules now have basic documentation.
11
+ * Overloads for methods now have basic explanatory documentation, including how to pass an empty request.
12
+ * Request object documentation no longer duplicates the method documentation.
13
+
14
+ ### 0.2.3 / 2020-04-06
15
+
16
+ * No changes
17
+
18
+ ### 0.2.2 / 2020-03-31
19
+
20
+ * Updates to common protos, especially core types which were more than a year old.
21
+
22
+ ### 0.2.1 / 2020-03-26
23
+
24
+ * Fix service address for LRO operation clients.
25
+ * Tweak sample task names for wrapper-gem Rakefiles.
26
+
27
+ ### 0.2.0 / 2020-03-23
28
+
29
+ Generation updates:
30
+
31
+ * Proto service documentation is rendered into client class YARD docs.
32
+ * Generated Apache license is now well-formatted markdown.
33
+ * YARD titles updated with the word "API".
34
+ * Tweaks to the default summary and description text.
35
+ * Generated rakefiles can run acceptance tests if present.
36
+ * Switch the order of summary and description in the readmes.
37
+ * Exempt a few more files (notably gemspec and rakefile) from rubocop.
38
+ * Several formatting tweaks, including removal of redundant whitespace.
39
+
40
+ Internal changes:
41
+
42
+ * New configuration allows path helpers to be generated from outputs.
43
+ * Moved presenters into lib so they can be changed/subclassed more easily.
44
+ * Several additions to GemPresenter to support new features.
45
+
46
+ ### 0.1.7 / 2020-03-18
47
+
48
+ * Path modules extend self so helpers can be invoked on them directly
49
+ * Trigger IAM dependency for IAM V1 files other than iam_policy.proto
50
+
51
+ ### 0.1.6 / 2020-03-17
52
+
53
+ * Generated libraries now depend on gapic-common 0.2
54
+ * Convert cross-reference syntax in proto docs to YARD cross-reference links.
55
+ * Preserve call options in LROs
56
+ * Fix implicit kwarg warnings under Ruby 2.7
57
+
3
58
  ### 0.1.5 / 2020-03-13
4
59
 
5
60
  * More improvements to escaping of curly braces.
@@ -22,25 +22,25 @@ module Gapic
22
22
  #
23
23
  module FormattingUtils
24
24
  @brace_detector = /\A(?<pre>[^`]*(`[^`]*`[^`]*)*[^`\\])?\{(?<inside>[^\s][^}]*)\}(?<post>.*)\z/m
25
+ @xref_detector = /\A(?<pre>[^`]*(`[^`]*`[^`]*)*)?\[(?<text>[\w\.]+)\]\[(?<addr>[\w\.]+)\](?<post>.*)\z/m
25
26
  @list_element_detector = /\A\s*(\*|\+|-|[0-9a-zA-Z]+\.)\s/
26
27
 
27
28
  class << self
28
29
  ##
29
- # Given an enumerable of lines, escape braces that look like yardoc type
30
- # links. Tries to be smart about handling only braces that would be
31
- # interpreted by yard (i.e. those that are not part of preformatted text
32
- # blocks).
30
+ # Given an enumerable of lines, performs yardoc formatting, including:
31
+ # * Interpreting cross-references identified as described in AIP 192
32
+ # * Escaping literal braces that look like yardoc type links
33
33
  #
34
+ # Tries to be smart about exempting preformatted text blocks.
35
+ #
36
+ # @param api [Gapic::Schema::Api]
34
37
  # @param lines [Enumerable<String>]
38
+ # @param disable_xrefs [Boolean] (default is `false`) Disable linking to
39
+ # cross-references, and render them simply as text. This can be used if
40
+ # it is known that the targets are not present in the current library.
35
41
  # @return [Enumerable<String>]
36
42
  #
37
- def escape_braces lines
38
- # This looks for braces that:
39
- # * Are opened and closed on the same line
40
- # * Are not nested
41
- # * Are not located between backticks
42
- # * Are not in a preformatted block
43
- #
43
+ def format_doc_lines api, lines, disable_xrefs: false
44
44
  # To detect preformatted blocks, this tracks the "expected" base indent
45
45
  # according to Markdown. Specifically, this is the effective indent of
46
46
  # previous block, which is normally 0 except if we're in a list item.
@@ -55,7 +55,10 @@ module Gapic
55
55
  in_block = nil
56
56
  else
57
57
  in_block, base_indent = update_indent_state in_block, base_indent, line, indent
58
- line = escape_line_braces line if in_block == false
58
+ if in_block == false
59
+ line = escape_line_braces line
60
+ line = format_line_xrefs api, line, disable_xrefs
61
+ end
59
62
  end
60
63
  line
61
64
  end
@@ -104,6 +107,54 @@ module Gapic
104
107
  end
105
108
  line
106
109
  end
110
+
111
+ def format_line_xrefs api, line, disable_xrefs
112
+ while (m = @xref_detector.match line)
113
+ entity = api.lookup m[:addr]
114
+ return line if entity.nil?
115
+ text = m[:text]
116
+ yard_link = disable_xrefs ? text : yard_link_for_entity(entity, text)
117
+ return line if yard_link.nil?
118
+ line = "#{m[:pre]}#{yard_link}#{m[:post]}"
119
+ end
120
+ line
121
+ end
122
+
123
+ ##
124
+ # Generate a YARD-style cross-reference for the given entity.
125
+ #
126
+ # @param entity [Gapic::Schema::Proto] the entity to link to
127
+ # @param text [String] the text for the link
128
+ # @return [String] YARD cross-reference syntax
129
+ #
130
+ def yard_link_for_entity entity, text
131
+ # As a special case, omit the service "google.longrunning.Operations"
132
+ # and its methods. This is because the generator creates
133
+ # service-specific copies of the operations client, rather than a
134
+ # Google::Longrunning::Operations::Client class, and there is in
135
+ # general no way to tell what the actual service-specific namespace is.
136
+ return text if entity.address[0, 3] == ["google", "longrunning", "Operations"]
137
+
138
+ case entity
139
+ when Gapic::Schema::Service
140
+ "{#{convert_address_to_ruby entity}::Client #{text}}"
141
+ when Gapic::Schema::Method
142
+ "{#{convert_address_to_ruby entity.parent}::Client##{entity.name.underscore} #{text}}"
143
+ when Gapic::Schema::Message, Gapic::Schema::Enum, Gapic::Schema::EnumValue
144
+ "{#{convert_address_to_ruby entity} #{text}}"
145
+ when Gapic::Schema::Field
146
+ "{#{convert_address_to_ruby entity.parent}##{entity.name} #{text}}"
147
+ end
148
+ end
149
+
150
+ def convert_address_to_ruby entity
151
+ file = entity.containing_file
152
+ api = file.containing_api
153
+ address = entity.address
154
+ address = address.join "." if address.is_a? Array
155
+ address = address.sub file.package, file.ruby_package if file.ruby_package&.present?
156
+ address.split(".").reject(&:empty?).map(&:camelize).map { |node| api.fix_namespace node }.join("::")
157
+ end
107
158
  end
108
159
  end
109
160
  end
@@ -16,6 +16,6 @@
16
16
 
17
17
  module Gapic
18
18
  module Generator
19
- VERSION = "0.1.5"
19
+ VERSION = "0.3.0"
20
20
  end
21
21
  end
@@ -55,14 +55,6 @@ module Gapic
55
55
  controller.class.all_helpers_from_path helpers_path
56
56
  end
57
57
 
58
- def use_helpers! *helper_methods
59
- helper_methods.each do |helper_method|
60
- define_singleton_method helper_method do |*args|
61
- controller.class.helpers.method(helper_method).call(*args)
62
- end
63
- end
64
- end
65
-
66
58
  def controller
67
59
  # Each controller gets a new class, so multiple generators can be
68
60
  # active at the same time without stomping on each other.
@@ -15,6 +15,7 @@
15
15
  # limitations under the License.
16
16
 
17
17
  require "gapic/generators/base_generator"
18
+ require "gapic/presenters"
18
19
 
19
20
  module Gapic
20
21
  module Generators
@@ -29,9 +30,6 @@ module Gapic
29
30
 
30
31
  # Configure to use a custom templates directory
31
32
  use_templates! File.join __dir__, "../../../templates/default"
32
-
33
- # Configure these helper method to be used by the generator
34
- use_helpers! :gem_presenter
35
33
  end
36
34
 
37
35
  # Disable Rubocop because we expect generate to grow and violate more
@@ -46,7 +44,7 @@ module Gapic
46
44
  def generate
47
45
  files = []
48
46
 
49
- gem = gem_presenter @api
47
+ gem = Gapic::Presenters.gem_presenter @api
50
48
 
51
49
  gem.packages.each do |package|
52
50
  # Package level files
@@ -65,16 +63,17 @@ module Gapic
65
63
  end
66
64
 
67
65
  # Gem level files
68
- files << g("gem/gitignore.erb", ".gitignore", gem: gem)
69
- files << g("gem/version.erb", "lib/#{gem.version_file_path}", gem: gem)
70
- files << g("gem/gemspec.erb", "#{gem.name}.gemspec", gem: gem)
71
- files << g("gem/gemfile.erb", "Gemfile", gem: gem)
72
- files << g("gem/rakefile.erb", "Rakefile", gem: gem)
73
- files << g("gem/readme.erb", "README.md", gem: gem)
74
- files << g("gem/changelog.erb", "CHANGELOG.md", gem: gem)
75
- files << g("gem/rubocop.erb", ".rubocop.yml", gem: gem)
76
- files << g("gem/yardopts.erb", ".yardopts", gem: gem)
77
- files << g("gem/license.erb", "LICENSE.md", gem: gem)
66
+ files << g("gem/gitignore.erb", ".gitignore", gem: gem)
67
+ files << g("gem/version.erb", "lib/#{gem.version_file_path}", gem: gem)
68
+ files << g("gem/gemspec.erb", "#{gem.name}.gemspec", gem: gem)
69
+ files << g("gem/gemfile.erb", "Gemfile", gem: gem)
70
+ files << g("gem/rakefile.erb", "Rakefile", gem: gem)
71
+ files << g("gem/readme.erb", "README.md", gem: gem)
72
+ files << g("gem/changelog.erb", "CHANGELOG.md", gem: gem)
73
+ files << g("gem/rubocop.erb", ".rubocop.yml", gem: gem)
74
+ files << g("gem/yardopts.erb", ".yardopts", gem: gem)
75
+ files << g("gem/license.erb", "LICENSE.md", gem: gem)
76
+ files << g("gem/entrypoint.erb", "lib/#{gem.name}.rb", gem: gem)
78
77
 
79
78
  gem.proto_files.each do |proto_file|
80
79
  files << g("proto_docs/proto_file.erb", "proto_docs/#{proto_file.docs_file_path}", file: proto_file)
@@ -0,0 +1,45 @@
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
+ module Gapic
20
+ module Helpers
21
+ ##
22
+ # Helpers related to generating paths to ruby files (e.g. for require)
23
+ #
24
+ module FilepathHelper
25
+ ##
26
+ # Converts a ruby namespace string to a file path string.
27
+ def ruby_file_path api, namespace
28
+ file_path = ruby_file_path_for_namespace namespace
29
+ fix_file_path api, file_path
30
+ end
31
+
32
+ ##
33
+ # Converts a ruby namespace string to a file path string.
34
+ def ruby_file_path_for_namespace namespace
35
+ ActiveSupport::Inflector.underscore namespace
36
+ end
37
+
38
+ ##
39
+ # Corrects a namespace by replacing known bad values with good values.
40
+ def fix_file_path api, file_path
41
+ file_path.split("/").map { |node| api.fix_file_path node }.join("/")
42
+ end
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,51 @@
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
+ module Gapic
20
+ module Helpers
21
+ ##
22
+ # Helpers related to generating ruby namespaces
23
+ #
24
+ module NamespaceHelper
25
+ ##
26
+ # Looks up the ruby_package for a dot-separated address string to a new string
27
+ # and creates the corrected Ruby namespace
28
+ def ruby_namespace api, address
29
+ file = api.file_for address
30
+ address = address.dup
31
+ address[file.package] = file.ruby_package if file.ruby_package.present?
32
+ namespace = ruby_namespace_for_address address
33
+ fix_namespace api, namespace
34
+ end
35
+
36
+ ##
37
+ # Converts an array or dot-separated address string to a new string with
38
+ # Ruby double-semicolon separators.
39
+ def ruby_namespace_for_address address
40
+ address = address.split "." if address.is_a? String
41
+ address.reject(&:empty?).map(&:camelize).join "::"
42
+ end
43
+
44
+ ##
45
+ # Corrects a namespace by replacing known bad values with good values.
46
+ def fix_namespace api, namespace
47
+ namespace.split("::").map { |node| api.fix_namespace node }.join("::")
48
+ end
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,44 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Copyright 2020 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 "gapic/presenters/enum_presenter"
18
+ require "gapic/presenters/enum_value_presenter"
19
+ require "gapic/presenters/field_presenter"
20
+ require "gapic/presenters/file_presenter"
21
+ require "gapic/presenters/gem_presenter"
22
+ require "gapic/presenters/message_presenter"
23
+ require "gapic/presenters/method_presenter"
24
+ require "gapic/presenters/package_presenter"
25
+ require "gapic/presenters/resource_presenter"
26
+ require "gapic/presenters/sample_presenter"
27
+ require "gapic/presenters/service_presenter"
28
+
29
+ module Gapic
30
+ ##
31
+ # A namespace for presenter classes.
32
+ #
33
+ module Presenters
34
+ ##
35
+ # Return a gem presenter
36
+ #
37
+ # @param api [Gapic::Schema::Api] The api schema object
38
+ # @return [Gapic::Presenters::GemPresenter]
39
+ #
40
+ def self.gem_presenter api
41
+ GemPresenter.new api
42
+ end
43
+ end
44
+ end
@@ -14,22 +14,27 @@
14
14
  # See the License for the specific language governing permissions and
15
15
  # limitations under the License.
16
16
 
17
- require_relative "enum_value_presenter"
17
+ module Gapic
18
+ module Presenters
19
+ ##
20
+ # A presenter for proto enums.
21
+ #
22
+ class EnumPresenter
23
+ def initialize enum
24
+ @enum = enum
25
+ end
18
26
 
19
- class EnumPresenter
20
- def initialize enum
21
- @enum = enum
22
- end
23
-
24
- def name
25
- @enum.name
26
- end
27
+ def name
28
+ @enum.name
29
+ end
27
30
 
28
- def doc_description
29
- @enum.docs_leading_comments
30
- end
31
+ def doc_description
32
+ @enum.docs_leading_comments
33
+ end
31
34
 
32
- def values
33
- @values ||= @enum.values.map { |v| EnumValuePresenter.new v }
35
+ def values
36
+ @values ||= @enum.values.map { |v| EnumValuePresenter.new v }
37
+ end
38
+ end
34
39
  end
35
40
  end
@@ -14,20 +14,27 @@
14
14
  # See the License for the specific language governing permissions and
15
15
  # limitations under the License.
16
16
 
17
- class EnumValuePresenter
18
- def initialize value
19
- @value = value
20
- end
17
+ module Gapic
18
+ module Presenters
19
+ ##
20
+ # A presenter for proto enum values.
21
+ #
22
+ class EnumValuePresenter
23
+ def initialize value
24
+ @value = value
25
+ end
21
26
 
22
- def name
23
- @value.name
24
- end
27
+ def name
28
+ @value.name
29
+ end
25
30
 
26
- def doc_description
27
- @value.docs_leading_comments
28
- end
31
+ def doc_description
32
+ @value.docs_leading_comments
33
+ end
29
34
 
30
- def number
31
- @value.number
35
+ def number
36
+ @value.number
37
+ end
38
+ end
32
39
  end
33
40
  end