gapic-generator 0.1.1 → 0.1.7

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 53e29f5e9a5cd2e6c4cf68d8e28fe095b5a0f5155f7c892f0b9b5429914b5dfb
4
- data.tar.gz: 5ea2ad00f9c340675f2bd4f1b16d02dbb5d2e2b7444b450d326993de263a1cc0
3
+ metadata.gz: 7758f2d15a52b89f57555f192cf9d477cbfdbd9788578ba30b5e04d9c468ed85
4
+ data.tar.gz: ef2c5bd9924646eea488db7060dc654dc0cc2ff2ad1d5736e4f04cad217e0fe4
5
5
  SHA512:
6
- metadata.gz: 8f975242f0242375263e065351763fb67594ba65fc571f882bb54ce1877a5e14ad1419ecaf75e5c58ea0c29c81f5e8becdef635f1013111b624acd3e06248e92
7
- data.tar.gz: 10abc98e678f667815d6e325cb27d582d4cbe27f4037edc66cde40ae8eb76b0d7b6fc884258d8ec5473612d327059baffbea94f3e9edf1ba83ae29f2d988e655
6
+ metadata.gz: 6d28f3903643f3b86770f83538dcaa669668bcd9f89e85592bbc6680c95c13fc043b323cf406fa0fa37b0ad0ad21ed30bb56ed42c7a2be0b423cbfc4c0b7c423
7
+ data.tar.gz: a98b3d1af7be74a680e0b738b4d0753130f90c51ef71fb181a94189d1806b947338558826cd3e4f5b8c3315897546d2e36a1ce5d99d58dd501fd5aa5e8c3a76d
@@ -1,5 +1,34 @@
1
1
  # Release History for gapic-generator
2
2
 
3
+ ### 0.1.7 / 2020-03-18
4
+
5
+ * Path modules extend self so helpers can be invoked on them directly
6
+ * Trigger IAM dependency for IAM V1 files other than iam_policy.proto
7
+
8
+ ### 0.1.6 / 2020-03-17
9
+
10
+ * Generated libraries now depend on gapic-common 0.2
11
+ * Convert cross-reference syntax in proto docs to YARD cross-reference links.
12
+ * Preserve call options in LROs
13
+ * Fix implicit kwarg warnings under Ruby 2.7
14
+
15
+ ### 0.1.5 / 2020-03-13
16
+
17
+ * More improvements to escaping of curly braces.
18
+
19
+ ### 0.1.4 / 2020-03-12
20
+
21
+ * Fixed over-escaping of curly braces in preformatted blocks in the yardocs.
22
+ * Fixed typo in authentication document.
23
+
24
+ ### 0.1.3 / 2020-03-11
25
+
26
+ * Generated numeric constants are formatted with underscores if necessary.
27
+
28
+ ### 0.1.2 / 2020-03-09
29
+
30
+ * Support multiple grpc service config files
31
+
3
32
  ### 0.1.1 / 2020-03-09
4
33
 
5
34
  * Relax rake dependency.
