gapic-generator 0.6.0 → 0.6.5
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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +30 -0
- data/gem_templates/entrypoint.erb +1 -0
- data/gem_templates/gemspec.erb +0 -1
- data/lib/gapic/file_formatter.rb +1 -2
- data/lib/gapic/generator/version.rb +1 -1
- data/lib/gapic/{path_template.rb → path_pattern.rb} +9 -8
- data/lib/gapic/path_pattern/parser.rb +146 -0
- data/lib/gapic/path_pattern/pattern.rb +80 -0
- data/lib/gapic/path_pattern/segment.rb +276 -0
- data/lib/gapic/presenters/field_presenter.rb +12 -0
- data/lib/gapic/presenters/gem_presenter.rb +16 -2
- data/lib/gapic/presenters/method_presenter.rb +7 -3
- data/lib/gapic/presenters/resource_presenter.rb +23 -31
- data/lib/gapic/presenters/service_presenter.rb +2 -1
- data/lib/gapic/runner.rb +3 -1
- data/lib/gapic/schema/api.rb +17 -1
- data/lib/gapic/schema/wrappers.rb +24 -20
- data/lib/gapic/uri_template.rb +36 -0
- data/lib/gapic/uri_template/parser.rb +50 -0
- data/lib/google/protobuf/compiler/plugin.pb.rb +5 -1
- data/lib/google/protobuf/descriptor.pb.rb +1 -0
- data/templates/default/gem/gemfile.erb +0 -3
- data/templates/default/gem/readme.erb +1 -1
- data/templates/default/service/client/resource/_doc.erb +1 -1
- data/templates/default/service/client/resource/_multi.erb +4 -0
- data/templates/default/service/test/client.erb +1 -3
- data/templates/default/service/test/client_operations.erb +1 -3
- data/templates/default/service/test/client_paths.erb +1 -3
- data/templates/default/service/test/method/_bidi.erb +10 -2
- data/templates/default/service/test/method/_client.erb +10 -2
- data/templates/default/service/test/method/_normal.erb +6 -0
- data/templates/default/service/test/method/_server.erb +9 -1
- data/templates/default/service/test/method/_setup.erb +2 -2
- metadata +10 -21
- data/lib/gapic/path_template/parser.rb +0 -83
- data/lib/gapic/path_template/segment.rb +0 -74
@@ -16,7 +16,7 @@ $ gem install <%= gem.name %>
|
|
16
16
|
|
17
17
|
```ruby
|
18
18
|
require "<%= gem.entrypoint_require %>"
|
19
|
-
<%- service = gem.
|
19
|
+
<%- service = gem.first_non_common_service -%>
|
20
20
|
<%- method = service&.methods.first -%>
|
21
21
|
<%- if service && method -%>
|
22
22
|
|
@@ -13,7 +13,11 @@ def <%= resource.path_helper %> **args
|
|
13
13
|
<%- last_pattern_index = resource.patterns.count - 1 -%>
|
14
14
|
<%- resource.patterns.each_with_index do |pattern, index| -%>
|
15
15
|
<%- comma = last_pattern_index == index ? "" : "," -%>
|
16
|
+
<%- if pattern.formal_arguments.empty? -%>
|
17
|
+
<%= pattern.arguments_key.inspect %> => (proc do
|
18
|
+
<%- else -%>
|
16
19
|
<%= pattern.arguments_key.inspect %> => (proc do |<%= pattern.formal_arguments %>|
|
20
|
+
<%- end -%>
|
17
21
|
<%= indent render(partial: "service/client/resource/def", locals: { pattern: pattern }), 6 %>
|
18
22
|
end)<%= comma %>
|
19
23
|
<%- end -%>
|
@@ -86,13 +86,21 @@ def test_<%= method.name %>
|
|
86
86
|
request.to_a.each do |r|
|
87
87
|
assert_kind_of <%= method.request_type %>, r
|
88
88
|
<%- fields.each do |field| -%>
|
89
|
-
<%- if field.message? && field.repeated? -%>
|
90
|
-
assert_kind_of <%= field.type_name_full %>,
|
89
|
+
<%- if field.message? && field.repeated? && !field.map? -%>
|
90
|
+
assert_kind_of <%= field.type_name_full %>, r.<%= field.name %>.first
|
91
|
+
<%- elsif field.map? -%>
|
92
|
+
assert_equal(<%= field.default_value %>, r.<%= field.name %>.to_h)
|
91
93
|
<%- elsif field.message? -%>
|
92
94
|
assert_equal Gapic::Protobuf.coerce(<%= field.default_value %>, to: <%= field.type_name_full %>), r.<%= field.name %>
|
93
95
|
<%- else -%>
|
94
96
|
assert_equal <%= field.default_value %>, r.<%= field.name %>
|
95
97
|
<%- end -%>
|
98
|
+
<%- if field.oneof? && !field.proto3_optional? -%>
|
99
|
+
assert_equal :<%= field.name %>, r.<%= field.oneof_name %>
|
100
|
+
<%- end -%>
|
101
|
+
<%- if field.proto3_optional? -%>
|
102
|
+
assert r.has_<%= field.name %>?
|
103
|
+
<%- end -%>
|
96
104
|
<%- end -%>
|
97
105
|
end
|
98
106
|
end
|
@@ -70,13 +70,21 @@ def test_<%= method.name %>
|
|
70
70
|
request.to_a.each do |r|
|
71
71
|
assert_kind_of <%= method.request_type %>, r
|
72
72
|
<%- fields.each do |field| -%>
|
73
|
-
<%- if field.message? && field.repeated? -%>
|
74
|
-
assert_kind_of <%= field.type_name_full %>,
|
73
|
+
<%- if field.message? && field.repeated? && !field.map? -%>
|
74
|
+
assert_kind_of <%= field.type_name_full %>, r.<%= field.name %>.first
|
75
|
+
<%- elsif field.map? -%>
|
76
|
+
assert_equal(<%= field.default_value %>, r.<%= field.name %>.to_h)
|
75
77
|
<%- elsif field.message? -%>
|
76
78
|
assert_equal Gapic::Protobuf.coerce(<%= field.default_value %>, to: <%= field.type_name_full %>), r.<%= field.name %>
|
77
79
|
<%- else -%>
|
78
80
|
assert_equal <%= field.default_value %>, r.<%= field.name %>
|
79
81
|
<%- end -%>
|
82
|
+
<%- if field.oneof? && !field.proto3_optional? -%>
|
83
|
+
assert_equal :<%= field.name %>, r.<%= field.oneof_name %>
|
84
|
+
<%- end -%>
|
85
|
+
<%- if field.proto3_optional? -%>
|
86
|
+
assert r.has_<%= field.name %>?
|
87
|
+
<%- end -%>
|
80
88
|
<%- end -%>
|
81
89
|
end
|
82
90
|
end
|
@@ -26,6 +26,12 @@ def test_<%= method.name %>
|
|
26
26
|
<%- else -%>
|
27
27
|
assert_equal <%= field.default_value %>, request.<%= field.name %>
|
28
28
|
<%- end -%>
|
29
|
+
<%- if field.oneof? && !field.proto3_optional? -%>
|
30
|
+
assert_equal :<%= field.name %>, request.<%= field.oneof_name %>
|
31
|
+
<%- end -%>
|
32
|
+
<%- if field.proto3_optional? -%>
|
33
|
+
assert request.has_<%= field.name %>?
|
34
|
+
<%- end -%>
|
29
35
|
<%- end -%>
|
30
36
|
refute_nil options
|
31
37
|
end
|
@@ -17,13 +17,21 @@ def test_<%= method.name %>
|
|
17
17
|
assert_equal :<%= method.name %>, name
|
18
18
|
assert_kind_of <%= method.request_type %>, request
|
19
19
|
<%- fields.each do |field| -%>
|
20
|
-
<%- if field.message? && field.repeated? -%>
|
20
|
+
<%- if field.message? && field.repeated? && !field.map? -%>
|
21
21
|
assert_kind_of <%= field.type_name_full %>, request.<%= field.name %>.first
|
22
|
+
<%- elsif field.map? -%>
|
23
|
+
assert_equal(<%= field.default_value %>, request.<%= field.name %>.to_h)
|
22
24
|
<%- elsif field.message? -%>
|
23
25
|
assert_equal Gapic::Protobuf.coerce(<%= field.default_value %>, to: <%= field.type_name_full %>), request.<%= field.name %>
|
24
26
|
<%- else -%>
|
25
27
|
assert_equal <%= field.default_value %>, request.<%= field.name %>
|
26
28
|
<%- end -%>
|
29
|
+
<%- if field.oneof? && !field.proto3_optional? -%>
|
30
|
+
assert_equal :<%= field.name %>, request.<%= field.oneof_name %>
|
31
|
+
<%- end -%>
|
32
|
+
<%- if field.proto3_optional? -%>
|
33
|
+
assert request.has_<%= field.name %>?
|
34
|
+
<%- end -%>
|
27
35
|
<%- end -%>
|
28
36
|
refute_nil options
|
29
37
|
end
|
@@ -9,10 +9,10 @@ class ClientStub
|
|
9
9
|
@requests = []
|
10
10
|
end
|
11
11
|
|
12
|
-
def call_rpc *args
|
12
|
+
def call_rpc *args, **kwargs
|
13
13
|
@call_rpc_count += 1
|
14
14
|
|
15
|
-
@requests << @block&.call(*args)
|
15
|
+
@requests << @block&.call(*args, **kwargs)
|
16
16
|
|
17
17
|
yield @response, @operation if block_given?
|
18
18
|
|
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.6.
|
4
|
+
version: 0.6.5
|
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-
|
13
|
+
date: 2020-07-20 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: actionpack
|
@@ -40,20 +40,6 @@ dependencies:
|
|
40
40
|
- - "~>"
|
41
41
|
- !ruby/object:Gem::Version
|
42
42
|
version: '3.8'
|
43
|
-
- !ruby/object:Gem::Dependency
|
44
|
-
name: bundler
|
45
|
-
requirement: !ruby/object:Gem::Requirement
|
46
|
-
requirements:
|
47
|
-
- - "~>"
|
48
|
-
- !ruby/object:Gem::Version
|
49
|
-
version: '2.1'
|
50
|
-
type: :development
|
51
|
-
prerelease: false
|
52
|
-
version_requirements: !ruby/object:Gem::Requirement
|
53
|
-
requirements:
|
54
|
-
- - "~>"
|
55
|
-
- !ruby/object:Gem::Version
|
56
|
-
version: '2.1'
|
57
43
|
- !ruby/object:Gem::Dependency
|
58
44
|
name: google-style
|
59
45
|
requirement: !ruby/object:Gem::Requirement
|
@@ -74,14 +60,14 @@ dependencies:
|
|
74
60
|
requirements:
|
75
61
|
- - "~>"
|
76
62
|
- !ruby/object:Gem::Version
|
77
|
-
version:
|
63
|
+
version: 1.30.1
|
78
64
|
type: :development
|
79
65
|
prerelease: false
|
80
66
|
version_requirements: !ruby/object:Gem::Requirement
|
81
67
|
requirements:
|
82
68
|
- - "~>"
|
83
69
|
- !ruby/object:Gem::Version
|
84
|
-
version:
|
70
|
+
version: 1.30.1
|
85
71
|
- !ruby/object:Gem::Dependency
|
86
72
|
name: minitest
|
87
73
|
requirement: !ruby/object:Gem::Requirement
|
@@ -217,9 +203,10 @@ files:
|
|
217
203
|
- lib/gapic/grpc_service_config/service_config.rb
|
218
204
|
- lib/gapic/helpers/filepath_helper.rb
|
219
205
|
- lib/gapic/helpers/namespace_helper.rb
|
220
|
-
- lib/gapic/
|
221
|
-
- lib/gapic/
|
222
|
-
- lib/gapic/
|
206
|
+
- lib/gapic/path_pattern.rb
|
207
|
+
- lib/gapic/path_pattern/parser.rb
|
208
|
+
- lib/gapic/path_pattern/pattern.rb
|
209
|
+
- lib/gapic/path_pattern/segment.rb
|
223
210
|
- lib/gapic/presenters.rb
|
224
211
|
- lib/gapic/presenters/enum_presenter.rb
|
225
212
|
- lib/gapic/presenters/enum_value_presenter.rb
|
@@ -239,6 +226,8 @@ files:
|
|
239
226
|
- lib/gapic/schema/api.rb
|
240
227
|
- lib/gapic/schema/loader.rb
|
241
228
|
- lib/gapic/schema/wrappers.rb
|
229
|
+
- lib/gapic/uri_template.rb
|
230
|
+
- lib/gapic/uri_template/parser.rb
|
242
231
|
- lib/google/api/annotations.pb.rb
|
243
232
|
- lib/google/api/client.pb.rb
|
244
233
|
- lib/google/api/field_behavior.pb.rb
|
@@ -1,83 +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 "gapic/path_template/segment"
|
18
|
-
|
19
|
-
module Gapic
|
20
|
-
module PathTemplate
|
21
|
-
# A URI path template parser.
|
22
|
-
#
|
23
|
-
# @see https://tools.ietf.org/html/rfc6570 URI Template
|
24
|
-
#
|
25
|
-
# @!attribute [r] path_template
|
26
|
-
# @return [String] The URI path template to be parsed.
|
27
|
-
# @!attribute [r] segments
|
28
|
-
# @return [Array<Segment|String>] The segments of the parsed URI path
|
29
|
-
# template.
|
30
|
-
class Parser
|
31
|
-
# @private
|
32
|
-
# /((?<positional>\*\*?)|{(?<name>[^\/]+?)(?:=(?<template>.+?))?})/
|
33
|
-
PATH_TEMPLATE = %r{
|
34
|
-
(
|
35
|
-
(?<positional>\*\*?)
|
36
|
-
|
|
37
|
-
{(?<name>[^\/]+?)(?:=(?<template>.+?))?}
|
38
|
-
)
|
39
|
-
}x.freeze
|
40
|
-
|
41
|
-
attr_reader :path_template, :segments
|
42
|
-
|
43
|
-
# Create a new URI path template parser.
|
44
|
-
#
|
45
|
-
# @param path_template [String] The URI path template to be parsed.
|
46
|
-
def initialize path_template
|
47
|
-
@path_template = path_template
|
48
|
-
@segments = parse! path_template
|
49
|
-
end
|
50
|
-
|
51
|
-
protected
|
52
|
-
|
53
|
-
def parse! path_template
|
54
|
-
# segments contain either Strings or segment objects
|
55
|
-
segments = []
|
56
|
-
segment_pos = 0
|
57
|
-
|
58
|
-
while (match = PATH_TEMPLATE.match path_template)
|
59
|
-
# The String before the match needs to be added to the segments
|
60
|
-
segments << match.pre_match unless match.pre_match.empty?
|
61
|
-
|
62
|
-
segment, segment_pos = segment_and_pos_from_match match, segment_pos
|
63
|
-
segments << segment
|
64
|
-
|
65
|
-
path_template = match.post_match
|
66
|
-
end
|
67
|
-
|
68
|
-
# Whatever String is unmatched needs to be added to the segments
|
69
|
-
segments << path_template unless path_template.empty?
|
70
|
-
|
71
|
-
segments
|
72
|
-
end
|
73
|
-
|
74
|
-
def segment_and_pos_from_match match, pos
|
75
|
-
if match[:positional]
|
76
|
-
[Segment.new(pos, match[:positional]), pos + 1]
|
77
|
-
else
|
78
|
-
[Segment.new(match[:name], match[:template]), pos]
|
79
|
-
end
|
80
|
-
end
|
81
|
-
end
|
82
|
-
end
|
83
|
-
end
|
@@ -1,74 +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
|
-
module Gapic
|
18
|
-
module PathTemplate
|
19
|
-
# A segment in a URI path template.
|
20
|
-
#
|
21
|
-
# @see https://tools.ietf.org/html/rfc6570 URI Template
|
22
|
-
#
|
23
|
-
# @!attribute [r] name
|
24
|
-
# @return [String, Integer] The name of a named segment, or the position
|
25
|
-
# of a positional segment.
|
26
|
-
# @!attribute [r] pattern
|
27
|
-
# @return [String, nil] The pattern of the segment, nil if not set.
|
28
|
-
class Segment
|
29
|
-
attr_reader :name, :pattern
|
30
|
-
|
31
|
-
def initialize name, pattern
|
32
|
-
@name = name
|
33
|
-
@pattern = pattern
|
34
|
-
end
|
35
|
-
|
36
|
-
# Determines if the segment is positional (has a number for a name).
|
37
|
-
#
|
38
|
-
# @return [Boolean]
|
39
|
-
def positional?
|
40
|
-
name.is_a? Integer
|
41
|
-
end
|
42
|
-
|
43
|
-
# Determines if the segment is named (has a string for a name).
|
44
|
-
#
|
45
|
-
# @return [Boolean]
|
46
|
-
def named?
|
47
|
-
!positional?
|
48
|
-
end
|
49
|
-
|
50
|
-
# Determines if the segment has a pattern. Positional segments always
|
51
|
-
# have a pattern. Named segments may have a pattern if provided in the
|
52
|
-
# URI path template.
|
53
|
-
#
|
54
|
-
# @return [Boolean]
|
55
|
-
def pattern?
|
56
|
-
!@pattern.nil?
|
57
|
-
end
|
58
|
-
|
59
|
-
# Determines if the segment has a nontrivial pattern (i.e. not `*` or `**`).
|
60
|
-
#
|
61
|
-
# @return [Boolean]
|
62
|
-
def nontrivial_pattern?
|
63
|
-
@pattern && @pattern != "*" && @pattern != "**"
|
64
|
-
end
|
65
|
-
|
66
|
-
# @private
|
67
|
-
def == other
|
68
|
-
return false unless other.is_a? self.class
|
69
|
-
|
70
|
-
(name == other.name) && (pattern == other.pattern)
|
71
|
-
end
|
72
|
-
end
|
73
|
-
end
|
74
|
-
end
|