gapic-generator 0.11.0 → 0.45.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 +303 -0
- data/CONTRIBUTING.md +1 -1
- data/README.md +71 -37
- data/bin/protoc-gen-ruby_gapic +2 -2
- data/lib/gapic/file_formatter.rb +23 -19
- data/lib/gapic/formatting_utils.rb +24 -10
- data/lib/gapic/gem_builder.rb +15 -17
- data/lib/gapic/generator/version.rb +1 -1
- data/lib/gapic/generators/base_generator.rb +6 -4
- data/lib/gapic/generators/default_generator.rb +70 -34
- data/lib/gapic/generators/default_generator_parameters.rb +9 -3
- data/lib/gapic/grpc_service_config/parser.rb +2 -2
- data/lib/gapic/model/api_metadata.rb +173 -0
- data/lib/gapic/model/method/http_annotation.rb +158 -60
- data/lib/gapic/model/method/lro.rb +8 -5
- data/lib/gapic/model/method/routing.rb +3 -18
- data/lib/gapic/model/mixins.rb +76 -10
- data/lib/gapic/model/service/nonstandard_lro_provider.rb +10 -11
- data/lib/gapic/package_snippets.rb +159 -0
- data/lib/gapic/path_pattern/parser.rb +11 -2
- data/lib/gapic/path_pattern/pattern.rb +18 -1
- data/lib/gapic/path_pattern/segment.rb +11 -4
- data/lib/gapic/presenters/enum_presenter.rb +14 -0
- data/lib/gapic/presenters/enum_value_presenter.rb +4 -1
- data/lib/gapic/presenters/field_presenter.rb +78 -21
- data/lib/gapic/presenters/gem_presenter.rb +109 -35
- data/lib/gapic/presenters/message_presenter.rb +15 -0
- data/lib/gapic/presenters/method/{rest_pagination_info.rb → compute_pagination_info.rb} +31 -20
- data/lib/gapic/presenters/method/http_binding_presenter.rb +128 -0
- data/lib/gapic/presenters/method_presenter.rb +109 -35
- data/lib/gapic/presenters/method_rest_presenter.rb +83 -137
- data/lib/gapic/presenters/package_presenter.rb +63 -18
- data/lib/gapic/presenters/resource_presenter.rb +9 -3
- data/lib/gapic/presenters/service/lro_client_presenter.rb +14 -14
- data/lib/gapic/presenters/service/mixin_client_presenter.rb +89 -0
- data/lib/gapic/presenters/service/sub_client_presenter.rb +84 -0
- data/lib/gapic/presenters/service_presenter.rb +183 -31
- data/lib/gapic/presenters/service_rest_presenter.rb +180 -27
- data/lib/gapic/presenters/snippet/client_call_presenter.rb +82 -0
- data/lib/gapic/presenters/snippet/client_initialization_presenter.rb +87 -0
- data/lib/gapic/presenters/snippet/declaration_presenter.rb +91 -0
- data/lib/gapic/presenters/snippet/expression_presenter.rb +154 -0
- data/lib/gapic/presenters/snippet/iteration_presenter.rb +118 -0
- data/lib/gapic/presenters/snippet/parameter_presenter.rb +67 -0
- data/lib/gapic/presenters/snippet/request_initialization_presenters.rb +202 -0
- data/lib/gapic/presenters/snippet/response_handling_presenters.rb +329 -0
- data/lib/gapic/presenters/snippet/statement_presenter.rb +134 -0
- data/lib/gapic/presenters/snippet/type_presenter.rb +98 -0
- data/lib/gapic/presenters/snippet_presenter.rb +199 -10
- data/lib/gapic/presenters.rb +2 -0
- data/lib/gapic/runner.rb +1 -1
- data/lib/gapic/schema/api.rb +49 -3
- data/lib/gapic/schema/loader.rb +67 -22
- data/lib/gapic/schema/parameter_schema.rb +8 -8
- data/lib/gapic/schema/proto_tools.rb +193 -0
- data/lib/gapic/schema/request_param_parser.rb +5 -7
- data/lib/gapic/schema/service_config_parser.rb +38 -4
- data/lib/gapic/schema/wrappers.rb +192 -31
- data/lib/gapic/uri_template/parser.rb +15 -7
- data/lib/google/cloud/tools/snippetgen/configlanguage/v1/snippet_config_language_pb.rb +104 -0
- data/lib/google/cloud/tools/snippetgen/snippetindex/v1/snippet_index_pb.rb +58 -0
- data/lib/google/protobuf/compiler/plugin_pb.rb +47 -0
- data/templates/default/binding_override.text.erb +6 -0
- data/templates/default/gem/gemfile.text.erb +12 -0
- data/templates/default/gem/{gemspec.erb → gemspec.text.erb} +3 -11
- data/templates/default/gem/{readme.erb → readme.text.erb} +10 -6
- data/templates/default/gem/{rubocop.erb → rubocop.text.erb} +3 -0
- data/templates/default/gem/{test_helper.erb → test_helper.text.erb} +4 -2
- data/templates/default/gem/toys.text.erb +12 -0
- data/templates/default/helpers/default_helper.rb +33 -1
- data/templates/default/lib/_binding_override.text.erb +49 -0
- data/templates/default/lib/{_package.erb → _package.text.erb} +6 -9
- data/templates/default/lib/_package_rest.text.erb +24 -0
- data/templates/default/lib/{_service.erb → _service.text.erb} +11 -23
- data/templates/default/lib/package/_self_configure.text.erb +16 -0
- data/templates/default/lib/package/_self_configure_defaults.text.erb +13 -0
- data/templates/default/lib/package/self_configure/_binding_default.text.erb +15 -0
- data/templates/default/lib/rest/_rest.text.erb +46 -0
- data/templates/default/package_rest.text.erb +6 -0
- data/templates/default/proto_docs/_deprecated.text.erb +9 -0
- data/templates/default/proto_docs/{_enum.erb → _enum.text.erb} +1 -0
- data/templates/default/proto_docs/{_message.erb → _message.text.erb} +2 -0
- data/templates/default/service/client/{_client.erb → _client.text.erb} +60 -12
- data/templates/default/service/client/{_config.erb → _config.text.erb} +39 -8
- data/templates/default/service/client/{_operations.erb → _operations.text.erb} +24 -3
- data/templates/default/service/client/method/{_def.erb → _def.text.erb} +2 -2
- data/templates/default/service/client/method/def/{_options_defaults.erb → _options_defaults.text.erb} +2 -1
- data/templates/default/service/client/method/def/_request_normal.text.erb +18 -0
- data/templates/default/service/client/method/def/_request_streaming.text.erb +23 -0
- data/templates/default/service/client/method/def/{_response.erb → _response.text.erb} +2 -0
- data/templates/default/service/client/method/def/{_response_nonstandard_lro.erb → _response_nonstandard_lro.text.erb} +1 -1
- data/templates/default/service/client/method/def/_response_normal.text.erb +4 -0
- data/templates/default/service/client/method/def/{_response_normal.erb → _response_normal_lro.text.erb} +1 -3
- data/templates/default/service/client/method/def/{_response_paged.erb → _response_paged.text.erb} +1 -1
- data/templates/default/service/client/method/docs/{_request_normal.erb → _request_normal.text.erb} +1 -1
- data/templates/default/service/client/method/docs/_snippets.text.erb +6 -0
- data/templates/default/service/client/resource/_def.text.erb +7 -0
- data/templates/default/service/nonstandard_lro.text.erb +6 -0
- data/templates/default/service/rest/client/{_client.erb → _client.text.erb} +82 -13
- data/templates/default/service/rest/client/_config.text.erb +178 -0
- data/templates/default/service/rest/client/_operations.text.erb +124 -0
- data/templates/default/service/rest/client/method/{_def.erb → _def.text.erb} +7 -1
- data/templates/default/service/rest/client/method/def/{_options_defaults.erb → _options_defaults.text.erb} +8 -3
- data/templates/default/service/rest/client/method/def/{_response.erb → _response.text.erb} +4 -0
- data/templates/default/service/rest/client/method/def/{_response_nonstandard_lro.erb → _response_nonstandard_lro.text.erb} +5 -4
- data/templates/default/service/rest/client/method/def/_response_normal.text.erb +5 -0
- data/templates/default/service/rest/client/method/def/_response_normal_lro.text.erb +7 -0
- data/templates/default/service/rest/client/method/def/_response_paged.text.erb +7 -0
- data/templates/default/service/rest/client/method/def/_response_server_streaming.text.erb +11 -0
- data/templates/default/service/rest/client/method/docs/{_request.erb → _request.text.erb} +1 -3
- data/templates/default/service/rest/client/method/docs/_result.text.erb +10 -0
- data/templates/default/service/rest/client/method/docs/_snippets.text.erb +6 -0
- data/templates/default/service/{nonstandard_lro.erb → rest/nonstandard_lro.text.erb} +1 -1
- data/templates/default/service/rest/operations.text.erb +6 -0
- data/templates/default/service/rest/service_stub/_service_stub.text.erb +63 -0
- data/templates/default/service/rest/service_stub/grpc_transcoding_method/_def.text.erb +37 -0
- data/templates/default/service/rest/service_stub/method/_def.text.erb +35 -0
- data/templates/default/service/rest/service_stub/method/def/_response.text.erb +37 -0
- data/templates/default/service/rest/test/{client.erb → client.text.erb} +3 -3
- data/templates/default/service/rest/test/method/_assert_response.text.erb +2 -0
- data/templates/default/service/rest/test/method/{_configure.erb → _configure.text.erb} +3 -2
- data/templates/default/service/rest/test/method/_normal.text.erb +60 -0
- data/templates/default/service/rest/test/method/_server.text.erb +60 -0
- data/templates/default/service/rest/test/method/{_setup.erb → _setup.text.erb} +26 -10
- data/templates/default/service/test/{_resource.erb → _resource.text.erb} +1 -1
- data/templates/default/service/test/{client.erb → client.text.erb} +3 -2
- data/templates/default/service/test/client_paths.text.erb +33 -0
- data/templates/default/service/test/method/{_bidi.erb → _bidi.text.erb} +1 -1
- data/templates/default/service/test/method/{_client.erb → _client.text.erb} +1 -1
- data/templates/default/service/test/method/{_configure.erb → _configure.text.erb} +2 -1
- data/templates/default/service/test/method/{_normal.erb → _normal.text.erb} +1 -1
- data/templates/default/service/test/method/{_server.erb → _server.text.erb} +1 -1
- data/templates/default/service/test/method/{_setup.erb → _setup.text.erb} +19 -2
- data/templates/default/snippets/{gemfile.erb → gemfile.text.erb} +2 -2
- data/templates/default/snippets/snippet/_body.text.erb +24 -0
- data/templates/default/snippets/snippet/_inline.text.erb +11 -0
- data/templates/default/snippets/snippet/_standalone.text.erb +25 -0
- data/templates/default/snippets/{standalone.erb → standalone.text.erb} +1 -1
- metadata +199 -274
- data/lib/google/api/annotations.pb.rb +0 -39
- data/lib/google/api/auth.pb.rb +0 -75
- data/lib/google/api/backend.pb.rb +0 -59
- data/lib/google/api/billing.pb.rb +0 -53
- data/lib/google/api/client.pb.rb +0 -43
- data/lib/google/api/context.pb.rb +0 -47
- data/lib/google/api/control.pb.rb +0 -38
- data/lib/google/api/documentation.pb.rb +0 -56
- data/lib/google/api/endpoint.pb.rb +0 -42
- data/lib/google/api/field_behavior.pb.rb +0 -51
- data/lib/google/api/http.pb.rb +0 -60
- data/lib/google/api/label.pb.rb +0 -49
- data/lib/google/api/launch_stage.pb.rb +0 -37
- data/lib/google/api/log.pb.rb +0 -47
- data/lib/google/api/logging.pb.rb +0 -48
- data/lib/google/api/metric.pb.rb +0 -90
- data/lib/google/api/monitored_resource.pb.rb +0 -68
- data/lib/google/api/monitoring.pb.rb +0 -48
- data/lib/google/api/quota.pb.rb +0 -63
- data/lib/google/api/resource.pb.rb +0 -80
- data/lib/google/api/routing.pb.rb +0 -58
- data/lib/google/api/service.pb.rb +0 -90
- data/lib/google/api/source_info.pb.rb +0 -44
- data/lib/google/api/system_parameter.pb.rb +0 -51
- data/lib/google/api/usage.pb.rb +0 -47
- data/lib/google/cloud/extended_operations.pb.rb +0 -57
- data/lib/google/longrunning/operations.pb.rb +0 -115
- data/lib/google/protobuf/any.pb.rb +0 -40
- data/lib/google/protobuf/api.pb.rb +0 -69
- data/lib/google/protobuf/compiler/plugin.pb.rb +0 -79
- data/lib/google/protobuf/descriptor.pb.rb +0 -360
- data/lib/google/protobuf/duration.pb.rb +0 -41
- data/lib/google/protobuf/empty.pb.rb +0 -36
- data/lib/google/protobuf/source_context.pb.rb +0 -39
- data/lib/google/protobuf/struct.pb.rb +0 -65
- data/lib/google/protobuf/type.pb.rb +0 -128
- data/lib/google/protobuf/wrappers.pb.rb +0 -80
- data/lib/google/rpc/status.pb.rb +0 -46
- data/templates/default/gem/gemfile.erb +0 -4
- data/templates/default/lib/rest/_rest.erb +0 -9
- data/templates/default/service/client/method/def/_request_normal.erb +0 -4
- data/templates/default/service/client/method/def/_request_streaming.erb +0 -9
- data/templates/default/service/client/method/docs/_deprecated.erb +0 -5
- data/templates/default/service/client/method/docs/_snippets.erb +0 -6
- data/templates/default/service/client/resource/_def.erb +0 -6
- data/templates/default/service/rest/client/_config.erb +0 -122
- data/templates/default/service/rest/client/method/def/_response_normal.erb +0 -6
- data/templates/default/service/rest/client/method/def/_response_paged.erb +0 -7
- data/templates/default/service/rest/client/method/docs/_result.erb +0 -6
- data/templates/default/service/rest/service_stub/_service_stub.erb +0 -25
- data/templates/default/service/rest/service_stub/grpc_transcoding_method/_def.erb +0 -24
- data/templates/default/service/rest/service_stub/method/_def.erb +0 -20
- data/templates/default/service/rest/service_stub/method/def/_response.erb +0 -17
- data/templates/default/service/rest/test/method/_assert_response.erb +0 -2
- data/templates/default/service/rest/test/method/_normal.erb +0 -71
- data/templates/default/service/test/client_paths.erb +0 -15
- data/templates/default/snippets/snippet/_structure.erb +0 -71
- /data/gem_templates/{binary.erb → binary.text.erb} +0 -0
- /data/gem_templates/{dockerfile.erb → dockerfile.text.erb} +0 -0
- /data/gem_templates/{entrypoint.erb → entrypoint.text.erb} +0 -0
- /data/gem_templates/{gapic_sh.erb → gapic_sh.text.erb} +0 -0
- /data/gem_templates/{gemfile.erb → gemfile.text.erb} +0 -0
- /data/gem_templates/{gemspec.erb → gemspec.text.erb} +0 -0
- /data/gem_templates/{generator.erb → generator.text.erb} +0 -0
- /data/gem_templates/{gitignore.erb → gitignore.text.erb} +0 -0
- /data/gem_templates/{rakefile.erb → rakefile.text.erb} +0 -0
- /data/gem_templates/{readme.erb → readme.text.erb} +0 -0
- /data/gem_templates/{rubocop.erb → rubocop.text.erb} +0 -0
- /data/gem_templates/shared/{_header.erb → _header.text.erb} +0 -0
- /data/gem_templates/shared/{_license.erb → _license.text.erb} +0 -0
- /data/gem_templates/shared/{_warning.erb → _warning.text.erb} +0 -0
- /data/gem_templates/{test_generator.erb → test_generator.text.erb} +0 -0
- /data/gem_templates/{test_helper.erb → test_helper.text.erb} +0 -0
- /data/gem_templates/{version.erb → version.text.erb} +0 -0
- /data/templates/default/gem/{_version.erb → _version.text.erb} +0 -0
- /data/templates/default/gem/{changelog.erb → changelog.text.erb} +0 -0
- /data/templates/default/gem/{entrypoint.erb → entrypoint.text.erb} +0 -0
- /data/templates/default/gem/{gapic_metadata_json.erb → gapic_metadata_json.text.erb} +0 -0
- /data/templates/default/gem/{gitignore.erb → gitignore.text.erb} +0 -0
- /data/templates/default/gem/{license.erb → license.text.erb} +0 -0
- /data/templates/default/gem/{rakefile.erb → rakefile.text.erb} +0 -0
- /data/templates/default/gem/{version.erb → version.text.erb} +0 -0
- /data/templates/default/gem/{yardopts.erb → yardopts.text.erb} +0 -0
- /data/templates/default/layouts/{_ruby.erb → _ruby.text.erb} +0 -0
- /data/templates/default/{package.erb → package.text.erb} +0 -0
- /data/templates/default/proto_docs/{_proto_file.erb → _proto_file.text.erb} +0 -0
- /data/templates/default/proto_docs/{proto_file.erb → proto_file.text.erb} +0 -0
- /data/templates/default/proto_docs/{readme.erb → readme.text.erb} +0 -0
- /data/templates/default/service/{_helpers.erb → _helpers.text.erb} +0 -0
- /data/templates/default/service/client/{_credentials.erb → _credentials.text.erb} +0 -0
- /data/templates/default/service/client/{_nonstandard_lro.erb → _nonstandard_lro.text.erb} +0 -0
- /data/templates/default/service/client/{_paths.erb → _paths.text.erb} +0 -0
- /data/templates/default/service/client/{_requires.erb → _requires.text.erb} +0 -0
- /data/templates/default/service/client/{_resource.erb → _resource.text.erb} +0 -0
- /data/templates/default/service/client/{_self_configure.erb → _self_configure.text.erb} +0 -0
- /data/templates/default/service/client/{_self_configure_defaults.erb → _self_configure_defaults.text.erb} +0 -0
- /data/templates/default/service/client/method/def/{_request.erb → _request.text.erb} +0 -0
- /data/templates/default/service/client/method/def/{_rescue.erb → _rescue.text.erb} +0 -0
- /data/templates/default/service/client/method/def/{_routing_params.erb → _routing_params.text.erb} +0 -0
- /data/templates/default/service/client/method/docs/{_error.erb → _error.text.erb} +0 -0
- /data/templates/default/service/client/method/docs/{_request.erb → _request.text.erb} +0 -0
- /data/templates/default/service/client/method/docs/{_request_field.erb → _request_field.text.erb} +0 -0
- /data/templates/default/service/client/method/docs/{_request_streaming.erb → _request_streaming.text.erb} +0 -0
- /data/templates/default/service/client/method/docs/{_response.erb → _response.text.erb} +0 -0
- /data/templates/default/service/client/method/docs/{_sample.erb → _sample.text.erb} +0 -0
- /data/templates/default/service/client/method/docs/{_sample_response.erb → _sample_response.text.erb} +0 -0
- /data/templates/default/service/client/method/docs/{_samples.erb → _samples.text.erb} +0 -0
- /data/templates/default/service/client/method/docs/request_field/{_arg.erb → _arg.text.erb} +0 -0
- /data/templates/default/service/client/method/docs/request_field/{_hash.erb → _hash.text.erb} +0 -0
- /data/templates/default/service/client/method/docs/sample_response/{_comment.erb → _comment.text.erb} +0 -0
- /data/templates/default/service/client/method/docs/sample_response/{_define.erb → _define.text.erb} +0 -0
- /data/templates/default/service/client/method/docs/sample_response/{_loop.erb → _loop.text.erb} +0 -0
- /data/templates/default/service/client/method/docs/sample_response/{_print.erb → _print.text.erb} +0 -0
- /data/templates/default/service/client/method/docs/sample_response/{_write_file.erb → _write_file.text.erb} +0 -0
- /data/templates/default/service/client/resource/{_doc.erb → _doc.text.erb} +0 -0
- /data/templates/default/service/client/resource/{_multi.erb → _multi.text.erb} +0 -0
- /data/templates/default/service/client/resource/{_single.erb → _single.text.erb} +0 -0
- /data/templates/default/service/{client.erb → client.text.erb} +0 -0
- /data/templates/default/service/{credentials.erb → credentials.text.erb} +0 -0
- /data/templates/default/service/{operations.erb → operations.text.erb} +0 -0
- /data/templates/default/service/{paths.erb → paths.text.erb} +0 -0
- /data/templates/default/service/rest/client/method/def/{_rescue.erb → _rescue.text.erb} +0 -0
- /data/templates/default/service/rest/client/method/docs/{_error.erb → _error.text.erb} +0 -0
- /data/templates/default/service/rest/{client.erb → client.text.erb} +0 -0
- /data/templates/default/service/rest/{grpc_transcoding.erb → grpc_transcoding.text.erb} +0 -0
- /data/templates/default/service/rest/service_stub/grpc_transcoding_method/def/{_query_string_param.erb → _query_string_param.text.erb} +0 -0
- /data/templates/default/service/rest/service_stub/method/def/{_request.erb → _request.text.erb} +0 -0
- /data/templates/default/service/rest/{service_stub.erb → service_stub.text.erb} +0 -0
- /data/templates/default/service/{rest.erb → rest.text.erb} +0 -0
- /data/templates/default/service/test/{client_operations.erb → client_operations.text.erb} +0 -0
- /data/templates/default/service/test/method/{_assert_response.erb → _assert_response.text.erb} +0 -0
- /data/templates/default/service/test/{smoke.erb → smoke.text.erb} +0 -0
- /data/templates/default/{service.erb → service.text.erb} +0 -0
- /data/templates/default/shared/{_header.erb → _header.text.erb} +0 -0
- /data/templates/default/shared/{_license.erb → _license.text.erb} +0 -0
- /data/templates/default/shared/{_warning.erb → _warning.text.erb} +0 -0
@@ -23,99 +23,197 @@ module Gapic
|
|
23
23
|
# The information used in the generation process that
|
24
24
|
# can be gathered from the `google.api.http` annotation.
|
25
25
|
# `google.api.http` is used in two distinct ways:
|
26
|
-
# -
|
27
|
-
# -
|
26
|
+
# - REST libs use it as part of the transcoding to set up the REST call
|
27
|
+
# - gRPC libs use it as a source of implicit routing headers
|
28
28
|
#
|
29
29
|
class HttpAnnotation
|
30
30
|
##
|
31
|
-
#
|
31
|
+
# The Http bindings found in the annotation
|
32
|
+
# this includes main binding in the annotation itself,
|
33
|
+
# as well as those in the `additional_bindings`.
|
32
34
|
#
|
33
|
-
|
34
|
-
|
35
|
+
# @return [Array<HttpBinding>]
|
36
|
+
attr_reader :bindings
|
37
|
+
|
38
|
+
##
|
39
|
+
# @param proto_http [::Google::Api::HttpRule]
|
40
|
+
# The base http annotation
|
41
|
+
#
|
42
|
+
def initialize proto_http
|
43
|
+
@bindings = parse_bindings proto_http
|
35
44
|
end
|
36
45
|
|
37
46
|
##
|
38
|
-
# Whether
|
47
|
+
# Whether any implicit routing parameters are present.
|
39
48
|
#
|
40
49
|
# @return [Boolean]
|
41
|
-
def
|
42
|
-
|
50
|
+
def routing_params?
|
51
|
+
routing_params.any?
|
43
52
|
end
|
44
53
|
|
45
54
|
##
|
46
|
-
# The
|
55
|
+
# The implicit routing parameter names.
|
47
56
|
#
|
48
|
-
# @return [
|
49
|
-
def
|
50
|
-
|
51
|
-
|
52
|
-
method = {
|
53
|
-
get: @proto_method.http.get,
|
54
|
-
post: @proto_method.http.post,
|
55
|
-
put: @proto_method.http.put,
|
56
|
-
patch: @proto_method.http.patch,
|
57
|
-
delete: @proto_method.http.delete
|
58
|
-
}.find { |_, value| !value.empty? }
|
59
|
-
|
60
|
-
method[0] unless method.nil?
|
57
|
+
# @return [Array<String>]
|
58
|
+
def routing_params
|
59
|
+
routing_params_with_patterns.map { |param, _| param }
|
61
60
|
end
|
62
61
|
|
63
62
|
##
|
64
|
-
#
|
63
|
+
# The implicit routing parameter names and their corresponding paterns,
|
64
|
+
# including the `*` pattern implied for the named segments
|
65
|
+
# without an explicitly specified pattern.
|
65
66
|
#
|
66
|
-
# @return [
|
67
|
-
def
|
68
|
-
|
67
|
+
# @return [Array<Array<String>>]
|
68
|
+
def routing_params_with_patterns
|
69
|
+
bindings.first&.routing_params_with_patterns || []
|
69
70
|
end
|
70
71
|
|
71
72
|
##
|
72
|
-
#
|
73
|
+
# @param proto_method [::Gapic::Schema::Method]
|
74
|
+
# The proto method this annotation model applies to
|
75
|
+
# @param service_config [::Google::Api::Service]
|
76
|
+
# The service config that might contain an override for the http annotation.
|
77
|
+
# This is used for mixins: when generating Operations sublients, and when
|
78
|
+
# setting up overrides for other mixin clients in the host services's classes.
|
79
|
+
# For non-mixin service generation
|
80
|
+
# it is assumed that the service config is merged into protos before generation.
|
73
81
|
#
|
74
|
-
|
75
|
-
|
76
|
-
return "" if @proto_method.http.nil?
|
82
|
+
def self.create_with_override proto_method, service_config = nil
|
83
|
+
proto_http = proto_method.http
|
77
84
|
|
78
|
-
|
79
|
-
@proto_method.http.get, @proto_method.http.post, @proto_method.http.put,
|
80
|
-
@proto_method.http.patch, @proto_method.http.delete
|
81
|
-
].find { |x| !x.empty? }
|
85
|
+
http_override = service_config&.http&.rules&.find { |http_rule| http_rule.selector == proto_method.full_name }
|
82
86
|
|
83
|
-
|
87
|
+
http = http_override || proto_http
|
88
|
+
HttpAnnotation.new http
|
84
89
|
end
|
85
90
|
|
86
91
|
##
|
87
|
-
#
|
92
|
+
# A single Http binding.
|
88
93
|
#
|
89
|
-
|
90
|
-
|
91
|
-
|
94
|
+
class HttpBinding
|
95
|
+
##
|
96
|
+
# @param binding [::Google::Api::HttpRule]
|
97
|
+
# The baseline instance of the Http annotation
|
98
|
+
def initialize binding
|
99
|
+
@binding = binding
|
100
|
+
end
|
101
|
+
|
102
|
+
##
|
103
|
+
# Whether a http verb is present for this method
|
104
|
+
#
|
105
|
+
# @return [Boolean]
|
106
|
+
def verb?
|
107
|
+
!verb.nil?
|
108
|
+
end
|
109
|
+
|
110
|
+
##
|
111
|
+
# The http verb for this method
|
112
|
+
#
|
113
|
+
# @return [Symbol, nil]
|
114
|
+
def verb
|
115
|
+
verb_path[0] if verb_path
|
116
|
+
end
|
117
|
+
|
118
|
+
##
|
119
|
+
# Whether a method path is present and non-empty
|
120
|
+
#
|
121
|
+
# @return [Boolean]
|
122
|
+
def path?
|
123
|
+
!path.empty?
|
124
|
+
end
|
125
|
+
|
126
|
+
##
|
127
|
+
# A method path or an empty string if not present
|
128
|
+
#
|
129
|
+
# @return [String]
|
130
|
+
def path
|
131
|
+
return "" unless verb_path
|
132
|
+
verb_path[1]
|
133
|
+
end
|
134
|
+
|
135
|
+
##
|
136
|
+
# Whether any routing params are present
|
137
|
+
#
|
138
|
+
# @return [Boolean]
|
139
|
+
def routing_params?
|
140
|
+
routing_params.any?
|
141
|
+
end
|
142
|
+
|
143
|
+
##
|
144
|
+
# The segment key names and their corresponding paterns,
|
145
|
+
# including the `*` pattern implied for the named segments
|
146
|
+
# without pattern explicitly specified.
|
147
|
+
#
|
148
|
+
# @return [Array<Array<String>>]
|
149
|
+
def routing_params_with_patterns
|
150
|
+
@routing_params_with_patterns ||= begin
|
151
|
+
Gapic::UriTemplate.parse_arguments(path).map do |name, pattern|
|
152
|
+
[name, pattern.empty? ? "*" : pattern]
|
153
|
+
end
|
154
|
+
end
|
155
|
+
end
|
156
|
+
|
157
|
+
##
|
158
|
+
# The segment key names.
|
159
|
+
#
|
160
|
+
# @return [Array<String>]
|
161
|
+
def routing_params
|
162
|
+
routing_params_with_patterns.map { |param, _| param }
|
163
|
+
end
|
164
|
+
|
165
|
+
##
|
166
|
+
# Whether method has body specified in proto
|
167
|
+
#
|
168
|
+
# @return [Boolean]
|
169
|
+
def body?
|
170
|
+
!body.empty?
|
171
|
+
end
|
172
|
+
|
173
|
+
##
|
174
|
+
# The body specified for the given method in proto
|
175
|
+
# or an empty string if not specified
|
176
|
+
#
|
177
|
+
# @return [String]
|
178
|
+
def body
|
179
|
+
@binding&.body || ""
|
180
|
+
end
|
181
|
+
|
182
|
+
private
|
183
|
+
|
184
|
+
##
|
185
|
+
# The combination of verb and path found in the http annotation
|
186
|
+
# (or Nil if the annotation is Nil).
|
187
|
+
#
|
188
|
+
# @return [Array<Symbol, String>, Nil]
|
189
|
+
def verb_path
|
190
|
+
return nil if @binding.nil?
|
191
|
+
|
192
|
+
{
|
193
|
+
get: @binding.get,
|
194
|
+
post: @binding.post,
|
195
|
+
put: @binding.put,
|
196
|
+
patch: @binding.patch,
|
197
|
+
delete: @binding.delete
|
198
|
+
}.find { |_, value| !value.empty? }
|
199
|
+
end
|
92
200
|
end
|
93
201
|
|
94
|
-
|
95
|
-
# The segment key names.
|
96
|
-
#
|
97
|
-
# @return [Array<String>]
|
98
|
-
def routing_params
|
99
|
-
Gapic::UriTemplate.parse_arguments path
|
100
|
-
end
|
202
|
+
private
|
101
203
|
|
102
204
|
##
|
103
|
-
#
|
205
|
+
# Parses http bindings from the `google.api.http` annotation, preserving order.
|
104
206
|
#
|
105
|
-
# @
|
106
|
-
|
107
|
-
return false if @proto_method.http.nil?
|
108
|
-
|
109
|
-
!@proto_method.http.body.empty?
|
110
|
-
end
|
111
|
-
|
112
|
-
##
|
113
|
-
# The body specified for the given method in proto
|
114
|
-
# or an empty string if not specified
|
207
|
+
# @param http [::Google::Api::HttpRule]
|
208
|
+
# The root instance of the HttpRule to parse.
|
115
209
|
#
|
116
|
-
# @return
|
117
|
-
|
118
|
-
|
210
|
+
# @return Array<HttpBinding>
|
211
|
+
# The parsed bindings.
|
212
|
+
def parse_bindings http
|
213
|
+
return [] if http.nil?
|
214
|
+
|
215
|
+
raw_binds = [http] + http.additional_bindings.to_a
|
216
|
+
raw_binds.map { |raw_bind| HttpBinding.new raw_bind }
|
119
217
|
end
|
120
218
|
end
|
121
219
|
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 "singleton"
|
18
|
+
|
17
19
|
require "gapic/path_pattern"
|
18
20
|
|
19
21
|
module Gapic
|
@@ -55,9 +57,9 @@ module Gapic
|
|
55
57
|
!f.operation_request_field.nil? && !f.operation_request_field.empty?
|
56
58
|
end
|
57
59
|
|
58
|
-
@operation_request_fields = ops_request_fields.
|
60
|
+
@operation_request_fields = ops_request_fields.to_h do |field|
|
59
61
|
[field.name, field.operation_request_field]
|
60
|
-
end
|
62
|
+
end
|
61
63
|
end
|
62
64
|
|
63
65
|
##
|
@@ -138,14 +140,15 @@ module Gapic
|
|
138
140
|
ops_service_lro = api.nonstandard_lro_model_for service_full_name
|
139
141
|
unless ops_service_lro.nonstandard_lro?
|
140
142
|
error_text = "A service #{service_full_name} specified as a nonstandard LRO service for " \
|
141
|
-
|
143
|
+
"the method #{method.full_name} was not found."
|
142
144
|
raise ModelError, error_text
|
143
145
|
end
|
144
146
|
|
145
147
|
unless method.output.full_name == ops_service_lro.lro_object_full_name
|
146
148
|
error_text = "A service #{service_full_name} specified as a nonstandard LRO service for " \
|
147
|
-
|
148
|
-
|
149
|
+
"the method #{method.full_name} has a different LRO object " \
|
150
|
+
"(#{ops_service_lro.lro_object_full_name}) from the method's return type " \
|
151
|
+
"(#{method.output.full_name})."
|
149
152
|
raise ModelError, error_text
|
150
153
|
end
|
151
154
|
|
@@ -175,8 +175,8 @@ module Gapic
|
|
175
175
|
end
|
176
176
|
|
177
177
|
@field_pattern = @path_pattern.simplified_pattern
|
178
|
-
@field_full_regex_str =
|
179
|
-
@field_regex_str =
|
178
|
+
@field_full_regex_str = @path_pattern.to_field_regex_str
|
179
|
+
@field_regex_str = Gapic::PathPattern.parse(@field_pattern).to_field_regex_str
|
180
180
|
|
181
181
|
@key = resource_segment.arguments[0]
|
182
182
|
@value_pattern = resource_segment.resource_patterns[0]
|
@@ -200,20 +200,6 @@ module Gapic
|
|
200
200
|
|
201
201
|
private
|
202
202
|
|
203
|
-
# Makes a regex pattern match a field
|
204
|
-
# - adds markers for the beginning and end of the string
|
205
|
-
# - adds handling of an optional tail `/` if needed
|
206
|
-
# @param pattern [String]
|
207
|
-
# @return [String]
|
208
|
-
def to_field_pattern pattern
|
209
|
-
tail_slash_accept = if pattern.segments.last.simplified_pattern == "**"
|
210
|
-
""
|
211
|
-
else
|
212
|
-
"/?"
|
213
|
-
end
|
214
|
-
"^#{pattern.to_regex_str}#{tail_slash_accept}$"
|
215
|
-
end
|
216
|
-
|
217
203
|
# Converts path template simplified forms into canonical
|
218
204
|
# ResourceId representations by adding a field as a Resource Id
|
219
205
|
# @param template [String]
|
@@ -244,8 +230,7 @@ module Gapic
|
|
244
230
|
"it contains a multivariate ResourceId segment (e.g. `{foo}~{bar}`)"
|
245
231
|
end
|
246
232
|
|
247
|
-
"A routing header parameter with the path_template #{raw_template}\n "
|
248
|
-
"is invalid: #{reason}"
|
233
|
+
"A routing header parameter with the path_template #{raw_template}\n is invalid: #{reason}"
|
249
234
|
end
|
250
235
|
end
|
251
236
|
|
data/lib/gapic/model/mixins.rb
CHANGED
@@ -36,9 +36,12 @@ module Gapic
|
|
36
36
|
# List of services from the Api model
|
37
37
|
# @param service_config [Google::Api::Service]
|
38
38
|
# The service config
|
39
|
-
|
39
|
+
# @param gem_name [String]
|
40
|
+
# The name of the gem.
|
41
|
+
def initialize api_services, service_config, gem_name
|
40
42
|
@api_services = api_services
|
41
43
|
@service_config = service_config
|
44
|
+
@gem_name = gem_name
|
42
45
|
end
|
43
46
|
|
44
47
|
# @return [Boolean] Whether there are any mix-in services
|
@@ -50,13 +53,14 @@ module Gapic
|
|
50
53
|
# List of Mixin objects, providing the information that is needed
|
51
54
|
# to add the mixin service references to the generated library
|
52
55
|
def mixins
|
53
|
-
@mixins ||= mixin_services.map { |service| create_mixin
|
56
|
+
@mixins ||= mixin_services.map { |service| create_mixin service }
|
54
57
|
end
|
55
58
|
|
56
59
|
# @return [Enumerable<String>] Full proto names of the mix-in services
|
57
60
|
def mixin_services
|
58
|
-
@mixin_services ||=
|
59
|
-
|
61
|
+
@mixin_services ||= begin
|
62
|
+
candidates = services_in_config & SERVICE_TO_DEPENDENCY.keys
|
63
|
+
candidates.reject { |name| SERVICE_TO_DEPENDENCY[name].include? @gem_name }
|
60
64
|
end
|
61
65
|
end
|
62
66
|
|
@@ -77,12 +81,21 @@ module Gapic
|
|
77
81
|
# @!attribute [r] require_str
|
78
82
|
# Path to `require` the client of the service
|
79
83
|
# @return [String]
|
84
|
+
# @!attribute [r] require_str_rest
|
85
|
+
# Path to `require` the REST client of the service
|
86
|
+
# @return [String]
|
80
87
|
# @!attribute [r] client_class_name
|
81
88
|
# Full name of the class of the client of the service
|
82
89
|
# @return [String]
|
90
|
+
# @!attribute [r] client_class_name_rest
|
91
|
+
# Full name of the class of the REST client of the service
|
92
|
+
# @return [String]
|
83
93
|
# @!attribute [r] client_class_docname
|
84
94
|
# Name of the class as it should appear in the documentation
|
85
95
|
# @return [String]
|
96
|
+
# @!attribute [r] client_class_docname_rest
|
97
|
+
# Name of the REST class as it should appear in the documentation
|
98
|
+
# @return [String]
|
86
99
|
# @!attribute [r] client_var_name
|
87
100
|
# Name for the variable for the client of the
|
88
101
|
# mixin service to use when generating library's service
|
@@ -91,8 +104,11 @@ module Gapic
|
|
91
104
|
attr_reader :service
|
92
105
|
attr_reader :dependency
|
93
106
|
attr_reader :require_str
|
107
|
+
attr_reader :require_str_rest
|
94
108
|
attr_reader :client_class_name
|
109
|
+
attr_reader :client_class_name_rest
|
95
110
|
attr_reader :client_class_docname
|
111
|
+
attr_reader :client_class_docname_rest
|
96
112
|
attr_reader :client_var_name
|
97
113
|
|
98
114
|
# @param service [String]
|
@@ -102,17 +118,25 @@ module Gapic
|
|
102
118
|
# `{ gem_name => version pattern }` format
|
103
119
|
# @param require_str [String]
|
104
120
|
# Path to require the client of the service
|
121
|
+
# @param require_str_rest [String]
|
122
|
+
# Path to require the REST client of the service
|
105
123
|
# @param client_class_name [String]
|
106
124
|
# Full name of the class of the client of the service
|
125
|
+
# @param client_class_name_rest [String]
|
126
|
+
# Full name of the class of the REST client of the service
|
107
127
|
# @param client_var_name [String]
|
108
128
|
# Name for the variable for the client of the mixin service
|
109
129
|
# to use when generating library's service
|
110
|
-
def initialize service, dependency, require_str, client_class_name,
|
130
|
+
def initialize service, dependency, require_str, require_str_rest, client_class_name, client_class_name_rest,
|
131
|
+
client_var_name
|
111
132
|
@service = service
|
112
133
|
@dependency = dependency
|
113
134
|
@require_str = require_str
|
135
|
+
@require_str_rest = require_str_rest
|
114
136
|
@client_class_name = client_class_name
|
137
|
+
@client_class_name_rest = client_class_name_rest
|
115
138
|
@client_class_docname = client_class_name # For mixins, the doc name should be the full class name
|
139
|
+
@client_class_docname_rest = client_class_name_rest # For mixins, the doc name should be the full class name
|
116
140
|
@client_var_name = client_var_name
|
117
141
|
end
|
118
142
|
|
@@ -123,6 +147,21 @@ module Gapic
|
|
123
147
|
end
|
124
148
|
end
|
125
149
|
|
150
|
+
##
|
151
|
+
# Returns true if the given service address is a mixin.
|
152
|
+
# This just checks the service against a (hard-coded) set of known mixins.
|
153
|
+
# If `gem_name` is provided, services that correspond to that gem_name are not considered mixins.
|
154
|
+
#
|
155
|
+
# @param service_address [String,Array<String>] The address (either array
|
156
|
+
# or dot-delimited) of the service to check.
|
157
|
+
# @param gem_name [String] The name of the gem.
|
158
|
+
# @return [boolean]
|
159
|
+
#
|
160
|
+
def self.mixin_service_address? service_address, gem_name: nil
|
161
|
+
service_address = service_address.join "." unless service_address.is_a? String
|
162
|
+
MIXIN_GEM_NAMES.include?(service_address) && gem_name != MIXIN_GEM_NAMES[service_address]
|
163
|
+
end
|
164
|
+
|
126
165
|
private
|
127
166
|
|
128
167
|
# @return [Enumerable<String>] Names of all services that are specified
|
@@ -133,28 +172,51 @@ module Gapic
|
|
133
172
|
@service_config.apis.map(&:name)
|
134
173
|
end
|
135
174
|
|
175
|
+
MIXIN_GEM_NAMES = {
|
176
|
+
LOCATIONS_SERVICE => "google-cloud-location",
|
177
|
+
IAM_SERVICE => "google-iam-v1",
|
178
|
+
LRO_SERVICE => "google-longrunning-operations"
|
179
|
+
}.freeze
|
180
|
+
private_constant :MIXIN_GEM_NAMES
|
181
|
+
|
136
182
|
# Since mixins are scope-limited to a couple of services, it is easier to
|
137
183
|
# have these in lookup tables than to construct a ServicePresenter
|
138
184
|
|
139
185
|
SERVICE_TO_DEPENDENCY = {
|
140
|
-
LOCATIONS_SERVICE => { "google-cloud-location" => "~> 0
|
141
|
-
IAM_SERVICE => { "google-iam-v1" => "~>
|
186
|
+
LOCATIONS_SERVICE => { "google-cloud-location" => ["~> 1.0"] },
|
187
|
+
IAM_SERVICE => { "google-iam-v1" => ["~> 1.3"] }
|
142
188
|
}.freeze
|
189
|
+
private_constant :SERVICE_TO_DEPENDENCY
|
143
190
|
|
144
191
|
SERVICE_TO_REQUIRE_STR = {
|
145
192
|
LOCATIONS_SERVICE => "google/cloud/location",
|
146
|
-
IAM_SERVICE => "google/iam/v1
|
193
|
+
IAM_SERVICE => "google/iam/v1"
|
194
|
+
}.freeze
|
195
|
+
private_constant :SERVICE_TO_REQUIRE_STR
|
196
|
+
|
197
|
+
SERVICE_TO_REQUIRE_STR_REST = {
|
198
|
+
LOCATIONS_SERVICE => "google/cloud/location/rest",
|
199
|
+
IAM_SERVICE => "google/iam/v1/rest"
|
147
200
|
}.freeze
|
201
|
+
private_constant :SERVICE_TO_REQUIRE_STR_REST
|
148
202
|
|
149
203
|
SERVICE_TO_CLIENT_CLASS_NAME = {
|
150
204
|
LOCATIONS_SERVICE => "Google::Cloud::Location::Locations::Client",
|
151
205
|
IAM_SERVICE => "Google::Iam::V1::IAMPolicy::Client"
|
152
206
|
}.freeze
|
207
|
+
private_constant :SERVICE_TO_CLIENT_CLASS_NAME
|
208
|
+
|
209
|
+
SERVICE_TO_CLIENT_CLASS_NAME_REST = {
|
210
|
+
LOCATIONS_SERVICE => "Google::Cloud::Location::Locations::Rest::Client",
|
211
|
+
IAM_SERVICE => "Google::Iam::V1::IAMPolicy::Rest::Client"
|
212
|
+
}.freeze
|
213
|
+
private_constant :SERVICE_TO_CLIENT_CLASS_NAME_REST
|
153
214
|
|
154
215
|
SERVICE_TO_CLIENT_ATTR_NAME = {
|
155
216
|
LOCATIONS_SERVICE => "location_client",
|
156
217
|
IAM_SERVICE => "iam_policy_client"
|
157
218
|
}.freeze
|
219
|
+
private_constant :SERVICE_TO_CLIENT_ATTR_NAME
|
158
220
|
|
159
221
|
# @param service [String] full grpc name of the service
|
160
222
|
# @raise [ModelError]
|
@@ -162,8 +224,10 @@ module Gapic
|
|
162
224
|
def create_mixin service
|
163
225
|
unless SERVICE_TO_DEPENDENCY.key?(service) &&
|
164
226
|
SERVICE_TO_REQUIRE_STR.key?(service) &&
|
165
|
-
|
166
|
-
|
227
|
+
SERVICE_TO_REQUIRE_STR_REST.key?(service) &&
|
228
|
+
SERVICE_TO_CLIENT_CLASS_NAME.key?(service) &&
|
229
|
+
SERVICE_TO_CLIENT_CLASS_NAME_REST.key?(service) &&
|
230
|
+
SERVICE_TO_CLIENT_ATTR_NAME.key?(service)
|
167
231
|
|
168
232
|
error_text = "A mixin service #{service} is specified in service config, but " \
|
169
233
|
"the Generator does not know of it."
|
@@ -173,7 +237,9 @@ module Gapic
|
|
173
237
|
Mixin.new service,
|
174
238
|
SERVICE_TO_DEPENDENCY[service],
|
175
239
|
SERVICE_TO_REQUIRE_STR[service],
|
240
|
+
SERVICE_TO_REQUIRE_STR_REST[service],
|
176
241
|
SERVICE_TO_CLIENT_CLASS_NAME[service],
|
242
|
+
SERVICE_TO_CLIENT_CLASS_NAME_REST[service],
|
177
243
|
SERVICE_TO_CLIENT_ATTR_NAME[service]
|
178
244
|
end
|
179
245
|
end
|
@@ -114,7 +114,6 @@ module Gapic
|
|
114
114
|
operation_err_code_field,
|
115
115
|
operation_err_msg_field,
|
116
116
|
operation_response_fields
|
117
|
-
|
118
117
|
@service_full_name = service_full_name
|
119
118
|
@polling_method_name = polling_method_name
|
120
119
|
@lro_object_full_name = lro_object_full_name
|
@@ -166,11 +165,11 @@ module Gapic
|
|
166
165
|
if nonstandard_lro_candidates.length.positive?
|
167
166
|
ops_service_method = nonstandard_lro_candidates[0]
|
168
167
|
error_text = "A service `#{service.name}` has a method annotated " \
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
168
|
+
"with `polling_method` (`#{polling_method.name}`), and also a method annotated " \
|
169
|
+
"with `operation_service` (`#{ops_service_method.name}`). " \
|
170
|
+
"This means a grpc service tries to be a client " \
|
171
|
+
"and a provider of the nonstandard LRO at the same time. " \
|
172
|
+
"This is not supported."
|
174
173
|
raise ModelError, error_text
|
175
174
|
end
|
176
175
|
|
@@ -191,9 +190,9 @@ module Gapic
|
|
191
190
|
!f.operation_response_field.nil? && !f.operation_response_field.empty?
|
192
191
|
end
|
193
192
|
|
194
|
-
operation_response_fields = ops_response_fields.
|
193
|
+
operation_response_fields = ops_response_fields.to_h do |field|
|
195
194
|
[field.name, field.operation_response_field]
|
196
|
-
end
|
195
|
+
end
|
197
196
|
|
198
197
|
NonstandardLroProvider.new service.full_name,
|
199
198
|
polling_method.name,
|
@@ -221,7 +220,7 @@ module Gapic
|
|
221
220
|
name_candidate = polling_method.output.fields.find do |f|
|
222
221
|
f.operation_field == ops_response_field
|
223
222
|
end
|
224
|
-
|
223
|
+
name_candidate&.name
|
225
224
|
end
|
226
225
|
|
227
226
|
##
|
@@ -242,7 +241,7 @@ module Gapic
|
|
242
241
|
end
|
243
242
|
if polling_method_candidates.length > 1
|
244
243
|
error_text = "A service #{service.name} has more than one method annotated " \
|
245
|
-
|
244
|
+
"with `operation_polling_method`. This should not happen."
|
246
245
|
raise ModelError, error_text
|
247
246
|
end
|
248
247
|
|
@@ -277,7 +276,7 @@ module Gapic
|
|
277
276
|
raise ModelError, error_text
|
278
277
|
end
|
279
278
|
|
280
|
-
if status_candidates.
|
279
|
+
if status_candidates.empty?
|
281
280
|
error_text = "A nonstandard LRO provider service `#{service.name}`'s " \
|
282
281
|
"polling method `#{polling_method.name}`'s output message " \
|
283
282
|
"`#{polling_method.output.name}` does not have any fields annotated " \
|