@@ -0,0 +1,155 @@
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 "bigdecimal"
18
+
19
+ module Gapic
20
+ ##
21
+ # Various string formatting utils
22
+ #
23
+ module FormattingUtils
24
+ @brace_detector = /\A(?<pre>[^`]*(`[^`]*`[^`]*)*[^`\\])?\{(?<inside>[^\s][^}]*)\}(?<post>.*)\z/m
25
+ @xref_detector = /\A(?<pre>[^`]*(`[^`]*`[^`]*)*)?\[(?<text>[\w\.]+)\]\[(?<addr>[\w\.]+)\](?<post>.*)\z/m
26
+ @list_element_detector = /\A\s*(\*|\+|-|[0-9a-zA-Z]+\.)\s/
27
+
28
+ class << self
29
+ ##
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
+ #
34
+ # Tries to be smart about exempting preformatted text blocks.
35
+ #
36
+ # @param lines [Enumerable<String>]
37
+ # @return [Enumerable<String>]
38
+ #
39
+ def format_doc_lines api, lines
40
+ # To detect preformatted blocks, this tracks the "expected" base indent
41
+ # according to Markdown. Specifically, this is the effective indent of
42
+ # previous block, which is normally 0 except if we're in a list item.
43
+ # Then, if a block is indented at least 4 spaces past that expected
44
+ # indent (and as long as it remains so), those lines are considered
45
+ # preformatted.
46
+ in_block = nil
47
+ base_indent = 0
48
+ lines.map do |line|
49
+ indent = line_indent line
50
+ if indent.nil?
51
+ in_block = nil
52
+ else
53
+ in_block, base_indent = update_indent_state in_block, base_indent, line, indent
54
+ if in_block == false
55
+ line = escape_line_braces line
56
+ line = format_line_xrefs api, line
57
+ end
58
+ end
59
+ line
60
+ end
61
+ end
62
+
63
+ ##
64
+ # Given a number, format it in such a way that Rubocop will be happy.
65
+ # Specifically, we add underscores if the magnitude is at least 10_000.
66
+ # This works for both integers and floats.
67
+ #
68
+ # @param value [Numeric]
69
+ # @return [String]
70
+ #
71
+ def format_number value
72
+ return value.to_s if value.abs < 10_000
73
+ str = value.is_a?(Integer) ? value.to_s : BigDecimal(value.to_f.to_s).to_s("F")
74
+ re = /^(-?\d+)(\d\d\d)([_\.][_\.\d]+)?$/
75
+ while (m = re.match str)
76
+ str = "#{m[1]}_#{m[2]}#{m[3]}"
77
+ end
78
+ str
79
+ end
80
+
81
+ private
82
+
83
+ def update_indent_state in_block, base_indent, line, indent
84
+ if in_block != true && @list_element_detector =~ line
85
+ in_block = false
86
+ indent = base_indent if indent > base_indent
87
+ base_indent = (indent + 7) / 4 * 4
88
+ else
89
+ in_block = indent >= base_indent + 4 unless in_block == false
90
+ base_indent = indent / 4 * 4 if in_block == false && indent < base_indent
91
+ end
92
+ [in_block, base_indent]
93
+ end
94
+
95
+ def line_indent line
96
+ m = /^( *)\S/.match line
97
+ m.nil? ? nil : m[1].length
98
+ end
99
+
100
+ def escape_line_braces line
101
+ while (m = @brace_detector.match line)
102
+ line = "#{m[:pre]}\\\\{#{m[:inside]}}#{m[:post]}"
103
+ end
104
+ line
105
+ end
106
+
107
+ def format_line_xrefs api, line
108
+ while (m = @xref_detector.match line)
109
+ entity = api.lookup m[:addr]
110
+ return line if entity.nil?
111
+ yard_link = yard_link_for_entity entity, m[:text]
112
+ return line if yard_link.nil?
113
+ line = "#{m[:pre]}#{yard_link}#{m[:post]}"
114
+ end
115
+ line
116
+ end
117
+
118
+ ##
119
+ # Generate a YARD-style cross-reference for the given entity.
120
+ #
121
+ # @param entity [Gapic::Schema::Proto] the entity to link to
122
+ # @param text [String] the text for the link
123
+ # @return [String] YARD cross-reference syntax
124
+ #
125
+ def yard_link_for_entity entity, text
126
+ # As a special case, omit the service "google.longrunning.Operations"
127
+ # and its methods. This is because the generator creates
128
+ # service-specific copies of the operations client, rather than a
129
+ # Google::Longrunning::Operations::Client class, and there is in
130
+ # general no way to tell what the actual service-specific namespace is.
131
+ return text if entity.address[0, 3] == ["google", "longrunning", "Operations"]
132
+
133
+ case entity
134
+ when Gapic::Schema::Service
135
+ "{#{convert_address_to_ruby entity}::Client #{text}}"
136
+ when Gapic::Schema::Method
137
+ "{#{convert_address_to_ruby entity.parent}::Client##{entity.name.underscore} #{text}}"
138
+ when Gapic::Schema::Message, Gapic::Schema::Enum, Gapic::Schema::EnumValue
139
+ "{#{convert_address_to_ruby entity} #{text}}"
140
+ when Gapic::Schema::Field
141
+ "{#{convert_address_to_ruby entity.parent}##{entity.name} #{text}}"
142
+ end
143
+ end
144
+
145
+ def convert_address_to_ruby entity
146
+ file = entity.containing_file
147
+ api = file.containing_api
148
+ address = entity.address
149
+ address = address.join "." if address.is_a? Array
150
+ address = address.sub file.package, file.ruby_package if file.ruby_package&.present?
151
+ address.split(".").reject(&:empty?).map(&:camelize).map { |node| api.fix_namespace node }.join("::")
152
+ end
153
+ end
154
+ end
155
+ end
@@ -16,6 +16,6 @@
16
16
 
17
17
  module Gapic
18
18
  module Generator
19
- VERSION = "0.1.1"
19
+ VERSION = "0.1.7"
20
20
  end
21
21
  end
@@ -53,6 +53,14 @@ module Gapic
53
53
  @files.each { |f| f.parent = self }
54
54
  end
55
55
 
56
+ def containing_api
57
+ self
58
+ end
59
+
60
+ def containing_file
61
+ nil
62
+ end
63
+
56
64
  def lookup address
57
65
  address = address.join "." if address.is_a? Array
58
66
  @files.each do |f|
@@ -200,16 +208,14 @@ module Gapic
200
208
  end
201
209
  end
202
210
 
203
- # Raw parsed json of the grpc service config if provided
204
- # or an empty hash if config was not provided
211
+ # Raw parsed json of the combined grpc service config files if provided
212
+ # or an empty hash if no config was provided
205
213
  def grpc_service_config_raw
206
214
  @grpc_service_config_raw ||= begin
207
- grpc_service_config_filename = protoc_options["grpc_service_config"]
208
- if grpc_service_config_filename
209
- file = ::File.read grpc_service_config_filename
210
- JSON.parse file
211
- else
212
- {}
215
+ filenames = protoc_options["grpc_service_config"].to_s.split ";"
216
+ filenames.inject({}) do |running_hash, filename|
217
+ file_hash = JSON.parse ::File.read filename
218
+ deep_merge running_hash, file_hash
213
219
  end
214
220
  end
215
221
  end
@@ -252,6 +258,8 @@ module Gapic
252
258
  left.merge right do |_k, lt, rt|
253
259
  if lt.is_a?(Hash) && rt.is_a?(Hash)
254
260
  deep_merge lt, rt
261
+ elsif lt.is_a?(Array) && rt.is_a?(Array)
262
+ lt + rt
255
263
  else
256
264
  rt
257
265
  end
@@ -14,6 +14,8 @@
14
14
  # See the License for the specific language governing permissions and
15
15
  # limitations under the License.
16
16
 
17
+ require "gapic/formatting_utils"
18
+
17
19
  module Gapic
18
20
  module Schema
19
21
  # Base class for all generic proto types including: enums, messages,
@@ -93,18 +95,27 @@ module Gapic
93
95
  @docs = docs
94
96
  end
95
97
 
98
+ # Returns the "root" of this schema.
99
+ # @return [Gapic::Schema::Api]
100
+ def containing_api
101
+ parent&.containing_api
102
+ end
103
+
104
+ # Returns the file containing this proto entity
105
+ # @return [Gapic::Schema::File]
106
+ def containing_file
107
+ parent&.containing_file
108
+ end
109
+
96
110
  # Gets the cleaned up leading comments documentation
97
111
  def docs_leading_comments
98
112
  return nil if @docs.nil?
99
113
  return nil if @docs.leading_comments.empty?
100
114
 
101
- @docs
102
- .leading_comments
103
- .each_line
104
- .map { |line| line.start_with?(" ") ? line[1..-1] : line }
105
- .join
106
- .split("{").join("\\\\\\{") # The only safe way to replace with \ characters...
107
- .split("}").join("\\}")
115
+ lines = @docs.leading_comments.each_line.to_a
116
+ lines.map! { |line| line.start_with?(" ") ? line[1..-1] : line }
117
+ lines = FormattingUtils.format_doc_lines containing_api, lines
118
+ lines.join
108
119
  end
109
120
 
110
121
  # @!method path
@@ -377,6 +388,10 @@ module Gapic
377
388
  @services.each { |m| m.parent = self }
378
389
  end
379
390
 
391
+ def containing_file
392
+ self
393
+ end
394
+
380
395
  def lookup address
381
396
  address = address.split(".").reject(&:empty?).join(".")
382
397
  @registry[address]
@@ -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 -%>
@@ -16,3 +16,5 @@ pkg/*
16
16
  # Ignore files commonly present in certain dev environments
17
17
  .vagrant
18
18
  .DS_STORE
19
+ .idea
20
+ *.iml
@@ -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
@@ -15,6 +15,7 @@
15
15
  # limitations under the License.
16
16
 
17
17
  require "active_support/inflector"
18
+ require "gapic/formatting_utils"
18
19
 
19
20
  module DefaultHelper
20
21
  def prepend_with input, prepend
@@ -39,6 +40,10 @@ module DefaultHelper
39
40
  input.lines[0] + indent(input.lines[1..-1].join, spacing)
40
41
  end
41
42
 
43
+ def format_number value
44
+ Gapic::FormattingUtils.format_number value
45
+ end
46
+
42
47
  def assert_locals *locals
43
48
  locals.each { |local| raise "missing local in template" if local.nil? }
44
49
  end
@@ -114,7 +114,7 @@ class GemPresenter
114
114
  end
115
115
 
116
116
  def iam_dependency?
117
- @api.files.map(&:name).include? "google/iam/v1/iam_policy.proto"
117
+ @api.files.map(&:name).any? { |f| f.start_with? "google/iam/v1/" }
118
118
  end
119
119
 
120
120
  private
@@ -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
@@ -3,7 +3,7 @@
3
3
  <%- if service.grpc_service_config && !service.grpc_service_config.empty? -%>
4
4
 
5
5
  <%- if service.grpc_service_config.timeout_seconds -%>
6
- default_config.timeout = <%= service.grpc_service_config.timeout_seconds %>
6
+ default_config.timeout = <%= format_number service.grpc_service_config.timeout_seconds %>
7
7
  <%- end -%>
8
8
  <%- if service.grpc_service_config.retry_policy -%>
9
9
  default_config.retry_policy = <%= indent_tail render(partial: "service/client/self_configure_retry_policy", locals: { retry_policy: service.grpc_service_config.retry_policy }), 2 %>
@@ -13,7 +13,7 @@
13
13
  <%- if method.grpc_service_config && !method.grpc_service_config.empty? -%>
14
14
 
15
15
  <%- if method.grpc_service_config.timeout_seconds -%>
16
- default_config.rpcs.<%= method.name %>.timeout = <%= method.grpc_service_config.timeout_seconds %>
16
+ default_config.rpcs.<%= method.name %>.timeout = <%= format_number method.grpc_service_config.timeout_seconds %>
17
17
  <%- end -%>
18
18
  <%- if method.grpc_service_config.retry_policy -%>
19
19
  default_config.rpcs.<%= method.name %>.retry_policy =<%= indent_tail render(partial: "service/client/self_configure_retry_policy", locals: { retry_policy: method.grpc_service_config.retry_policy }), 2 %>
@@ -1,13 +1,13 @@
1
1
  <%- assert_locals retry_policy -%>
2
2
  {
3
3
  <%- if retry_policy.initial_delay_seconds -%>
4
- initial_delay: <%= retry_policy.initial_delay_seconds %>,
4
+ initial_delay: <%= format_number retry_policy.initial_delay_seconds %>,
5
5
  <%- end -%>
6
6
  <%- if retry_policy.max_delay_seconds -%>
7
- max_delay: <%= retry_policy.max_delay_seconds %>,
7
+ max_delay: <%= format_number retry_policy.max_delay_seconds %>,
8
8
  <%- end -%>
9
9
  <%- if retry_policy.multiplier -%>
10
- multiplier: <%= retry_policy.multiplier %>,
10
+ multiplier: <%= format_number retry_policy.multiplier %>,
11
11
  <%- end-%>
12
12
  <%- if retry_policy.status_codes -%>
13
13
  retry_codes: <%= retry_policy.status_codes %>
@@ -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.1
4
+ version: 0.1.7
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-09 00:00:00.000000000 Z
13
+ date: 2020-03-18 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: actionpack
@@ -204,6 +204,7 @@ files:
204
204
  - gem_templates/test_helper.erb
205
205
  - gem_templates/version.erb
206
206
  - lib/gapic/file_formatter.rb
207
+ - lib/gapic/formatting_utils.rb
207
208
  - lib/gapic/gem_builder.rb
208
209
  - lib/gapic/generator.rb
209
210
  - lib/gapic/generator/version.rb