gapic-generator 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.yardopts +13 -0
- data/CHANGELOG.md +38 -0
- data/CODE_OF_CONDUCT.md +43 -0
- data/CONTRIBUTING.md +28 -0
- data/LICENSE +202 -0
- data/README.md +72 -0
- data/bin/gapic-generator +103 -0
- data/bin/protoc-gen-ruby_gapic +33 -0
- data/default-rubocop.yml +10 -0
- data/gem_templates/binary.erb +20 -0
- data/gem_templates/dockerfile.erb +39 -0
- data/gem_templates/entrypoint.erb +24 -0
- data/gem_templates/gapic_sh.erb +97 -0
- data/gem_templates/gemfile.erb +8 -0
- data/gem_templates/gemspec.erb +36 -0
- data/gem_templates/generator.erb +37 -0
- data/gem_templates/gitignore.erb +10 -0
- data/gem_templates/rakefile.erb +29 -0
- data/gem_templates/readme.erb +69 -0
- data/gem_templates/rubocop.erb +16 -0
- data/gem_templates/shared/_header.erb +4 -0
- data/gem_templates/shared/_license.erb +13 -0
- data/gem_templates/shared/_warning.erb +1 -0
- data/gem_templates/test_generator.erb +13 -0
- data/gem_templates/test_helper.erb +25 -0
- data/gem_templates/version.erb +10 -0
- data/lib/gapic/file_formatter.rb +62 -0
- data/lib/gapic/gem_builder.rb +98 -0
- data/lib/gapic/generator.rb +30 -0
- data/lib/gapic/generator/version.rb +21 -0
- data/lib/gapic/generators/base_generator.rb +91 -0
- data/lib/gapic/generators/default_generator.rb +101 -0
- data/lib/gapic/grpc_service_config/method_config.rb +49 -0
- data/lib/gapic/grpc_service_config/parser.rb +218 -0
- data/lib/gapic/grpc_service_config/parsing_error.rb +25 -0
- data/lib/gapic/grpc_service_config/retry_policy.rb +51 -0
- data/lib/gapic/grpc_service_config/service_config.rb +42 -0
- data/lib/gapic/path_template.rb +35 -0
- data/lib/gapic/path_template/parser.rb +83 -0
- data/lib/gapic/path_template/segment.rb +67 -0
- data/lib/gapic/resource_lookup.rb +91 -0
- data/lib/gapic/runner.rb +76 -0
- data/lib/gapic/schema.rb +17 -0
- data/lib/gapic/schema/api.rb +264 -0
- data/lib/gapic/schema/loader.rb +269 -0
- data/lib/gapic/schema/wrappers.rb +718 -0
- data/lib/google/api/annotations.pb.rb +39 -0
- data/lib/google/api/client.pb.rb +43 -0
- data/lib/google/api/field_behavior.pb.rb +51 -0
- data/lib/google/api/http.pb.rb +60 -0
- data/lib/google/api/resource.pb.rb +80 -0
- data/lib/google/longrunning/operations.pb.rb +115 -0
- data/lib/google/protobuf/any.pb.rb +40 -0
- data/lib/google/protobuf/compiler/plugin.pb.rb +72 -0
- data/lib/google/protobuf/descriptor.pb.rb +359 -0
- data/lib/google/protobuf/empty.pb.rb +36 -0
- data/lib/google/rpc/status.pb.rb +46 -0
- data/templates/default/gem/_version.erb +2 -0
- data/templates/default/gem/changelog.erb +3 -0
- data/templates/default/gem/gemfile.erb +4 -0
- data/templates/default/gem/gemspec.erb +37 -0
- data/templates/default/gem/gitignore.erb +18 -0
- data/templates/default/gem/license.erb +22 -0
- data/templates/default/gem/rakefile.erb +27 -0
- data/templates/default/gem/readme.erb +24 -0
- data/templates/default/gem/rubocop.erb +59 -0
- data/templates/default/gem/version.erb +6 -0
- data/templates/default/gem/yardopts.erb +12 -0
- data/templates/default/helpers/default_helper.rb +56 -0
- data/templates/default/helpers/filepath_helper.rb +38 -0
- data/templates/default/helpers/namespace_helper.rb +44 -0
- data/templates/default/helpers/presenter_helper.rb +24 -0
- data/templates/default/helpers/presenters/enum_presenter.rb +35 -0
- data/templates/default/helpers/presenters/enum_value_presenter.rb +33 -0
- data/templates/default/helpers/presenters/field_presenter.rb +146 -0
- data/templates/default/helpers/presenters/file_presenter.rb +53 -0
- data/templates/default/helpers/presenters/gem_presenter.rb +140 -0
- data/templates/default/helpers/presenters/message_presenter.rb +66 -0
- data/templates/default/helpers/presenters/method_presenter.rb +293 -0
- data/templates/default/helpers/presenters/package_presenter.rb +65 -0
- data/templates/default/helpers/presenters/resource_presenter.rb +92 -0
- data/templates/default/helpers/presenters/sample_presenter.rb +74 -0
- data/templates/default/helpers/presenters/service_presenter.rb +276 -0
- data/templates/default/layouts/_ruby.erb +20 -0
- data/templates/default/package.erb +6 -0
- data/templates/default/proto_docs/_enum.erb +13 -0
- data/templates/default/proto_docs/_message.erb +23 -0
- data/templates/default/proto_docs/_proto_file.erb +9 -0
- data/templates/default/proto_docs/proto_file.erb +6 -0
- data/templates/default/proto_docs/readme.erb +5 -0
- data/templates/default/service.erb +8 -0
- data/templates/default/service/client.erb +6 -0
- data/templates/default/service/client/_client.erb +137 -0
- data/templates/default/service/client/_config.erb +155 -0
- data/templates/default/service/client/_credentials.erb +21 -0
- data/templates/default/service/client/_helpers.erb +9 -0
- data/templates/default/service/client/_operations.erb +88 -0
- data/templates/default/service/client/_paths.erb +8 -0
- data/templates/default/service/client/_requires.erb +1 -0
- data/templates/default/service/client/_resource.erb +6 -0
- data/templates/default/service/client/_self_configure.erb +9 -0
- data/templates/default/service/client/_self_configure_defaults.erb +22 -0
- data/templates/default/service/client/_self_configure_retry_policy.erb +15 -0
- data/templates/default/service/client/method/_def.erb +21 -0
- data/templates/default/service/client/method/def/_options_defaults.erb +29 -0
- data/templates/default/service/client/method/def/_request.erb +6 -0
- data/templates/default/service/client/method/def/_request_normal.erb +4 -0
- data/templates/default/service/client/method/def/_request_streaming.erb +9 -0
- data/templates/default/service/client/method/def/_rescue.erb +1 -0
- data/templates/default/service/client/method/def/_response.erb +6 -0
- data/templates/default/service/client/method/def/_response_normal.erb +8 -0
- data/templates/default/service/client/method/def/_response_paged.erb +9 -0
- data/templates/default/service/client/method/docs/_error.erb +2 -0
- data/templates/default/service/client/method/docs/_request.erb +6 -0
- data/templates/default/service/client/method/docs/_request_field.erb +7 -0
- data/templates/default/service/client/method/docs/_request_normal.erb +20 -0
- data/templates/default/service/client/method/docs/_request_streaming.erb +5 -0
- data/templates/default/service/client/method/docs/_response.erb +6 -0
- data/templates/default/service/client/method/docs/_sample.erb +20 -0
- data/templates/default/service/client/method/docs/_sample_response.erb +24 -0
- data/templates/default/service/client/method/docs/_samples.erb +6 -0
- data/templates/default/service/client/method/docs/request_field/_arg.erb +10 -0
- data/templates/default/service/client/method/docs/request_field/_hash.erb +19 -0
- data/templates/default/service/client/method/docs/sample_response/_comment.erb +5 -0
- data/templates/default/service/client/method/docs/sample_response/_define.erb +2 -0
- data/templates/default/service/client/method/docs/sample_response/_loop.erb +12 -0
- data/templates/default/service/client/method/docs/sample_response/_print.erb +2 -0
- data/templates/default/service/client/method/docs/sample_response/_write_file.erb +2 -0
- data/templates/default/service/client/resource/_def.erb +6 -0
- data/templates/default/service/client/resource/_doc.erb +8 -0
- data/templates/default/service/client/resource/_multi.erb +28 -0
- data/templates/default/service/client/resource/_single.erb +11 -0
- data/templates/default/service/credentials.erb +6 -0
- data/templates/default/service/operations.erb +6 -0
- data/templates/default/service/paths.erb +6 -0
- data/templates/default/service/test/client.erb +24 -0
- data/templates/default/service/test/client_operations.erb +24 -0
- data/templates/default/service/test/method/_assert_response.erb +11 -0
- data/templates/default/service/test/method/_bidi.erb +100 -0
- data/templates/default/service/test/method/_client.erb +84 -0
- data/templates/default/service/test/method/_normal.erb +69 -0
- data/templates/default/service/test/method/_server.erb +85 -0
- data/templates/default/service/test/method/_setup.erb +21 -0
- data/templates/default/service/test/smoke.erb +12 -0
- data/templates/default/shared/_header.erb +4 -0
- data/templates/default/shared/_license.erb +21 -0
- data/templates/default/shared/_warning.erb +1 -0
- metadata +350 -0
@@ -0,0 +1,33 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
# Copyright 2018 Google LLC
|
5
|
+
#
|
6
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
7
|
+
# you may not use this file except in compliance with the License.
|
8
|
+
# You may obtain a copy of the License at
|
9
|
+
#
|
10
|
+
# https://www.apache.org/licenses/LICENSE-2.0
|
11
|
+
#
|
12
|
+
# Unless required by applicable law or agreed to in writing, software
|
13
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
14
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
15
|
+
# See the License for the specific language governing permissions and
|
16
|
+
# limitations under the License.
|
17
|
+
|
18
|
+
$LOAD_PATH.unshift ::File.expand_path("../../lib", __FILE__)
|
19
|
+
require "gapic/runner"
|
20
|
+
require "google/protobuf/compiler/plugin.pb"
|
21
|
+
|
22
|
+
# Ensure that no encoding conversions are done on STDIN and STDOUT
|
23
|
+
# since we are passing binary data back and forth. Otherwise these
|
24
|
+
# streams will be mangled on Windows.
|
25
|
+
STDIN.binmode
|
26
|
+
STDOUT.binmode
|
27
|
+
|
28
|
+
request = Google::Protobuf::Compiler::CodeGeneratorRequest.decode STDIN.read
|
29
|
+
|
30
|
+
# Run the request
|
31
|
+
response = Gapic::Runner.run request
|
32
|
+
|
33
|
+
STDOUT.print response.serialize
|
data/default-rubocop.yml
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
# This file is to be used as the default config for formatting the generated files.
|
2
|
+
# We can't reference the generated .rubocop.yml file because Rubocop is so clevar
|
3
|
+
# that it won't find the google-style gem unless the file is referenced here.
|
4
|
+
inherit_gem:
|
5
|
+
google-style: google-style.yml
|
6
|
+
|
7
|
+
AllCops:
|
8
|
+
Exclude:
|
9
|
+
- "*.gemspec"
|
10
|
+
- "test/**/*"
|
@@ -0,0 +1,20 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
<%= render partial: "shared/header" -%>
|
4
|
+
|
5
|
+
gem "gapic-generator"
|
6
|
+
require "gapic/runner"
|
7
|
+
require "google/protobuf/compiler/plugin.pb"
|
8
|
+
|
9
|
+
# Ensure that no encoding conversions are done on STDIN and STDOUT
|
10
|
+
# since we are passing binary data back and forth. Otherwise these
|
11
|
+
# streams will be mangled on Windows.
|
12
|
+
STDIN.binmode
|
13
|
+
STDOUT.binmode
|
14
|
+
|
15
|
+
request = Google::Protobuf::Compiler::CodeGeneratorRequest.decode STDIN.read
|
16
|
+
|
17
|
+
# Run the request, specifying the <%= gem_name %> generator
|
18
|
+
response = Gapic::Runner.run request, generator: :<%= gem_name %>
|
19
|
+
|
20
|
+
STDOUT.print response.serialize
|
@@ -0,0 +1,39 @@
|
|
1
|
+
<%= render partial: "shared/header" -%>
|
2
|
+
|
3
|
+
##
|
4
|
+
# Builder image.
|
5
|
+
# Creates /workspace/gapic-generator-<%= gem_name %>.gem
|
6
|
+
# to be copied into the final runtime image.
|
7
|
+
##
|
8
|
+
FROM ruby:2.6-stretch as builder
|
9
|
+
WORKDIR /workspace
|
10
|
+
|
11
|
+
# Copy code from the local directory.
|
12
|
+
COPY . /workspace/
|
13
|
+
|
14
|
+
# Create a build of the gapic-generator-<%= gem_name %> gem from source.
|
15
|
+
RUN gem build -o gapic-generator-<%= gem_name %>.gem \
|
16
|
+
gapic-generator-<%= gem_name %>.gemspec
|
17
|
+
|
18
|
+
|
19
|
+
##
|
20
|
+
# Runtime image.
|
21
|
+
# Installs the generator executables, common protos, and an entrypoint.
|
22
|
+
##
|
23
|
+
FROM ruby:2.6-stretch
|
24
|
+
WORKDIR /workspace
|
25
|
+
|
26
|
+
# Install common protos.
|
27
|
+
COPY --from=gcr.io/gapic-images/api-common-protos:beta /protos/ /workspace/common-protos/
|
28
|
+
|
29
|
+
# Copy gems from the builder.
|
30
|
+
COPY --from=builder /workspace/*.gem /workspace/
|
31
|
+
|
32
|
+
# Install the subgenerator and other needed tools.
|
33
|
+
RUN gem install grpc-tools gapic-generator-<%= gem_name %>.gem \
|
34
|
+
&& rm gapic-generator-<%= gem_name %>.gem \
|
35
|
+
&& mkdir -p --mode=777 /.cache
|
36
|
+
|
37
|
+
# Install the entrypoint.
|
38
|
+
COPY ./docker-entrypoint.sh /workspace/entrypoint.sh
|
39
|
+
ENTRYPOINT ["/workspace/entrypoint.sh"]
|
@@ -0,0 +1,24 @@
|
|
1
|
+
#!/bin/bash
|
2
|
+
|
3
|
+
<%= render partial: "shared/license" -%>
|
4
|
+
|
5
|
+
# enable extended globbing for flag pattern matching
|
6
|
+
shopt -s extglob
|
7
|
+
|
8
|
+
# Parse out options.
|
9
|
+
while true; do
|
10
|
+
case "$1" in
|
11
|
+
--ruby-<%= gem_name %>* ) echo "Skipping unrecognized ruby-<%= gem_name %> flag: $1" >&2; shift ;;
|
12
|
+
--* | +([[:word:][:punct:]]) ) shift ;;
|
13
|
+
* ) break ;;
|
14
|
+
esac
|
15
|
+
done
|
16
|
+
|
17
|
+
mkdir -p /workspace/out/lib
|
18
|
+
exec grpc_tools_ruby_protoc \
|
19
|
+
--proto_path=/workspace/common-protos/ --proto_path=/workspace/in/ \
|
20
|
+
--ruby_out=/workspace/out/lib \
|
21
|
+
--grpc_out=/workspace/out/lib \
|
22
|
+
--ruby_<%= gem_name %>_out=/workspace/out/ \
|
23
|
+
--ruby_<%= gem_name %>_opt="configuration=/workspace/config.yml" \
|
24
|
+
`find /workspace/in/ -name *.proto`
|
@@ -0,0 +1,97 @@
|
|
1
|
+
#!/bin/bash
|
2
|
+
|
3
|
+
<%= render partial: "shared/license" -%>
|
4
|
+
|
5
|
+
set -e
|
6
|
+
|
7
|
+
CMD="$0"
|
8
|
+
|
9
|
+
# Set variables used by this script.
|
10
|
+
# All of these are set in options below, and all but PLUGIN_OPTIONS and
|
11
|
+
# PROTO_PATH are required.
|
12
|
+
IMAGE=
|
13
|
+
IN=
|
14
|
+
OUT=
|
15
|
+
PLUGIN_OPTIONS=
|
16
|
+
PROTO_PATH=`pwd`
|
17
|
+
GAPIC_SERVICE_CONFIG=
|
18
|
+
|
19
|
+
# Print help and exit.
|
20
|
+
function show_help {
|
21
|
+
cat << EOF
|
22
|
+
Usage: $CMD --image IMAGE --in IN_DIR --out OUT_DIR [--path PATH_DIR]
|
23
|
+
|
24
|
+
Required arguments:
|
25
|
+
--image The Docker image to use. The script will attempt to pull
|
26
|
+
it if it is not present.
|
27
|
+
-i, --in A directory containing the protos describing the API
|
28
|
+
to be generated.
|
29
|
+
-o, --out Destination directory for the completed client library.
|
30
|
+
--config Location of the GAPIC service configuration .yml file.
|
31
|
+
|
32
|
+
Optional arguments:
|
33
|
+
-p, --path The base import path for the protos. Assumed to be the
|
34
|
+
current working directory if unspecified.
|
35
|
+
-h, --help This help information.
|
36
|
+
EOF
|
37
|
+
|
38
|
+
exit 0
|
39
|
+
}
|
40
|
+
|
41
|
+
# Parse out options.
|
42
|
+
while true; do
|
43
|
+
case "$1" in
|
44
|
+
-h | --help ) show_help ;;
|
45
|
+
--image ) IMAGE="$2"; shift 2 ;;
|
46
|
+
-i | --in ) IN="$2"; shift 2 ;;
|
47
|
+
-o | --out ) OUT="$2"; shift 2 ;;
|
48
|
+
-p | --path ) PROTO_PATH=$2; shift 2 ;;
|
49
|
+
--config ) GAPIC_SERVICE_CONFIG=$2; shift 2 ;;
|
50
|
+
--* ) PLUGIN_OPTIONS="$PLUGIN_OPTIONS $1 $2"; shift 2 ;;
|
51
|
+
-- ) shift; break; ;;
|
52
|
+
* ) break ;;
|
53
|
+
esac
|
54
|
+
done
|
55
|
+
|
56
|
+
# Ensure that all required options are set.
|
57
|
+
if [ -z "$IMAGE" ] || [ -z "$IN" ] || [ -z "$OUT" ]; then
|
58
|
+
cat << EOF
|
59
|
+
Required argument missing.
|
60
|
+
The --image, --in, and --out arguments are all required.
|
61
|
+
Run $CMD --help for more information.
|
62
|
+
EOF
|
63
|
+
|
64
|
+
exit 64
|
65
|
+
fi
|
66
|
+
|
67
|
+
# Ensure that the input directory exists (and is a directory).
|
68
|
+
if ! [ -d ${PROTO_PATH}/${IN} ]; then
|
69
|
+
cat << EOF
|
70
|
+
Directory does not exist: ${PROTO_PATH}/${IN}
|
71
|
+
EOF
|
72
|
+
exit 2
|
73
|
+
fi
|
74
|
+
|
75
|
+
# Ensure Docker is running and seems healthy.
|
76
|
+
# This is mostly a check to bubble useful errors quickly.
|
77
|
+
docker ps > /dev/null
|
78
|
+
|
79
|
+
# If the output directory does not exist, create it.
|
80
|
+
mkdir -p $OUT
|
81
|
+
|
82
|
+
# If the output directory is not empty, warn (but continue).
|
83
|
+
if [ "$(ls -A $OUT )" ]; then
|
84
|
+
cat << EOF
|
85
|
+
Warning: Output directory is not empty.
|
86
|
+
EOF
|
87
|
+
fi
|
88
|
+
|
89
|
+
# Generate the client library.
|
90
|
+
docker run \
|
91
|
+
--mount type=bind,source=${PROTO_PATH}/${IN},destination=/workspace/in/${IN},readonly \
|
92
|
+
--mount type=bind,source=${PROTO_PATH}/${GAPIC_SERVICE_CONFIG},destination=/workspace/config.yml,readonly \
|
93
|
+
--mount type=bind,source=${PROTO_PATH}/${OUT},destination=/workspace/out \
|
94
|
+
--rm \
|
95
|
+
--user $UID \
|
96
|
+
$IMAGE \
|
97
|
+
$PLUGIN_OPTIONS
|
@@ -0,0 +1,36 @@
|
|
1
|
+
<%= render partial: "shared/header" -%>
|
2
|
+
|
3
|
+
|
4
|
+
lib = File.expand_path "lib", __dir__
|
5
|
+
$LOAD_PATH.unshift lib unless $LOAD_PATH.include? lib
|
6
|
+
require "gapic/generator/<%= gem_name %>/version"
|
7
|
+
|
8
|
+
Gem::Specification.new do |spec|
|
9
|
+
spec.name = "gapic-generator-<%= gem_name %>"
|
10
|
+
spec.version = Gapic::Generator::<%= gem_class_prefix %>::VERSION
|
11
|
+
spec.authors = ["Ernest Landrito", "Chris Smith", "Mike Moore"]
|
12
|
+
spec.email = ["landrito@google.com", "quartzmo@gmail.com",
|
13
|
+
"mike@blowmage.com"]
|
14
|
+
|
15
|
+
spec.licenses = ["Apache-2.0"]
|
16
|
+
|
17
|
+
spec.summary = "An API Client Generator for Ruby in Ruby!"
|
18
|
+
spec.homepage = "https://github.com/googleapis/gapic-generator-ruby"
|
19
|
+
|
20
|
+
spec.files = Dir.glob("bin/*") + Dir.glob("lib/**/*.rb") +
|
21
|
+
Dir.glob("templates/**/*.{rb,erb}") +
|
22
|
+
Dir.glob("*.md")
|
23
|
+
spec.bindir = "bin"
|
24
|
+
spec.executables = ["protoc-gen-ruby_<%= gem_name %>"]
|
25
|
+
spec.require_paths = ["lib"]
|
26
|
+
|
27
|
+
spec.add_dependency "actionpack", "~> 5.2"
|
28
|
+
spec.add_dependency "gapic-generator", "~> 0.0.0.dev"
|
29
|
+
spec.add_dependency "protobuf", "~> 3.8"
|
30
|
+
spec.add_dependency "rubocop", "~> 0.61"
|
31
|
+
|
32
|
+
spec.add_development_dependency "bundler", "~> 2.1"
|
33
|
+
spec.add_development_dependency "minitest", "~> 5.0"
|
34
|
+
spec.add_development_dependency "minitest-focus", "~> 1.0"
|
35
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
36
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
<%= render partial: "shared/header" -%>
|
2
|
+
|
3
|
+
|
4
|
+
require "gapic/generators/default_generator"
|
5
|
+
|
6
|
+
module Gapic
|
7
|
+
module Generators
|
8
|
+
# The generator orchestrates the rendering of templates for
|
9
|
+
# <%= gem_class_prefix %> projects.
|
10
|
+
class <%= gem_class_prefix %>Generator < DefaultGenerator
|
11
|
+
# Initializes the generator.
|
12
|
+
#
|
13
|
+
# @param api [Gapic::Schema::Api] The API model/context to
|
14
|
+
# generate.
|
15
|
+
def initialize api
|
16
|
+
super
|
17
|
+
|
18
|
+
# Configure to use prefer <%= gem_class_prefix %> templates
|
19
|
+
template_path = File.join __dir__,
|
20
|
+
"../../../templates/<%= gem_name %>"
|
21
|
+
use_templates! template_path
|
22
|
+
|
23
|
+
# Configure these helper method to be used by the generator
|
24
|
+
# use_helpers! :helper_method1, :helper_method2, :helper_method3
|
25
|
+
end
|
26
|
+
|
27
|
+
# Generates all the files for the API.
|
28
|
+
#
|
29
|
+
# @return [Array<
|
30
|
+
# Google::Protobuf::Compiler::CodeGeneratorResponse::File>]
|
31
|
+
# The files that were generated for the API.
|
32
|
+
def generate
|
33
|
+
super
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
<%= render partial: "shared/header" -%>
|
2
|
+
|
3
|
+
require "bundler/gem_tasks"
|
4
|
+
require "rubocop/rake_task"
|
5
|
+
require "rake/testtask"
|
6
|
+
|
7
|
+
RuboCop::RakeTask.new # Configuration is in .rubocop.yml
|
8
|
+
Rake::TestTask.new :test do |t|
|
9
|
+
t.libs << "test"
|
10
|
+
t.libs << "lib"
|
11
|
+
t.test_files = FileList["test/**/*_test.rb"]
|
12
|
+
end
|
13
|
+
|
14
|
+
desc "Run the CI build"
|
15
|
+
task :ci do
|
16
|
+
puts "\nBUILDING gapic-generator-<%= gem_name %>\n"
|
17
|
+
puts "\ngapic-generator-<%= gem_name %> rubocop\n"
|
18
|
+
Rake::Task[:rubocop].invoke
|
19
|
+
puts "\ngapic-generator-<%= gem_name %> test\n"
|
20
|
+
Rake::Task[:test].invoke
|
21
|
+
end
|
22
|
+
|
23
|
+
desc "Build the docker image."
|
24
|
+
task :image, :name do |_t, args|
|
25
|
+
image_name = args[:name] || "ruby-gapic-generator-<%= gem_name %>"
|
26
|
+
sh "docker build -t #{image_name} ."
|
27
|
+
end
|
28
|
+
|
29
|
+
task default: :ci
|
@@ -0,0 +1,69 @@
|
|
1
|
+
# <%= gem_class_prefix %> Generator for Ruby
|
2
|
+
|
3
|
+
Create Ruby clients from a protocol buffer description of an API.
|
4
|
+
|
5
|
+
**Note** This project is a preview. Please try it out and let us know what you think,
|
6
|
+
but there are currently no guarantees of stability or support.
|
7
|
+
|
8
|
+
## Usage
|
9
|
+
### Install the Proto Compiler
|
10
|
+
This generator relies on the Protocol Buffer Compiler to [orchestrate] the
|
11
|
+
client generation.
|
12
|
+
|
13
|
+
```sh
|
14
|
+
# Declare the protobuf version to use.
|
15
|
+
$ export PROTOBUF_VERSION=3.6.1
|
16
|
+
|
17
|
+
# Declare the target installation system.
|
18
|
+
# export SYSTEM=osx
|
19
|
+
$ export SYSTEM=linux
|
20
|
+
|
21
|
+
# Get the precompiled protobuf compiler.
|
22
|
+
$ curl --location https://github.com/google/protobuf/releases/download/v${PROTOBUF_VERSION}/protoc-${PROTOBUF_VERSION}-linux-x86_64.zip > usr/src/protoc/protoc-${PROTOBUF_VERSION}.zip
|
23
|
+
$ cd /usr/src/protoc/
|
24
|
+
$ unzip protoc-${PROTOBUF_VERSION}.zip
|
25
|
+
$ rm protoc-${PROTOBUF_VERSION}.zip
|
26
|
+
|
27
|
+
# Link the protoc to the path.
|
28
|
+
$ ln -s /usr/src/protoc/bin/protoc /usr/local/bin/protoc
|
29
|
+
$ mkdir -p /protos/
|
30
|
+
|
31
|
+
# Move the common protobuf files to the local include folder.
|
32
|
+
$ cp -R /usr/src/protoc/include/* /usr/local/include/
|
33
|
+
```
|
34
|
+
|
35
|
+
[orchestrate]: https://developers.google.com/protocol-buffers/docs/reference/ruby-generated
|
36
|
+
|
37
|
+
### Build and Install the Generator
|
38
|
+
This tool is in pre-alpha so it is not yet released to RubyGems. You will have to
|
39
|
+
build the generator from scratch.
|
40
|
+
|
41
|
+
```sh
|
42
|
+
$ git clone https://github.com/googleapis/gapic-generator-ruby.git
|
43
|
+
$ cd gapic-generator-ruby
|
44
|
+
$ gem build gapic-generator.gemspec
|
45
|
+
$ gem install gapic-generator-0.1.0.gem
|
46
|
+
$ which protoc-gen-ruby_gapic
|
47
|
+
> {Non-empty path}
|
48
|
+
```
|
49
|
+
|
50
|
+
### Generate an API
|
51
|
+
Installing this generator exposes `protoc-gen-ruby_gapic` on the PATH. By doing
|
52
|
+
so, it gives the protobuf compiler the CLI option `--ruby_gapic_out` on which
|
53
|
+
you can specify an output path for this generator.
|
54
|
+
|
55
|
+
If you want to experiment with an already-existing API, one example is available.
|
56
|
+
Note: You need to clone the googleapis repository from GitHub, and change
|
57
|
+
to a special branch:
|
58
|
+
```sh
|
59
|
+
# Get the protos and it's dependencies.
|
60
|
+
$ git clone git@github.com:googleapis/api-common-protos.git
|
61
|
+
$ git clone git@github.com:googleapis/googleapis.git
|
62
|
+
$ cd googleapis
|
63
|
+
$ git checkout --track -b input-contract origin/input-contract
|
64
|
+
|
65
|
+
# Now you're ready to compile the API.
|
66
|
+
$ protoc google/<%= gem_name %>/vision/v1/*.proto \
|
67
|
+
--proto_path=../api-common-protos/ --proto_path=. \
|
68
|
+
--ruby_gapic_out=/dest/
|
69
|
+
```
|
@@ -0,0 +1,16 @@
|
|
1
|
+
AllCops:
|
2
|
+
TargetRubyVersion: 2.5
|
3
|
+
Exclude:
|
4
|
+
- expected_output/**/*
|
5
|
+
|
6
|
+
Documentation:
|
7
|
+
Enabled: false
|
8
|
+
|
9
|
+
Style/StringLiterals:
|
10
|
+
EnforcedStyle: double_quotes
|
11
|
+
Style/MethodCallWithArgsParentheses:
|
12
|
+
Enabled: true
|
13
|
+
EnforcedStyle: omit_parentheses
|
14
|
+
AllowParenthesesInMultilineCall: true
|
15
|
+
Style/MethodDefParentheses:
|
16
|
+
EnforcedStyle: require_no_parentheses
|