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.
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
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ac1010a66ffc02b0775927f2d4407dbb28ad35ac6be10dafe5f59953b79afd34
4
- data.tar.gz: f30721b9e721bd6ae5ba2d17cbc0158dcd5983ea53d7b53128b029dc37245886
3
+ metadata.gz: 4a5c16d4ae2bf94ccb62b00d0a7cd0d35fbebc348072649684f7550950ef370d
4
+ data.tar.gz: 162528840170a3992fa85e76d17e6110779cad71d22e5c670cc07647e6c931e6
5
5
  SHA512:
6
- metadata.gz: d44bfe9a92b92b4417fdb59c8cf3fcc727d43fb83a66502e10c6689bf95d5934038d7c7928a6df4152a1e2f410699dc06708cd841f9538fa29a3a609388c9c9e
7
- data.tar.gz: 5c21836f4a939dd7d9b5bf6ac6ace693aa122c9d81eb3df3c44a1d55df29c9d2a74cc4b5823ba9f71809549ec108b97bbdc61f0c6675480233abd208498c31c0
6
+ metadata.gz: 9b0f283cae815e46051faed3bb47ce892772f3f8635b9ce85d6c1d1af7e7d66f87e5900079011abe356ff5f34e1a5e3b0a2bb5eb49d85237f47a695724b7acb1
7
+ data.tar.gz: d81fb0ca1e7787beb0dd886a2cf8e58ad53b05de862b73334e1f8eafb395de6d4f30538bd53b0ff27876c6e9d14d3dc4641297b6b669d6f99c193f80a925c71d
@@ -1,5 +1,53 @@
1
1
  # Release History for gapic-generator
2
2
 
3
+ ### 0.2.3 / 2020-04-06
4
+
5
+ * No changes
6
+
7
+ ### 0.2.2 / 2020-03-31
8
+
9
+ * Updates to common protos, especially core types which were more than a year old.
10
+
11
+ ### 0.2.1 / 2020-03-26
12
+
13
+ * Fix service address for LRO operation clients.
14
+ * Tweak sample task names for wrapper-gem Rakefiles.
15
+
16
+ ### 0.2.0 / 2020-03-23
17
+
18
+ Generation updates:
19
+
20
+ * Proto service documentation is rendered into client class YARD docs.
21
+ * Generated Apache license is now well-formatted markdown.
22
+ * YARD titles updated with the word "API".
23
+ * Tweaks to the default summary and description text.
24
+ * Generated rakefiles can run acceptance tests if present.
25
+ * Switch the order of summary and description in the readmes.
26
+ * Exempt a few more files (notably gemspec and rakefile) from rubocop.
27
+ * Several formatting tweaks, including removal of redundant whitespace.
28
+
29
+ Internal changes:
30
+
31
+ * New configuration allows path helpers to be generated from outputs.
32
+ * Moved presenters into lib so they can be changed/subclassed more easily.
33
+ * Several additions to GemPresenter to support new features.
34
+
35
+ ### 0.1.7 / 2020-03-18
36
+
37
+ * Path modules extend self so helpers can be invoked on them directly
38
+ * Trigger IAM dependency for IAM V1 files other than iam_policy.proto
39
+
40
+ ### 0.1.6 / 2020-03-17
41
+
42
+ * Generated libraries now depend on gapic-common 0.2
43
+ * Convert cross-reference syntax in proto docs to YARD cross-reference links.
44
+ * Preserve call options in LROs
45
+ * Fix implicit kwarg warnings under Ruby 2.7
46
+
47
+ ### 0.1.5 / 2020-03-13
48
+
49
+ * More improvements to escaping of curly braces.
50
+
3
51
  ### 0.1.4 / 2020-03-12
4
52
 
5
53
  * Fixed over-escaping of curly braces in preformatted blocks in the yardocs.
@@ -21,26 +21,26 @@ module Gapic
21
21
  # Various string formatting utils
22
22
  #
23
23
  module FormattingUtils
24
- @brace_detector = /\A([^`]*(`[^`]*`[^`]*)*[^`\\])?\{([\w,]+)\}(.*)\z/m
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
@@ -100,10 +103,58 @@ module Gapic
100
103
 
101
104
  def escape_line_braces line
102
105
  while (m = @brace_detector.match line)
103
- line = "#{m[1]}\\\\{#{m[3]}}#{m[4]}"
106
+ line = "#{m[:pre]}\\\\{#{m[:inside]}}#{m[:post]}"
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.4"
19
+ VERSION = "0.2.3"
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
@@ -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