gapic-generator 0.4.2 → 0.6.2
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 +33 -0
- data/gem_templates/dockerfile.erb +1 -1
- data/gem_templates/entrypoint.erb +1 -0
- data/lib/gapic/file_formatter.rb +0 -1
- data/lib/gapic/generator/version.rb +1 -1
- data/lib/gapic/generators/default_generator.rb +16 -14
- 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 +39 -3
- data/lib/gapic/presenters/method_presenter.rb +10 -5
- data/lib/gapic/presenters/package_presenter.rb +4 -3
- data/lib/gapic/presenters/resource_presenter.rb +48 -36
- data/lib/gapic/presenters/service_presenter.rb +18 -12
- data/lib/gapic/runner.rb +3 -1
- data/lib/gapic/schema/api.rb +7 -0
- 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/gemspec.erb +7 -6
- data/templates/default/gem/rakefile.erb +1 -0
- data/templates/default/gem/test_helper.erb +8 -0
- data/templates/default/lib/_service.erb +2 -0
- data/templates/default/service/client/_client.erb +4 -1
- data/templates/default/service/client/_config.erb +15 -11
- data/templates/default/service/client/_operations.erb +2 -0
- data/templates/default/service/client/resource/_doc.erb +1 -1
- data/templates/default/service/client/resource/_multi.erb +2 -5
- data/templates/default/service/client/resource/_single.erb +1 -2
- data/templates/default/service/test/_resource.erb +16 -0
- data/templates/default/service/test/client.erb +2 -5
- data/templates/default/service/test/client_operations.erb +2 -5
- data/templates/default/service/test/client_paths.erb +15 -0
- data/templates/default/service/test/method/_bidi.erb +6 -0
- data/templates/default/service/test/method/_client.erb +6 -0
- data/templates/default/service/test/method/_normal.erb +6 -0
- data/templates/default/service/test/method/_server.erb +6 -0
- metadata +13 -7
- data/lib/gapic/path_template/parser.rb +0 -83
- data/lib/gapic/path_template/segment.rb +0 -67
@@ -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,67 +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
|
-
# @private
|
60
|
-
def == other
|
61
|
-
return false unless other.is_a? self.class
|
62
|
-
|
63
|
-
(name == other.name) && (pattern == other.pattern)
|
64
|
-
end
|
65
|
-
end
|
66
|
-
end
|
67
|
-
end
|