diff --git a/gapic-generator/lib/gapic/presenters/resource_presenter.rb b/gapic-generator/lib/gapic/presenters/resource_presenter.rb index 39ba0d719..40a0355b5 100644 --- a/gapic-generator/lib/gapic/presenters/resource_presenter.rb +++ b/gapic-generator/lib/gapic/presenters/resource_presenter.rb @@ -26,10 +26,13 @@ class ResourcePresenter def initialize resource @resource = resource - @patterns = resource.pattern.map { |pattern| PatternPresenter.new pattern } + all_patterns = resource.pattern.map { |pattern| PatternPresenter.new pattern } # Keep only patterns that can be used to create path helpers - @patterns.filter!(&:useful_for_helpers?) + all_useful_patterns = all_patterns.filter(&:useful_for_helpers?) + + # Remove patterns where key is duplicated + @patterns = ResourcePresenter.dedup_patterns all_useful_patterns end def dup @@ -52,6 +55,25 @@ def path_helper "#{ActiveSupport::Inflector.underscore name}_path" end + ## + # Deduplicates pattern that have the same `arguments_key`. Our design for the "paths" helper + # only allows for one pattern per `arguments_key`. + # + # If patterns with the same `arguments_key` are detected, the shortest is taken. If there is + # a tie, the lexicographically first is taken. + # + # @param patterns [Array] + # + # @return [Array] + # + def self.dedup_patterns patterns + patterns.group_by(&:arguments_key).map do |_arguments_key, group| + group.min_by do |pattern| + [pattern.pattern.length, pattern.pattern] + end + end + end + ## # A presenter for a particular pattern # diff --git a/gapic-generator/test/gapic/presenters/resource_presenter_test.rb b/gapic-generator/test/gapic/presenters/resource_presenter_test.rb new file mode 100644 index 000000000..bb3b33587 --- /dev/null +++ b/gapic-generator/test/gapic/presenters/resource_presenter_test.rb @@ -0,0 +1,88 @@ +# frozen_string_literal: true + +# Copyright 2025 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +require "test_helper" +require "gapic/presenters/resource_presenter" + +class ResourcePresenterTest < PresenterTest + def test_noargument_nodedup + patterns = [ + "hello/compatibility/world" + ].map { |pattern| Gapic::Presenters::ResourcePresenter::PatternPresenter.new pattern } + + deduped_patterns = Gapic::Presenters::ResourcePresenter.dedup_patterns(patterns).map(&:pattern) + + assert_equal ["hello/compatibility/world"], deduped_patterns + end + + def test_noargument_dedup + patterns = [ + "hello/world", + "hello/zorld", + "hello/compatibility/world" + ].map { |pattern| Gapic::Presenters::ResourcePresenter::PatternPresenter.new pattern } + + deduped_patterns = Gapic::Presenters::ResourcePresenter.dedup_patterns(patterns).map(&:pattern) + + assert_equal ["hello/world"], deduped_patterns + end + + def test_noargument_dedup_with_additional + patterns = [ + "hello/world", + "hello/compatibility/world", + "hello/{foo}/world/{world}" + ].map { |pattern| Gapic::Presenters::ResourcePresenter::PatternPresenter.new pattern } + + deduped_patterns = Gapic::Presenters::ResourcePresenter.dedup_patterns(patterns).map(&:pattern) + + assert_equal ["hello/world", "hello/{foo}/world/{world}"], deduped_patterns + end + + def test_argument_nodedup + patterns = [ + "hello/{foo}/world/{world}" + ].map { |pattern| Gapic::Presenters::ResourcePresenter::PatternPresenter.new pattern } + + deduped_patterns = Gapic::Presenters::ResourcePresenter.dedup_patterns(patterns).map(&:pattern) + + assert_equal ["hello/{foo}/world/{world}"], deduped_patterns + end + + def test_argument_dedup + patterns = [ + "hello/{foo}/world/{world}", + "hello/{foo}/compatibility/world/{world}", + "hello/{foo}/zorld/{world}" + ].map { |pattern| Gapic::Presenters::ResourcePresenter::PatternPresenter.new pattern } + + deduped_patterns = Gapic::Presenters::ResourcePresenter.dedup_patterns(patterns).map(&:pattern) + + assert_equal ["hello/{foo}/world/{world}"], deduped_patterns + end + + def test_argument_dedup_with_additional + patterns = [ + "hello/{foo}/world/{world}", + "hello/{foo}/compatibility/world/{world}", + "baz/{baz}" + ].map { |pattern| Gapic::Presenters::ResourcePresenter::PatternPresenter.new pattern } + + deduped_patterns = Gapic::Presenters::ResourcePresenter.dedup_patterns(patterns).map(&:pattern) + + assert_equal ["hello/{foo}/world/{world}", "baz/{baz}"], deduped_patterns + end +end diff --git a/shared/gem_defaults.rb b/shared/gem_defaults.rb index 71f8f39af..cfc5a5348 100644 --- a/shared/gem_defaults.rb +++ b/shared/gem_defaults.rb @@ -155,6 +155,7 @@ def gem_defaults "testing/grpc_service_config/grpc_service_config.proto", "testing/mixins/mixins.proto", "testing/routing_headers/routing_headers.proto", + "testing/resources/resources.proto", "testing/nonstandard_lro_grpc/nonstandard_lro_grpc.proto", # `locations.proto` is included here because it is often # included in the real world libraries diff --git a/shared/input/testing_desc.bin b/shared/input/testing_desc.bin index 6e78832e0..712908dfa 100644 Binary files a/shared/input/testing_desc.bin and b/shared/input/testing_desc.bin differ diff --git a/shared/output/gapic/templates/testing/lib/testing.rb b/shared/output/gapic/templates/testing/lib/testing.rb index 6a201bfba..d31f5ff82 100644 --- a/shared/output/gapic/templates/testing/lib/testing.rb +++ b/shared/output/gapic/templates/testing/lib/testing.rb @@ -29,4 +29,5 @@ # require "testing/grpc_service_config" # require "testing/mixins" # require "testing/nonstandard_lro_grpc" +# require "testing/resources" # require "testing/routing_headers" diff --git a/shared/output/gapic/templates/testing/lib/testing/resources.rb b/shared/output/gapic/templates/testing/lib/testing/resources.rb new file mode 100644 index 000000000..aea71d43b --- /dev/null +++ b/shared/output/gapic/templates/testing/lib/testing/resources.rb @@ -0,0 +1,44 @@ +# frozen_string_literal: true + +# The MIT License (MIT) +# +# Copyright +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in +# all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +# THE SOFTWARE. + +# Auto-generated by gapic-generator-ruby. DO NOT EDIT! + +require "testing/resources/service_resources" +require "testing/version" + +module Testing + ## + # API client module. + # + # @example Load this package, including all its services, and instantiate a gRPC client + # + # require "testing/resources" + # client = ::Testing::Resources::ServiceResources::Client.new + # + module Resources + end +end + +helper_path = ::File.join __dir__, "resources", "_helpers.rb" +require "testing/resources/_helpers" if ::File.file? helper_path diff --git a/shared/output/gapic/templates/testing/lib/testing/resources/resources_pb.rb b/shared/output/gapic/templates/testing/lib/testing/resources/resources_pb.rb new file mode 100644 index 000000000..225157433 --- /dev/null +++ b/shared/output/gapic/templates/testing/lib/testing/resources/resources_pb.rb @@ -0,0 +1,45 @@ +# frozen_string_literal: true +# Generated by the protocol buffer compiler. DO NOT EDIT! +# source: testing/resources/resources.proto + +require 'google/protobuf' + +require 'google/api/client_pb' +require 'google/api/resource_pb' + + +descriptor_data = "\n!testing/resources/resources.proto\x12\x11testing.resources\x1a\x17google/api/client.proto\x1a\x19google/api/resource.proto\"\xc6\x03\n\x0fRequestResource\x12\x15\n\rresource_name\x18\x01 \x01(\t:\x9b\x03\xea\x41\x97\x03\n#testing.example.com/RequestResource\x12:projects/{project}/resources/{resource}/versions/{version}\x12Mprojects/{project}/resources/{resource}/subjects/{subject}/versions/{version}\x12>projects/{project}/compatibility/resources/{resource}/versions\x12Hprojects/{project}/compatibility/resources/{resource}/versions/{version}\x12[projects/{project}/compatibility/resources/{resource}/subjects/{subject}/versions/{version}\"\xb6\x01\n\x16RequestAnotherResource\x12\x15\n\rresource_name\x18\x01 \x01(\t:\x84\x01\xea\x41\x80\x01\n*testing.example.com/RequestAnotherResource\x12\x12projects/responses\x12 projects/compatibility/responses\x12\x1cprojects/{project}/responses\"\x92\x01\n\x14RequestThirdResource\x12\x15\n\rresource_name\x18\x01 \x01(\t:c\xea\x41`\n(testing.example.com/RequestThirdResource\x12\x12projects/responses\x12 projects/compatibility/responses\"\xe6\x01\n\x15RequestFourthResource\x12\x15\n\rresource_name\x18\x01 \x01(\t:\xb5\x01\xea\x41\xb1\x01\n)testing.example.com/RequestFourthResource\x12:projects/{project}/resources/{resource}/versions/{version}\x12Hprojects/{project}/compatibility/resources/{resource}/versions/{version}\"\n\n\x08Response2\x80\x03\n\x10ServiceResources\x12J\n\x05Plain\x12\".testing.resources.RequestResource\x1a\x1b.testing.resources.Response\"\x00\x12X\n\x0c\x41notherPlain\x12).testing.resources.RequestAnotherResource\x1a\x1b.testing.resources.Response\"\x00\x12T\n\nThirdPlain\x12\'.testing.resources.RequestThirdResource\x1a\x1b.testing.resources.Response\"\x00\x12V\n\x0b\x46ourthPlain\x12(.testing.resources.RequestFourthResource\x1a\x1b.testing.resources.Response\"\x00\x1a\x18\xca\x41\x15resources.example.comB\x15\xea\x02\x12Testing::Resourcesb\x06proto3" + +pool = Google::Protobuf::DescriptorPool.generated_pool + +begin + pool.add_serialized_file(descriptor_data) +rescue TypeError + # Compatibility code: will be removed in the next major version. + require 'google/protobuf/descriptor_pb' + parsed = Google::Protobuf::FileDescriptorProto.decode(descriptor_data) + parsed.clear_dependency + serialized = parsed.class.encode(parsed) + file = pool.add_serialized_file(serialized) + warn "Warning: Protobuf detected an import path issue while loading generated file #{__FILE__}" + imports = [ + ] + imports.each do |type_name, expected_filename| + import_file = pool.lookup(type_name).file_descriptor + if import_file.name != expected_filename + warn "- #{file.name} imports #{expected_filename}, but that import was loaded as #{import_file.name}" + end + end + warn "Each proto file must use a consistent fully-qualified name." + warn "This will become an error in the next major version." +end + +module Testing + module Resources + RequestResource = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("testing.resources.RequestResource").msgclass + RequestAnotherResource = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("testing.resources.RequestAnotherResource").msgclass + RequestThirdResource = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("testing.resources.RequestThirdResource").msgclass + RequestFourthResource = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("testing.resources.RequestFourthResource").msgclass + Response = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("testing.resources.Response").msgclass + end +end diff --git a/shared/output/gapic/templates/testing/lib/testing/resources/resources_services_pb.rb b/shared/output/gapic/templates/testing/lib/testing/resources/resources_services_pb.rb new file mode 100644 index 000000000..54a847f15 --- /dev/null +++ b/shared/output/gapic/templates/testing/lib/testing/resources/resources_services_pb.rb @@ -0,0 +1,27 @@ +# Generated by the protocol buffer compiler. DO NOT EDIT! +# Source: testing/resources/resources.proto for package 'Testing.Resources' + +require 'grpc' +require 'testing/resources/resources_pb' + +module Testing + module Resources + module ServiceResources + class Service + + include ::GRPC::GenericService + + self.marshal_class_method = :encode + self.unmarshal_class_method = :decode + self.service_name = 'testing.resources.ServiceResources' + + rpc :Plain, ::Testing::Resources::RequestResource, ::Testing::Resources::Response + rpc :AnotherPlain, ::Testing::Resources::RequestAnotherResource, ::Testing::Resources::Response + rpc :ThirdPlain, ::Testing::Resources::RequestThirdResource, ::Testing::Resources::Response + rpc :FourthPlain, ::Testing::Resources::RequestFourthResource, ::Testing::Resources::Response + end + + Stub = Service.rpc_stub_class + end + end +end diff --git a/shared/output/gapic/templates/testing/lib/testing/resources/service_resources.rb b/shared/output/gapic/templates/testing/lib/testing/resources/service_resources.rb new file mode 100644 index 000000000..088903d9d --- /dev/null +++ b/shared/output/gapic/templates/testing/lib/testing/resources/service_resources.rb @@ -0,0 +1,51 @@ +# frozen_string_literal: true + +# The MIT License (MIT) +# +# Copyright +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in +# all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +# THE SOFTWARE. + +# Auto-generated by gapic-generator-ruby. DO NOT EDIT! + +require "gapic/common" +require "gapic/config" +require "gapic/config/method" + +require "testing/version" + +require "testing/resources/service_resources/credentials" +require "testing/resources/service_resources/paths" +require "testing/resources/service_resources/client" + +module Testing + module Resources + ## + # @example Load this service and instantiate a gRPC client + # + # require "testing/resources/service_resources" + # client = ::Testing::Resources::ServiceResources::Client.new + # + module ServiceResources + end + end +end + +helper_path = ::File.join __dir__, "service_resources", "helpers.rb" +require "testing/resources/service_resources/helpers" if ::File.file? helper_path diff --git a/shared/output/gapic/templates/testing/lib/testing/resources/service_resources/client.rb b/shared/output/gapic/templates/testing/lib/testing/resources/service_resources/client.rb new file mode 100644 index 000000000..1b40f4717 --- /dev/null +++ b/shared/output/gapic/templates/testing/lib/testing/resources/service_resources/client.rb @@ -0,0 +1,692 @@ +# frozen_string_literal: true + +# The MIT License (MIT) +# +# Copyright +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in +# all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +# THE SOFTWARE. + +# Auto-generated by gapic-generator-ruby. DO NOT EDIT! + +require "testing/resources/resources_pb" +require "google/cloud/location" + +module Testing + module Resources + module ServiceResources + ## + # Client for the ServiceResources service. + # + class Client + # @private + API_VERSION = "" + + # @private + DEFAULT_ENDPOINT_TEMPLATE = "resources.example.com" + + include Paths + + # @private + attr_reader :service_resources_stub + + ## + # Configure the ServiceResources Client class. + # + # See {::Testing::Resources::ServiceResources::Client::Configuration} + # for a description of the configuration fields. + # + # @example + # + # # Modify the configuration for all ServiceResources clients + # ::Testing::Resources::ServiceResources::Client.configure do |config| + # config.timeout = 10.0 + # end + # + # @yield [config] Configure the Client client. + # @yieldparam config [Client::Configuration] + # + # @return [Client::Configuration] + # + def self.configure + @configure ||= begin + default_config = Client::Configuration.new + + default_config + end + yield @configure if block_given? + @configure + end + + ## + # Configure the ServiceResources Client instance. + # + # The configuration is set to the derived mode, meaning that values can be changed, + # but structural changes (adding new fields, etc.) are not allowed. Structural changes + # should be made on {Client.configure}. + # + # See {::Testing::Resources::ServiceResources::Client::Configuration} + # for a description of the configuration fields. + # + # @yield [config] Configure the Client client. + # @yieldparam config [Client::Configuration] + # + # @return [Client::Configuration] + # + def configure + yield @config if block_given? + @config + end + + ## + # The effective universe domain + # + # @return [String] + # + def universe_domain + @service_resources_stub.universe_domain + end + + ## + # Create a new ServiceResources client object. + # + # @example + # + # # Create a client using the default configuration + # client = ::Testing::Resources::ServiceResources::Client.new + # + # # Create a client using a custom configuration + # client = ::Testing::Resources::ServiceResources::Client.new do |config| + # config.timeout = 10.0 + # end + # + # @yield [config] Configure the ServiceResources client. + # @yieldparam config [Client::Configuration] + # + def initialize + # These require statements are intentionally placed here to initialize + # the gRPC module only when it's required. + # See https://github.com/googleapis/toolkit/issues/446 + require "gapic/grpc" + require "testing/resources/resources_services_pb" + + # Create the configuration object + @config = Configuration.new Client.configure + + # Yield the configuration if needed + yield @config if block_given? + + # Create credentials + credentials = @config.credentials + # Use self-signed JWT if the endpoint is unchanged from default, + # but only if the default endpoint does not have a region prefix. + enable_self_signed_jwt = @config.endpoint.nil? || + (@config.endpoint == Configuration::DEFAULT_ENDPOINT && + !@config.endpoint.split(".").first.include?("-")) + credentials ||= Credentials.default scope: @config.scope, + enable_self_signed_jwt: enable_self_signed_jwt + if credentials.is_a?(::String) || credentials.is_a?(::Hash) + credentials = Credentials.new credentials, scope: @config.scope + end + @quota_project_id = @config.quota_project + @quota_project_id ||= credentials.quota_project_id if credentials.respond_to? :quota_project_id + + @service_resources_stub = ::Gapic::ServiceStub.new( + ::Testing::Resources::ServiceResources::Stub, + credentials: credentials, + endpoint: @config.endpoint, + endpoint_template: DEFAULT_ENDPOINT_TEMPLATE, + universe_domain: @config.universe_domain, + channel_args: @config.channel_args, + interceptors: @config.interceptors, + channel_pool_config: @config.channel_pool, + logger: @config.logger + ) + + @service_resources_stub.stub_logger&.info do |entry| + entry.set_system_name + entry.set_service + entry.message = "Created client for #{entry.service}" + entry.set_credentials_fields credentials + entry.set "customEndpoint", @config.endpoint if @config.endpoint + entry.set "defaultTimeout", @config.timeout if @config.timeout + entry.set "quotaProject", @quota_project_id if @quota_project_id + end + + @location_client = Google::Cloud::Location::Locations::Client.new do |config| + config.credentials = credentials + config.quota_project = @quota_project_id + config.endpoint = @service_resources_stub.endpoint + config.universe_domain = @service_resources_stub.universe_domain + config.logger = @service_resources_stub.logger if config.respond_to? :logger= + end + end + + ## + # Get the associated client for mix-in of the Locations. + # + # @return [Google::Cloud::Location::Locations::Client] + # + attr_reader :location_client + + ## + # The logger used for request/response debug logging. + # + # @return [Logger] + # + def logger + @service_resources_stub.logger + end + + # Service calls + + ## + # @overload plain(request, options = nil) + # Pass arguments to `plain` via a request object, either of type + # {::Testing::Resources::RequestResource} or an equivalent Hash. + # + # @param request [::Testing::Resources::RequestResource, ::Hash] + # A request object representing the call parameters. Required. To specify no + # parameters, or to keep all the default parameter values, pass an empty Hash. + # @param options [::Gapic::CallOptions, ::Hash] + # Overrides the default settings for this call, e.g, timeout, retries, etc. Optional. + # + # @overload plain(resource_name: nil) + # Pass arguments to `plain` via keyword arguments. Note that at + # least one keyword argument is required. To specify no parameters, or to keep all + # the default parameter values, pass an empty Hash as a request object (see above). + # + # @param resource_name [::String] + # + # @yield [response, operation] Access the result along with the RPC operation + # @yieldparam response [::Testing::Resources::Response] + # @yieldparam operation [::GRPC::ActiveCall::Operation] + # + # @return [::Testing::Resources::Response] + # + # @raise [::GRPC::BadStatus] if the RPC is aborted. + # + # @example Basic example + # require "testing/resources" + # + # # Create a client object. The client can be reused for multiple calls. + # client = Testing::Resources::ServiceResources::Client.new + # + # # Create a request. To set request fields, pass in keyword arguments. + # request = Testing::Resources::RequestResource.new + # + # # Call the plain method. + # result = client.plain request + # + # # The returned object is of type Testing::Resources::Response. + # p result + # + def plain request, options = nil + raise ::ArgumentError, "request must be provided" if request.nil? + + request = ::Gapic::Protobuf.coerce request, to: ::Testing::Resources::RequestResource + + # Converts hash and nil to an options object + options = ::Gapic::CallOptions.new(**options.to_h) if options.respond_to? :to_h + + # Customize the options with defaults + metadata = @config.rpcs.plain.metadata.to_h + + # Set x-goog-api-client, x-goog-user-project and x-goog-api-version headers + metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \ + lib_name: @config.lib_name, lib_version: @config.lib_version, + gapic_version: ::Testing::VERSION + metadata[:"x-goog-api-version"] = API_VERSION unless API_VERSION.empty? + metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id + + options.apply_defaults timeout: @config.rpcs.plain.timeout, + metadata: metadata, + retry_policy: @config.rpcs.plain.retry_policy + + options.apply_defaults timeout: @config.timeout, + metadata: @config.metadata, + retry_policy: @config.retry_policy + + @service_resources_stub.call_rpc :plain, request, options: options do |response, operation| + yield response, operation if block_given? + end + end + + ## + # @overload another_plain(request, options = nil) + # Pass arguments to `another_plain` via a request object, either of type + # {::Testing::Resources::RequestAnotherResource} or an equivalent Hash. + # + # @param request [::Testing::Resources::RequestAnotherResource, ::Hash] + # A request object representing the call parameters. Required. To specify no + # parameters, or to keep all the default parameter values, pass an empty Hash. + # @param options [::Gapic::CallOptions, ::Hash] + # Overrides the default settings for this call, e.g, timeout, retries, etc. Optional. + # + # @overload another_plain(resource_name: nil) + # Pass arguments to `another_plain` via keyword arguments. Note that at + # least one keyword argument is required. To specify no parameters, or to keep all + # the default parameter values, pass an empty Hash as a request object (see above). + # + # @param resource_name [::String] + # + # @yield [response, operation] Access the result along with the RPC operation + # @yieldparam response [::Testing::Resources::Response] + # @yieldparam operation [::GRPC::ActiveCall::Operation] + # + # @return [::Testing::Resources::Response] + # + # @raise [::GRPC::BadStatus] if the RPC is aborted. + # + # @example Basic example + # require "testing/resources" + # + # # Create a client object. The client can be reused for multiple calls. + # client = Testing::Resources::ServiceResources::Client.new + # + # # Create a request. To set request fields, pass in keyword arguments. + # request = Testing::Resources::RequestAnotherResource.new + # + # # Call the another_plain method. + # result = client.another_plain request + # + # # The returned object is of type Testing::Resources::Response. + # p result + # + def another_plain request, options = nil + raise ::ArgumentError, "request must be provided" if request.nil? + + request = ::Gapic::Protobuf.coerce request, to: ::Testing::Resources::RequestAnotherResource + + # Converts hash and nil to an options object + options = ::Gapic::CallOptions.new(**options.to_h) if options.respond_to? :to_h + + # Customize the options with defaults + metadata = @config.rpcs.another_plain.metadata.to_h + + # Set x-goog-api-client, x-goog-user-project and x-goog-api-version headers + metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \ + lib_name: @config.lib_name, lib_version: @config.lib_version, + gapic_version: ::Testing::VERSION + metadata[:"x-goog-api-version"] = API_VERSION unless API_VERSION.empty? + metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id + + options.apply_defaults timeout: @config.rpcs.another_plain.timeout, + metadata: metadata, + retry_policy: @config.rpcs.another_plain.retry_policy + + options.apply_defaults timeout: @config.timeout, + metadata: @config.metadata, + retry_policy: @config.retry_policy + + @service_resources_stub.call_rpc :another_plain, request, options: options do |response, operation| + yield response, operation if block_given? + end + end + + ## + # @overload third_plain(request, options = nil) + # Pass arguments to `third_plain` via a request object, either of type + # {::Testing::Resources::RequestThirdResource} or an equivalent Hash. + # + # @param request [::Testing::Resources::RequestThirdResource, ::Hash] + # A request object representing the call parameters. Required. To specify no + # parameters, or to keep all the default parameter values, pass an empty Hash. + # @param options [::Gapic::CallOptions, ::Hash] + # Overrides the default settings for this call, e.g, timeout, retries, etc. Optional. + # + # @overload third_plain(resource_name: nil) + # Pass arguments to `third_plain` via keyword arguments. Note that at + # least one keyword argument is required. To specify no parameters, or to keep all + # the default parameter values, pass an empty Hash as a request object (see above). + # + # @param resource_name [::String] + # + # @yield [response, operation] Access the result along with the RPC operation + # @yieldparam response [::Testing::Resources::Response] + # @yieldparam operation [::GRPC::ActiveCall::Operation] + # + # @return [::Testing::Resources::Response] + # + # @raise [::GRPC::BadStatus] if the RPC is aborted. + # + # @example Basic example + # require "testing/resources" + # + # # Create a client object. The client can be reused for multiple calls. + # client = Testing::Resources::ServiceResources::Client.new + # + # # Create a request. To set request fields, pass in keyword arguments. + # request = Testing::Resources::RequestThirdResource.new + # + # # Call the third_plain method. + # result = client.third_plain request + # + # # The returned object is of type Testing::Resources::Response. + # p result + # + def third_plain request, options = nil + raise ::ArgumentError, "request must be provided" if request.nil? + + request = ::Gapic::Protobuf.coerce request, to: ::Testing::Resources::RequestThirdResource + + # Converts hash and nil to an options object + options = ::Gapic::CallOptions.new(**options.to_h) if options.respond_to? :to_h + + # Customize the options with defaults + metadata = @config.rpcs.third_plain.metadata.to_h + + # Set x-goog-api-client, x-goog-user-project and x-goog-api-version headers + metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \ + lib_name: @config.lib_name, lib_version: @config.lib_version, + gapic_version: ::Testing::VERSION + metadata[:"x-goog-api-version"] = API_VERSION unless API_VERSION.empty? + metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id + + options.apply_defaults timeout: @config.rpcs.third_plain.timeout, + metadata: metadata, + retry_policy: @config.rpcs.third_plain.retry_policy + + options.apply_defaults timeout: @config.timeout, + metadata: @config.metadata, + retry_policy: @config.retry_policy + + @service_resources_stub.call_rpc :third_plain, request, options: options do |response, operation| + yield response, operation if block_given? + end + end + + ## + # @overload fourth_plain(request, options = nil) + # Pass arguments to `fourth_plain` via a request object, either of type + # {::Testing::Resources::RequestFourthResource} or an equivalent Hash. + # + # @param request [::Testing::Resources::RequestFourthResource, ::Hash] + # A request object representing the call parameters. Required. To specify no + # parameters, or to keep all the default parameter values, pass an empty Hash. + # @param options [::Gapic::CallOptions, ::Hash] + # Overrides the default settings for this call, e.g, timeout, retries, etc. Optional. + # + # @overload fourth_plain(resource_name: nil) + # Pass arguments to `fourth_plain` via keyword arguments. Note that at + # least one keyword argument is required. To specify no parameters, or to keep all + # the default parameter values, pass an empty Hash as a request object (see above). + # + # @param resource_name [::String] + # + # @yield [response, operation] Access the result along with the RPC operation + # @yieldparam response [::Testing::Resources::Response] + # @yieldparam operation [::GRPC::ActiveCall::Operation] + # + # @return [::Testing::Resources::Response] + # + # @raise [::GRPC::BadStatus] if the RPC is aborted. + # + # @example Basic example + # require "testing/resources" + # + # # Create a client object. The client can be reused for multiple calls. + # client = Testing::Resources::ServiceResources::Client.new + # + # # Create a request. To set request fields, pass in keyword arguments. + # request = Testing::Resources::RequestFourthResource.new + # + # # Call the fourth_plain method. + # result = client.fourth_plain request + # + # # The returned object is of type Testing::Resources::Response. + # p result + # + def fourth_plain request, options = nil + raise ::ArgumentError, "request must be provided" if request.nil? + + request = ::Gapic::Protobuf.coerce request, to: ::Testing::Resources::RequestFourthResource + + # Converts hash and nil to an options object + options = ::Gapic::CallOptions.new(**options.to_h) if options.respond_to? :to_h + + # Customize the options with defaults + metadata = @config.rpcs.fourth_plain.metadata.to_h + + # Set x-goog-api-client, x-goog-user-project and x-goog-api-version headers + metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \ + lib_name: @config.lib_name, lib_version: @config.lib_version, + gapic_version: ::Testing::VERSION + metadata[:"x-goog-api-version"] = API_VERSION unless API_VERSION.empty? + metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id + + options.apply_defaults timeout: @config.rpcs.fourth_plain.timeout, + metadata: metadata, + retry_policy: @config.rpcs.fourth_plain.retry_policy + + options.apply_defaults timeout: @config.timeout, + metadata: @config.metadata, + retry_policy: @config.retry_policy + + @service_resources_stub.call_rpc :fourth_plain, request, options: options do |response, operation| + yield response, operation if block_given? + end + end + + ## + # Configuration class for the ServiceResources API. + # + # This class represents the configuration for ServiceResources, + # providing control over timeouts, retry behavior, logging, transport + # parameters, and other low-level controls. Certain parameters can also be + # applied individually to specific RPCs. See + # {::Testing::Resources::ServiceResources::Client::Configuration::Rpcs} + # for a list of RPCs that can be configured independently. + # + # Configuration can be applied globally to all clients, or to a single client + # on construction. + # + # @example + # + # # Modify the global config, setting the timeout for + # # plain to 20 seconds, + # # and all remaining timeouts to 10 seconds. + # ::Testing::Resources::ServiceResources::Client.configure do |config| + # config.timeout = 10.0 + # config.rpcs.plain.timeout = 20.0 + # end + # + # # Apply the above configuration only to a new client. + # client = ::Testing::Resources::ServiceResources::Client.new do |config| + # config.timeout = 10.0 + # config.rpcs.plain.timeout = 20.0 + # end + # + # @!attribute [rw] endpoint + # A custom service endpoint, as a hostname or hostname:port. The default is + # nil, indicating to use the default endpoint in the current universe domain. + # @return [::String,nil] + # @!attribute [rw] credentials + # Credentials to send with calls. You may provide any of the following types: + # * (`String`) The path to a service account key file in JSON format + # * (`Hash`) A service account key as a Hash + # * (`Google::Auth::Credentials`) A googleauth credentials object + # (see the [googleauth docs](https://rubydoc.info/gems/googleauth/Google/Auth/Credentials)) + # * (`Signet::OAuth2::Client`) A signet oauth2 client object + # (see the [signet docs](https://rubydoc.info/gems/signet/Signet/OAuth2/Client)) + # * (`GRPC::Core::Channel`) a gRPC channel with included credentials + # * (`GRPC::Core::ChannelCredentials`) a gRPC credentails object + # * (`nil`) indicating no credentials + # + # Warning: If you accept a credential configuration (JSON file or Hash) from an + # external source for authentication to Google Cloud, you must validate it before + # providing it to a Google API client library. Providing an unvalidated credential + # configuration to Google APIs can compromise the security of your systems and data. + # For more information, refer to [Validate credential configurations from external + # sources](https://cloud.google.com/docs/authentication/external/externally-sourced-credentials). + # @return [::Object] + # @!attribute [rw] scope + # The OAuth scopes + # @return [::Array<::String>] + # @!attribute [rw] lib_name + # The library name as recorded in instrumentation and logging + # @return [::String] + # @!attribute [rw] lib_version + # The library version as recorded in instrumentation and logging + # @return [::String] + # @!attribute [rw] channel_args + # Extra parameters passed to the gRPC channel. Note: this is ignored if a + # `GRPC::Core::Channel` object is provided as the credential. + # @return [::Hash] + # @!attribute [rw] interceptors + # An array of interceptors that are run before calls are executed. + # @return [::Array<::GRPC::ClientInterceptor>] + # @!attribute [rw] timeout + # The call timeout in seconds. + # @return [::Numeric] + # @!attribute [rw] metadata + # Additional gRPC headers to be sent with the call. + # @return [::Hash{::Symbol=>::String}] + # @!attribute [rw] retry_policy + # The retry policy. The value is a hash with the following keys: + # * `:initial_delay` (*type:* `Numeric`) - The initial delay in seconds. + # * `:max_delay` (*type:* `Numeric`) - The max delay in seconds. + # * `:multiplier` (*type:* `Numeric`) - The incremental backoff multiplier. + # * `:retry_codes` (*type:* `Array`) - The error codes that should + # trigger a retry. + # @return [::Hash] + # @!attribute [rw] quota_project + # A separate project against which to charge quota. + # @return [::String] + # @!attribute [rw] universe_domain + # The universe domain within which to make requests. This determines the + # default endpoint URL. The default value of nil uses the environment + # universe (usually the default "googleapis.com" universe). + # @return [::String,nil] + # @!attribute [rw] logger + # A custom logger to use for request/response debug logging, or the value + # `:default` (the default) to construct a default logger, or `nil` to + # explicitly disable logging. + # @return [::Logger,:default,nil] + # + class Configuration + extend ::Gapic::Config + + # @private + # The endpoint specific to the default "googleapis.com" universe. Deprecated. + DEFAULT_ENDPOINT = "resources.example.com" + + config_attr :endpoint, nil, ::String, nil + config_attr :credentials, nil do |value| + allowed = [::String, ::Hash, ::Proc, ::Symbol, ::Google::Auth::Credentials, ::Google::Auth::BaseClient, + ::Signet::OAuth2::Client, nil] + allowed += [::GRPC::Core::Channel, ::GRPC::Core::ChannelCredentials] if defined? ::GRPC::Core::Channel + allowed.any? { |klass| klass === value } + end + config_attr :scope, nil, ::String, ::Array, nil + config_attr :lib_name, nil, ::String, nil + config_attr :lib_version, nil, ::String, nil + config_attr(:channel_args, { "grpc.service_config_disable_resolution" => 1 }, ::Hash, nil) + config_attr :interceptors, nil, ::Array, nil + config_attr :timeout, nil, ::Numeric, nil + config_attr :metadata, nil, ::Hash, nil + config_attr :retry_policy, nil, ::Hash, ::Proc, nil + config_attr :quota_project, nil, ::String, nil + config_attr :universe_domain, nil, ::String, nil + config_attr :logger, :default, ::Logger, nil, :default + + # @private + def initialize parent_config = nil + @parent_config = parent_config unless parent_config.nil? + + yield self if block_given? + end + + ## + # Configurations for individual RPCs + # @return [Rpcs] + # + def rpcs + @rpcs ||= begin + parent_rpcs = nil + parent_rpcs = @parent_config.rpcs if defined?(@parent_config) && @parent_config.respond_to?(:rpcs) + Rpcs.new parent_rpcs + end + end + + ## + # Configuration for the channel pool + # @return [::Gapic::ServiceStub::ChannelPool::Configuration] + # + def channel_pool + @channel_pool ||= ::Gapic::ServiceStub::ChannelPool::Configuration.new + end + + ## + # Configuration RPC class for the ServiceResources API. + # + # Includes fields providing the configuration for each RPC in this service. + # Each configuration object is of type `Gapic::Config::Method` and includes + # the following configuration fields: + # + # * `timeout` (*type:* `Numeric`) - The call timeout in seconds + # * `metadata` (*type:* `Hash{Symbol=>String}`) - Additional gRPC headers + # * `retry_policy (*type:* `Hash`) - The retry policy. The policy fields + # include the following keys: + # * `:initial_delay` (*type:* `Numeric`) - The initial delay in seconds. + # * `:max_delay` (*type:* `Numeric`) - The max delay in seconds. + # * `:multiplier` (*type:* `Numeric`) - The incremental backoff multiplier. + # * `:retry_codes` (*type:* `Array`) - The error codes that should + # trigger a retry. + # + class Rpcs + ## + # RPC-specific configuration for `plain` + # @return [::Gapic::Config::Method] + # + attr_reader :plain + ## + # RPC-specific configuration for `another_plain` + # @return [::Gapic::Config::Method] + # + attr_reader :another_plain + ## + # RPC-specific configuration for `third_plain` + # @return [::Gapic::Config::Method] + # + attr_reader :third_plain + ## + # RPC-specific configuration for `fourth_plain` + # @return [::Gapic::Config::Method] + # + attr_reader :fourth_plain + + # @private + def initialize parent_rpcs = nil + plain_config = parent_rpcs.plain if parent_rpcs.respond_to? :plain + @plain = ::Gapic::Config::Method.new plain_config + another_plain_config = parent_rpcs.another_plain if parent_rpcs.respond_to? :another_plain + @another_plain = ::Gapic::Config::Method.new another_plain_config + third_plain_config = parent_rpcs.third_plain if parent_rpcs.respond_to? :third_plain + @third_plain = ::Gapic::Config::Method.new third_plain_config + fourth_plain_config = parent_rpcs.fourth_plain if parent_rpcs.respond_to? :fourth_plain + @fourth_plain = ::Gapic::Config::Method.new fourth_plain_config + + yield self if block_given? + end + end + end + end + end + end +end diff --git a/shared/output/gapic/templates/testing/lib/testing/resources/service_resources/credentials.rb b/shared/output/gapic/templates/testing/lib/testing/resources/service_resources/credentials.rb new file mode 100644 index 000000000..c9aa1ab1b --- /dev/null +++ b/shared/output/gapic/templates/testing/lib/testing/resources/service_resources/credentials.rb @@ -0,0 +1,37 @@ +# frozen_string_literal: true + +# The MIT License (MIT) +# +# Copyright +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in +# all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +# THE SOFTWARE. + +# Auto-generated by gapic-generator-ruby. DO NOT EDIT! + +require "googleauth" + +module Testing + module Resources + module ServiceResources + # Credentials for the ServiceResources API. + class Credentials < ::Google::Auth::Credentials + end + end + end +end diff --git a/shared/output/gapic/templates/testing/lib/testing/resources/service_resources/paths.rb b/shared/output/gapic/templates/testing/lib/testing/resources/service_resources/paths.rb new file mode 100644 index 000000000..35cd3333c --- /dev/null +++ b/shared/output/gapic/templates/testing/lib/testing/resources/service_resources/paths.rb @@ -0,0 +1,157 @@ +# frozen_string_literal: true + +# The MIT License (MIT) +# +# Copyright +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in +# all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +# THE SOFTWARE. + +# Auto-generated by gapic-generator-ruby. DO NOT EDIT! + + +module Testing + module Resources + module ServiceResources + # Path helper methods for the ServiceResources API. + module Paths + ## + # Create a fully-qualified RequestAnotherResource resource string. + # + # @overload request_another_resource_path() + # The resource will be in the following format: + # + # `projects/responses` + # + # @overload request_another_resource_path(project:) + # The resource will be in the following format: + # + # `projects/{project}/responses` + # + # @param project [String] + # + # @return [::String] + def request_another_resource_path **args + resources = { + "" => (proc do + "projects/responses" + end), + "project" => (proc do |project:| + "projects/#{project}/responses" + end) + } + + resource = resources[args.keys.sort.join(":")] + raise ::ArgumentError, "no resource found for values #{args.keys}" if resource.nil? + resource.call(**args) + end + + ## + # Create a fully-qualified RequestFourthResource resource string. + # + # The resource will be in the following format: + # + # `projects/{project}/resources/{resource}/versions/{version}` + # + # @param project [String] + # @param resource [String] + # @param version [String] + # + # @return [::String] + def request_fourth_resource_path project:, resource:, version: + raise ::ArgumentError, "project cannot contain /" if project.to_s.include? "/" + raise ::ArgumentError, "resource cannot contain /" if resource.to_s.include? "/" + + "projects/#{project}/resources/#{resource}/versions/#{version}" + end + + ## + # Create a fully-qualified RequestResource resource string. + # + # @overload request_resource_path(project:, resource:, version:) + # The resource will be in the following format: + # + # `projects/{project}/resources/{resource}/versions/{version}` + # + # @param project [String] + # @param resource [String] + # @param version [String] + # + # @overload request_resource_path(project:, resource:, subject:, version:) + # The resource will be in the following format: + # + # `projects/{project}/resources/{resource}/subjects/{subject}/versions/{version}` + # + # @param project [String] + # @param resource [String] + # @param subject [String] + # @param version [String] + # + # @overload request_resource_path(project:, resource:) + # The resource will be in the following format: + # + # `projects/{project}/compatibility/resources/{resource}/versions` + # + # @param project [String] + # @param resource [String] + # + # @return [::String] + def request_resource_path **args + resources = { + "project:resource:version" => (proc do |project:, resource:, version:| + raise ::ArgumentError, "project cannot contain /" if project.to_s.include? "/" + raise ::ArgumentError, "resource cannot contain /" if resource.to_s.include? "/" + + "projects/#{project}/resources/#{resource}/versions/#{version}" + end), + "project:resource:subject:version" => (proc do |project:, resource:, subject:, version:| + raise ::ArgumentError, "project cannot contain /" if project.to_s.include? "/" + raise ::ArgumentError, "resource cannot contain /" if resource.to_s.include? "/" + raise ::ArgumentError, "subject cannot contain /" if subject.to_s.include? "/" + + "projects/#{project}/resources/#{resource}/subjects/#{subject}/versions/#{version}" + end), + "project:resource" => (proc do |project:, resource:| + raise ::ArgumentError, "project cannot contain /" if project.to_s.include? "/" + + "projects/#{project}/compatibility/resources/#{resource}/versions" + end) + } + + resource = resources[args.keys.sort.join(":")] + raise ::ArgumentError, "no resource found for values #{args.keys}" if resource.nil? + resource.call(**args) + end + + ## + # Create a fully-qualified RequestThirdResource resource string. + # + # The resource will be in the following format: + # + # `projects/responses` + # + # @return [::String] + def request_third_resource_path + "projects/responses" + end + + extend self + end + end + end +end diff --git a/shared/output/gapic/templates/testing/proto_docs/google/api/resource.rb b/shared/output/gapic/templates/testing/proto_docs/google/api/resource.rb new file mode 100644 index 000000000..dedc34c9c --- /dev/null +++ b/shared/output/gapic/templates/testing/proto_docs/google/api/resource.rb @@ -0,0 +1,235 @@ +# frozen_string_literal: true + +# The MIT License (MIT) +# +# Copyright +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in +# all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +# THE SOFTWARE. + +# Auto-generated by gapic-generator-ruby. DO NOT EDIT! + + +module Google + module Api + # A simple descriptor of a resource type. + # + # ResourceDescriptor annotates a resource message (either by means of a + # protobuf annotation or use in the service config), and associates the + # resource's schema, the resource type, and the pattern of the resource name. + # + # Example: + # + # message Topic { + # // Indicates this message defines a resource schema. + # // Declares the resource type in the format of {service}/{kind}. + # // For Kubernetes resources, the format is {api group}/{kind}. + # option (google.api.resource) = { + # type: "pubsub.googleapis.com/Topic" + # pattern: "projects/{project}/topics/{topic}" + # }; + # } + # + # The ResourceDescriptor Yaml config will look like: + # + # resources: + # - type: "pubsub.googleapis.com/Topic" + # pattern: "projects/{project}/topics/{topic}" + # + # Sometimes, resources have multiple patterns, typically because they can + # live under multiple parents. + # + # Example: + # + # message LogEntry { + # option (google.api.resource) = { + # type: "logging.googleapis.com/LogEntry" + # pattern: "projects/{project}/logs/{log}" + # pattern: "folders/{folder}/logs/{log}" + # pattern: "organizations/{organization}/logs/{log}" + # pattern: "billingAccounts/{billing_account}/logs/{log}" + # }; + # } + # + # The ResourceDescriptor Yaml config will look like: + # + # resources: + # - type: 'logging.googleapis.com/LogEntry' + # pattern: "projects/{project}/logs/{log}" + # pattern: "folders/{folder}/logs/{log}" + # pattern: "organizations/{organization}/logs/{log}" + # pattern: "billingAccounts/{billing_account}/logs/{log}" + # @!attribute [rw] type + # @return [::String] + # The resource type. It must be in the format of + # \\{service_name}/\\{resource_type_kind}. The `resource_type_kind` must be + # singular and must not include version numbers. + # + # Example: `storage.googleapis.com/Bucket` + # + # The value of the resource_type_kind must follow the regular expression + # /[A-Za-z][a-zA-Z0-9]+/. It should start with an upper case character and + # should use PascalCase (UpperCamelCase). The maximum number of + # characters allowed for the `resource_type_kind` is 100. + # @!attribute [rw] pattern + # @return [::Array<::String>] + # Optional. The relative resource name pattern associated with this resource + # type. The DNS prefix of the full resource name shouldn't be specified here. + # + # The path pattern must follow the syntax, which aligns with HTTP binding + # syntax: + # + # Template = Segment { "/" Segment } ; + # Segment = LITERAL | Variable ; + # Variable = "{" LITERAL "}" ; + # + # Examples: + # + # - "projects/\\{project}/topics/\\{topic}" + # - "projects/\\{project}/knowledgeBases/\\{knowledge_base}" + # + # The components in braces correspond to the IDs for each resource in the + # hierarchy. It is expected that, if multiple patterns are provided, + # the same component name (e.g. "project") refers to IDs of the same + # type of resource. + # @!attribute [rw] name_field + # @return [::String] + # Optional. The field on the resource that designates the resource name + # field. If omitted, this is assumed to be "name". + # @!attribute [rw] history + # @return [::Google::Api::ResourceDescriptor::History] + # Optional. The historical or future-looking state of the resource pattern. + # + # Example: + # + # // The InspectTemplate message originally only supported resource + # // names with organization, and project was added later. + # message InspectTemplate { + # option (google.api.resource) = { + # type: "dlp.googleapis.com/InspectTemplate" + # pattern: + # "organizations/{organization}/inspectTemplates/{inspect_template}" + # pattern: "projects/{project}/inspectTemplates/{inspect_template}" + # history: ORIGINALLY_SINGLE_PATTERN + # }; + # } + # @!attribute [rw] plural + # @return [::String] + # The plural name used in the resource name and permission names, such as + # 'projects' for the resource name of 'projects/\\{project}' and the permission + # name of 'cloudresourcemanager.googleapis.com/projects.get'. One exception + # to this is for Nested Collections that have stuttering names, as defined + # in [AIP-122](https://google.aip.dev/122#nested-collections), where the + # collection ID in the resource name pattern does not necessarily directly + # match the `plural` value. + # + # It is the same concept of the `plural` field in k8s CRD spec + # https://kubernetes.io/docs/tasks/access-kubernetes-api/custom-resources/custom-resource-definitions/ + # + # Note: The plural form is required even for singleton resources. See + # https://aip.dev/156 + # @!attribute [rw] singular + # @return [::String] + # The same concept of the `singular` field in k8s CRD spec + # https://kubernetes.io/docs/tasks/access-kubernetes-api/custom-resources/custom-resource-definitions/ + # Such as "project" for the `resourcemanager.googleapis.com/Project` type. + # @!attribute [rw] style + # @return [::Array<::Google::Api::ResourceDescriptor::Style>] + # Style flag(s) for this resource. + # These indicate that a resource is expected to conform to a given + # style. See the specific style flags for additional information. + class ResourceDescriptor + include ::Google::Protobuf::MessageExts + extend ::Google::Protobuf::MessageExts::ClassMethods + + # A description of the historical or future-looking state of the + # resource pattern. + module History + # The "unset" value. + HISTORY_UNSPECIFIED = 0 + + # The resource originally had one pattern and launched as such, and + # additional patterns were added later. + ORIGINALLY_SINGLE_PATTERN = 1 + + # The resource has one pattern, but the API owner expects to add more + # later. (This is the inverse of ORIGINALLY_SINGLE_PATTERN, and prevents + # that from being necessary once there are multiple patterns.) + FUTURE_MULTI_PATTERN = 2 + end + + # A flag representing a specific style that a resource claims to conform to. + module Style + # The unspecified value. Do not use. + STYLE_UNSPECIFIED = 0 + + # This resource is intended to be "declarative-friendly". + # + # Declarative-friendly resources must be more strictly consistent, and + # setting this to true communicates to tools that this resource should + # adhere to declarative-friendly expectations. + # + # Note: This is used by the API linter (linter.aip.dev) to enable + # additional checks. + DECLARATIVE_FRIENDLY = 1 + end + end + + # Defines a proto annotation that describes a string field that refers to + # an API resource. + # @!attribute [rw] type + # @return [::String] + # The resource type that the annotated field references. + # + # Example: + # + # message Subscription { + # string topic = 2 [(google.api.resource_reference) = { + # type: "pubsub.googleapis.com/Topic" + # }]; + # } + # + # Occasionally, a field may reference an arbitrary resource. In this case, + # APIs use the special value * in their resource reference. + # + # Example: + # + # message GetIamPolicyRequest { + # string resource = 2 [(google.api.resource_reference) = { + # type: "*" + # }]; + # } + # @!attribute [rw] child_type + # @return [::String] + # The resource type of a child collection that the annotated field + # references. This is useful for annotating the `parent` field that + # doesn't have a fixed resource type. + # + # Example: + # + # message ListLogEntriesRequest { + # string parent = 1 [(google.api.resource_reference) = { + # child_type: "logging.googleapis.com/LogEntry" + # }; + # } + class ResourceReference + include ::Google::Protobuf::MessageExts + extend ::Google::Protobuf::MessageExts::ClassMethods + end + end +end diff --git a/shared/output/gapic/templates/testing/proto_docs/testing/resources/resources.rb b/shared/output/gapic/templates/testing/proto_docs/testing/resources/resources.rb new file mode 100644 index 000000000..f1e307e8a --- /dev/null +++ b/shared/output/gapic/templates/testing/proto_docs/testing/resources/resources.rb @@ -0,0 +1,63 @@ +# frozen_string_literal: true + +# The MIT License (MIT) +# +# Copyright +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in +# all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +# THE SOFTWARE. + +# Auto-generated by gapic-generator-ruby. DO NOT EDIT! + + +module Testing + module Resources + # @!attribute [rw] resource_name + # @return [::String] + class RequestResource + include ::Google::Protobuf::MessageExts + extend ::Google::Protobuf::MessageExts::ClassMethods + end + + # @!attribute [rw] resource_name + # @return [::String] + class RequestAnotherResource + include ::Google::Protobuf::MessageExts + extend ::Google::Protobuf::MessageExts::ClassMethods + end + + # @!attribute [rw] resource_name + # @return [::String] + class RequestThirdResource + include ::Google::Protobuf::MessageExts + extend ::Google::Protobuf::MessageExts::ClassMethods + end + + # @!attribute [rw] resource_name + # @return [::String] + class RequestFourthResource + include ::Google::Protobuf::MessageExts + extend ::Google::Protobuf::MessageExts::ClassMethods + end + + class Response + include ::Google::Protobuf::MessageExts + extend ::Google::Protobuf::MessageExts::ClassMethods + end + end +end diff --git a/shared/output/gapic/templates/testing/snippets/service_resources/another_plain.rb b/shared/output/gapic/templates/testing/snippets/service_resources/another_plain.rb new file mode 100644 index 000000000..1565216af --- /dev/null +++ b/shared/output/gapic/templates/testing/snippets/service_resources/another_plain.rb @@ -0,0 +1,55 @@ +# frozen_string_literal: true + +# The MIT License (MIT) +# +# Copyright +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in +# all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +# THE SOFTWARE. + +# Auto-generated by gapic-generator-ruby. DO NOT EDIT! + +# [START testing_v0_generated_ServiceResources_AnotherPlain_sync] +require "testing/resources" + +## +# Snippet for the another_plain call in the ServiceResources service +# +# This snippet has been automatically generated and should be regarded as a code +# template only. It will require modifications to work: +# - It may require correct/in-range values for request initialization. +# - It may require specifying regional endpoints when creating the service +# client as shown in https://cloud.google.com/ruby/docs/reference. +# +# This is an auto-generated example demonstrating basic usage of +# Testing::Resources::ServiceResources::Client#another_plain. +# +def another_plain + # Create a client object. The client can be reused for multiple calls. + client = Testing::Resources::ServiceResources::Client.new + + # Create a request. To set request fields, pass in keyword arguments. + request = Testing::Resources::RequestAnotherResource.new + + # Call the another_plain method. + result = client.another_plain request + + # The returned object is of type Testing::Resources::Response. + p result +end +# [END testing_v0_generated_ServiceResources_AnotherPlain_sync] diff --git a/shared/output/gapic/templates/testing/snippets/service_resources/fourth_plain.rb b/shared/output/gapic/templates/testing/snippets/service_resources/fourth_plain.rb new file mode 100644 index 000000000..b80624767 --- /dev/null +++ b/shared/output/gapic/templates/testing/snippets/service_resources/fourth_plain.rb @@ -0,0 +1,55 @@ +# frozen_string_literal: true + +# The MIT License (MIT) +# +# Copyright +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in +# all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +# THE SOFTWARE. + +# Auto-generated by gapic-generator-ruby. DO NOT EDIT! + +# [START testing_v0_generated_ServiceResources_FourthPlain_sync] +require "testing/resources" + +## +# Snippet for the fourth_plain call in the ServiceResources service +# +# This snippet has been automatically generated and should be regarded as a code +# template only. It will require modifications to work: +# - It may require correct/in-range values for request initialization. +# - It may require specifying regional endpoints when creating the service +# client as shown in https://cloud.google.com/ruby/docs/reference. +# +# This is an auto-generated example demonstrating basic usage of +# Testing::Resources::ServiceResources::Client#fourth_plain. +# +def fourth_plain + # Create a client object. The client can be reused for multiple calls. + client = Testing::Resources::ServiceResources::Client.new + + # Create a request. To set request fields, pass in keyword arguments. + request = Testing::Resources::RequestFourthResource.new + + # Call the fourth_plain method. + result = client.fourth_plain request + + # The returned object is of type Testing::Resources::Response. + p result +end +# [END testing_v0_generated_ServiceResources_FourthPlain_sync] diff --git a/shared/output/gapic/templates/testing/snippets/service_resources/plain.rb b/shared/output/gapic/templates/testing/snippets/service_resources/plain.rb new file mode 100644 index 000000000..ed42ab46b --- /dev/null +++ b/shared/output/gapic/templates/testing/snippets/service_resources/plain.rb @@ -0,0 +1,55 @@ +# frozen_string_literal: true + +# The MIT License (MIT) +# +# Copyright +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in +# all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +# THE SOFTWARE. + +# Auto-generated by gapic-generator-ruby. DO NOT EDIT! + +# [START testing_v0_generated_ServiceResources_Plain_sync] +require "testing/resources" + +## +# Snippet for the plain call in the ServiceResources service +# +# This snippet has been automatically generated and should be regarded as a code +# template only. It will require modifications to work: +# - It may require correct/in-range values for request initialization. +# - It may require specifying regional endpoints when creating the service +# client as shown in https://cloud.google.com/ruby/docs/reference. +# +# This is an auto-generated example demonstrating basic usage of +# Testing::Resources::ServiceResources::Client#plain. +# +def plain + # Create a client object. The client can be reused for multiple calls. + client = Testing::Resources::ServiceResources::Client.new + + # Create a request. To set request fields, pass in keyword arguments. + request = Testing::Resources::RequestResource.new + + # Call the plain method. + result = client.plain request + + # The returned object is of type Testing::Resources::Response. + p result +end +# [END testing_v0_generated_ServiceResources_Plain_sync] diff --git a/shared/output/gapic/templates/testing/snippets/service_resources/third_plain.rb b/shared/output/gapic/templates/testing/snippets/service_resources/third_plain.rb new file mode 100644 index 000000000..0abdcb7f0 --- /dev/null +++ b/shared/output/gapic/templates/testing/snippets/service_resources/third_plain.rb @@ -0,0 +1,55 @@ +# frozen_string_literal: true + +# The MIT License (MIT) +# +# Copyright +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in +# all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +# THE SOFTWARE. + +# Auto-generated by gapic-generator-ruby. DO NOT EDIT! + +# [START testing_v0_generated_ServiceResources_ThirdPlain_sync] +require "testing/resources" + +## +# Snippet for the third_plain call in the ServiceResources service +# +# This snippet has been automatically generated and should be regarded as a code +# template only. It will require modifications to work: +# - It may require correct/in-range values for request initialization. +# - It may require specifying regional endpoints when creating the service +# client as shown in https://cloud.google.com/ruby/docs/reference. +# +# This is an auto-generated example demonstrating basic usage of +# Testing::Resources::ServiceResources::Client#third_plain. +# +def third_plain + # Create a client object. The client can be reused for multiple calls. + client = Testing::Resources::ServiceResources::Client.new + + # Create a request. To set request fields, pass in keyword arguments. + request = Testing::Resources::RequestThirdResource.new + + # Call the third_plain method. + result = client.third_plain request + + # The returned object is of type Testing::Resources::Response. + p result +end +# [END testing_v0_generated_ServiceResources_ThirdPlain_sync] diff --git a/shared/output/gapic/templates/testing/snippets/snippet_metadata_testing.resources.json b/shared/output/gapic/templates/testing/snippets/snippet_metadata_testing.resources.json new file mode 100644 index 000000000..3aed904da --- /dev/null +++ b/shared/output/gapic/templates/testing/snippets/snippet_metadata_testing.resources.json @@ -0,0 +1,175 @@ +{ + "client_library": { + "name": "testing", + "version": "", + "language": "RUBY", + "apis": [ + { + "id": "testing.resources", + "version": "resources" + } + ] + }, + "snippets": [ + { + "region_tag": "testing_v0_generated_ServiceResources_Plain_sync", + "title": "Snippet for the plain call in the ServiceResources service", + "description": "This is an auto-generated example demonstrating basic usage of Testing::Resources::ServiceResources::Client#plain.", + "file": "service_resources/plain.rb", + "language": "RUBY", + "client_method": { + "short_name": "plain", + "full_name": "::Testing::Resources::ServiceResources::Client#plain", + "async": false, + "parameters": [ + { + "type": "::Testing::Resources::RequestResource", + "name": "request" + } + ], + "result_type": "::Testing::Resources::Response", + "client": { + "short_name": "ServiceResources::Client", + "full_name": "::Testing::Resources::ServiceResources::Client" + }, + "method": { + "short_name": "Plain", + "full_name": "testing.resources.ServiceResources.Plain", + "service": { + "short_name": "ServiceResources", + "full_name": "testing.resources.ServiceResources" + } + } + }, + "canonical": true, + "origin": "API_DEFINITION", + "segments": [ + { + "start": 28, + "end": 54, + "type": "FULL" + } + ] + }, + { + "region_tag": "testing_v0_generated_ServiceResources_AnotherPlain_sync", + "title": "Snippet for the another_plain call in the ServiceResources service", + "description": "This is an auto-generated example demonstrating basic usage of Testing::Resources::ServiceResources::Client#another_plain.", + "file": "service_resources/another_plain.rb", + "language": "RUBY", + "client_method": { + "short_name": "another_plain", + "full_name": "::Testing::Resources::ServiceResources::Client#another_plain", + "async": false, + "parameters": [ + { + "type": "::Testing::Resources::RequestAnotherResource", + "name": "request" + } + ], + "result_type": "::Testing::Resources::Response", + "client": { + "short_name": "ServiceResources::Client", + "full_name": "::Testing::Resources::ServiceResources::Client" + }, + "method": { + "short_name": "AnotherPlain", + "full_name": "testing.resources.ServiceResources.AnotherPlain", + "service": { + "short_name": "ServiceResources", + "full_name": "testing.resources.ServiceResources" + } + } + }, + "canonical": true, + "origin": "API_DEFINITION", + "segments": [ + { + "start": 28, + "end": 54, + "type": "FULL" + } + ] + }, + { + "region_tag": "testing_v0_generated_ServiceResources_ThirdPlain_sync", + "title": "Snippet for the third_plain call in the ServiceResources service", + "description": "This is an auto-generated example demonstrating basic usage of Testing::Resources::ServiceResources::Client#third_plain.", + "file": "service_resources/third_plain.rb", + "language": "RUBY", + "client_method": { + "short_name": "third_plain", + "full_name": "::Testing::Resources::ServiceResources::Client#third_plain", + "async": false, + "parameters": [ + { + "type": "::Testing::Resources::RequestThirdResource", + "name": "request" + } + ], + "result_type": "::Testing::Resources::Response", + "client": { + "short_name": "ServiceResources::Client", + "full_name": "::Testing::Resources::ServiceResources::Client" + }, + "method": { + "short_name": "ThirdPlain", + "full_name": "testing.resources.ServiceResources.ThirdPlain", + "service": { + "short_name": "ServiceResources", + "full_name": "testing.resources.ServiceResources" + } + } + }, + "canonical": true, + "origin": "API_DEFINITION", + "segments": [ + { + "start": 28, + "end": 54, + "type": "FULL" + } + ] + }, + { + "region_tag": "testing_v0_generated_ServiceResources_FourthPlain_sync", + "title": "Snippet for the fourth_plain call in the ServiceResources service", + "description": "This is an auto-generated example demonstrating basic usage of Testing::Resources::ServiceResources::Client#fourth_plain.", + "file": "service_resources/fourth_plain.rb", + "language": "RUBY", + "client_method": { + "short_name": "fourth_plain", + "full_name": "::Testing::Resources::ServiceResources::Client#fourth_plain", + "async": false, + "parameters": [ + { + "type": "::Testing::Resources::RequestFourthResource", + "name": "request" + } + ], + "result_type": "::Testing::Resources::Response", + "client": { + "short_name": "ServiceResources::Client", + "full_name": "::Testing::Resources::ServiceResources::Client" + }, + "method": { + "short_name": "FourthPlain", + "full_name": "testing.resources.ServiceResources.FourthPlain", + "service": { + "short_name": "ServiceResources", + "full_name": "testing.resources.ServiceResources" + } + } + }, + "canonical": true, + "origin": "API_DEFINITION", + "segments": [ + { + "start": 28, + "end": 54, + "type": "FULL" + } + ] + } + ] +} \ No newline at end of file diff --git a/shared/output/gapic/templates/testing/test/testing/resources/service_resources_paths_test.rb b/shared/output/gapic/templates/testing/test/testing/resources/service_resources_paths_test.rb new file mode 100644 index 000000000..969e5b376 --- /dev/null +++ b/shared/output/gapic/templates/testing/test/testing/resources/service_resources_paths_test.rb @@ -0,0 +1,108 @@ +# frozen_string_literal: true + +# The MIT License (MIT) +# +# Copyright +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in +# all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +# THE SOFTWARE. + +# Auto-generated by gapic-generator-ruby. DO NOT EDIT! + +require "helper" + +require "gapic/grpc/service_stub" + +require "testing/resources/service_resources" + +class ::Testing::Resources::ServiceResources::ClientPathsTest < Minitest::Test + class DummyStub + def endpoint + "endpoint.example.com" + end + + def universe_domain + "example.com" + end + + def stub_logger + nil + end + + def logger + nil + end + end + + def test_request_another_resource_path + grpc_channel = ::GRPC::Core::Channel.new "localhost:8888", nil, :this_channel_is_insecure + ::Gapic::ServiceStub.stub :new, DummyStub.new do + client = ::Testing::Resources::ServiceResources::Client.new do |config| + config.credentials = grpc_channel + end + + path = client.request_another_resource_path + assert_equal "projects/responses", path + + path = client.request_another_resource_path project: "value0" + assert_equal "projects/value0/responses", path + end + end + + def test_request_fourth_resource_path + grpc_channel = ::GRPC::Core::Channel.new "localhost:8888", nil, :this_channel_is_insecure + ::Gapic::ServiceStub.stub :new, DummyStub.new do + client = ::Testing::Resources::ServiceResources::Client.new do |config| + config.credentials = grpc_channel + end + + path = client.request_fourth_resource_path project: "value0", resource: "value1", version: "value2" + assert_equal "projects/value0/resources/value1/versions/value2", path + end + end + + def test_request_resource_path + grpc_channel = ::GRPC::Core::Channel.new "localhost:8888", nil, :this_channel_is_insecure + ::Gapic::ServiceStub.stub :new, DummyStub.new do + client = ::Testing::Resources::ServiceResources::Client.new do |config| + config.credentials = grpc_channel + end + + path = client.request_resource_path project: "value0", resource: "value1", version: "value2" + assert_equal "projects/value0/resources/value1/versions/value2", path + + path = client.request_resource_path project: "value0", resource: "value1", subject: "value2", version: "value3" + assert_equal "projects/value0/resources/value1/subjects/value2/versions/value3", path + + path = client.request_resource_path project: "value0", resource: "value1" + assert_equal "projects/value0/compatibility/resources/value1/versions", path + end + end + + def test_request_third_resource_path + grpc_channel = ::GRPC::Core::Channel.new "localhost:8888", nil, :this_channel_is_insecure + ::Gapic::ServiceStub.stub :new, DummyStub.new do + client = ::Testing::Resources::ServiceResources::Client.new do |config| + config.credentials = grpc_channel + end + + path = client.request_third_resource_path + assert_equal "projects/responses", path + end + end +end diff --git a/shared/output/gapic/templates/testing/test/testing/resources/service_resources_test.rb b/shared/output/gapic/templates/testing/test/testing/resources/service_resources_test.rb new file mode 100644 index 000000000..6d3f8ff58 --- /dev/null +++ b/shared/output/gapic/templates/testing/test/testing/resources/service_resources_test.rb @@ -0,0 +1,324 @@ +# frozen_string_literal: true + +# The MIT License (MIT) +# +# Copyright +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in +# all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +# THE SOFTWARE. + +# Auto-generated by gapic-generator-ruby. DO NOT EDIT! + +require "helper" + +require "gapic/grpc/service_stub" + +require "testing/resources/resources_pb" +require "testing/resources/service_resources" + +class ::Testing::Resources::ServiceResources::ClientTest < Minitest::Test + class ClientStub + attr_accessor :call_rpc_count, :requests + + def initialize response, operation, &block + @response = response + @operation = operation + @block = block + @call_rpc_count = 0 + @requests = [] + end + + def call_rpc *args, **kwargs + @call_rpc_count += 1 + + @requests << @block&.call(*args, **kwargs) + + catch :response do + yield @response, @operation if block_given? + @response + end + end + + def endpoint + "endpoint.example.com" + end + + def universe_domain + "example.com" + end + + def stub_logger + nil + end + + def logger + nil + end + end + + def test_plain + # Create GRPC objects. + grpc_response = ::Testing::Resources::Response.new + grpc_operation = GRPC::ActiveCall::Operation.new nil + grpc_channel = GRPC::Core::Channel.new "localhost:8888", nil, :this_channel_is_insecure + grpc_options = {} + + # Create request parameters for a unary method. + resource_name = "hello world" + + plain_client_stub = ClientStub.new grpc_response, grpc_operation do |name, request, options:| + assert_equal :plain, name + assert_kind_of ::Testing::Resources::RequestResource, request + assert_equal "hello world", request["resource_name"] + refute_nil options + end + + Gapic::ServiceStub.stub :new, plain_client_stub do + # Create client + client = ::Testing::Resources::ServiceResources::Client.new do |config| + config.credentials = grpc_channel + end + + # Use hash object + client.plain({ resource_name: resource_name }) do |response, operation| + assert_equal grpc_response, response + assert_equal grpc_operation, operation + end + + # Use named arguments + client.plain resource_name: resource_name do |response, operation| + assert_equal grpc_response, response + assert_equal grpc_operation, operation + end + + # Use protobuf object + client.plain ::Testing::Resources::RequestResource.new(resource_name: resource_name) do |response, operation| + assert_equal grpc_response, response + assert_equal grpc_operation, operation + end + + # Use hash object with options + client.plain({ resource_name: resource_name }, grpc_options) do |response, operation| + assert_equal grpc_response, response + assert_equal grpc_operation, operation + end + + # Use protobuf object with options + client.plain(::Testing::Resources::RequestResource.new(resource_name: resource_name), grpc_options) do |response, operation| + assert_equal grpc_response, response + assert_equal grpc_operation, operation + end + + # Verify method calls + assert_equal 5, plain_client_stub.call_rpc_count + end + end + + def test_another_plain + # Create GRPC objects. + grpc_response = ::Testing::Resources::Response.new + grpc_operation = GRPC::ActiveCall::Operation.new nil + grpc_channel = GRPC::Core::Channel.new "localhost:8888", nil, :this_channel_is_insecure + grpc_options = {} + + # Create request parameters for a unary method. + resource_name = "hello world" + + another_plain_client_stub = ClientStub.new grpc_response, grpc_operation do |name, request, options:| + assert_equal :another_plain, name + assert_kind_of ::Testing::Resources::RequestAnotherResource, request + assert_equal "hello world", request["resource_name"] + refute_nil options + end + + Gapic::ServiceStub.stub :new, another_plain_client_stub do + # Create client + client = ::Testing::Resources::ServiceResources::Client.new do |config| + config.credentials = grpc_channel + end + + # Use hash object + client.another_plain({ resource_name: resource_name }) do |response, operation| + assert_equal grpc_response, response + assert_equal grpc_operation, operation + end + + # Use named arguments + client.another_plain resource_name: resource_name do |response, operation| + assert_equal grpc_response, response + assert_equal grpc_operation, operation + end + + # Use protobuf object + client.another_plain ::Testing::Resources::RequestAnotherResource.new(resource_name: resource_name) do |response, operation| + assert_equal grpc_response, response + assert_equal grpc_operation, operation + end + + # Use hash object with options + client.another_plain({ resource_name: resource_name }, grpc_options) do |response, operation| + assert_equal grpc_response, response + assert_equal grpc_operation, operation + end + + # Use protobuf object with options + client.another_plain(::Testing::Resources::RequestAnotherResource.new(resource_name: resource_name), grpc_options) do |response, operation| + assert_equal grpc_response, response + assert_equal grpc_operation, operation + end + + # Verify method calls + assert_equal 5, another_plain_client_stub.call_rpc_count + end + end + + def test_third_plain + # Create GRPC objects. + grpc_response = ::Testing::Resources::Response.new + grpc_operation = GRPC::ActiveCall::Operation.new nil + grpc_channel = GRPC::Core::Channel.new "localhost:8888", nil, :this_channel_is_insecure + grpc_options = {} + + # Create request parameters for a unary method. + resource_name = "hello world" + + third_plain_client_stub = ClientStub.new grpc_response, grpc_operation do |name, request, options:| + assert_equal :third_plain, name + assert_kind_of ::Testing::Resources::RequestThirdResource, request + assert_equal "hello world", request["resource_name"] + refute_nil options + end + + Gapic::ServiceStub.stub :new, third_plain_client_stub do + # Create client + client = ::Testing::Resources::ServiceResources::Client.new do |config| + config.credentials = grpc_channel + end + + # Use hash object + client.third_plain({ resource_name: resource_name }) do |response, operation| + assert_equal grpc_response, response + assert_equal grpc_operation, operation + end + + # Use named arguments + client.third_plain resource_name: resource_name do |response, operation| + assert_equal grpc_response, response + assert_equal grpc_operation, operation + end + + # Use protobuf object + client.third_plain ::Testing::Resources::RequestThirdResource.new(resource_name: resource_name) do |response, operation| + assert_equal grpc_response, response + assert_equal grpc_operation, operation + end + + # Use hash object with options + client.third_plain({ resource_name: resource_name }, grpc_options) do |response, operation| + assert_equal grpc_response, response + assert_equal grpc_operation, operation + end + + # Use protobuf object with options + client.third_plain(::Testing::Resources::RequestThirdResource.new(resource_name: resource_name), grpc_options) do |response, operation| + assert_equal grpc_response, response + assert_equal grpc_operation, operation + end + + # Verify method calls + assert_equal 5, third_plain_client_stub.call_rpc_count + end + end + + def test_fourth_plain + # Create GRPC objects. + grpc_response = ::Testing::Resources::Response.new + grpc_operation = GRPC::ActiveCall::Operation.new nil + grpc_channel = GRPC::Core::Channel.new "localhost:8888", nil, :this_channel_is_insecure + grpc_options = {} + + # Create request parameters for a unary method. + resource_name = "hello world" + + fourth_plain_client_stub = ClientStub.new grpc_response, grpc_operation do |name, request, options:| + assert_equal :fourth_plain, name + assert_kind_of ::Testing::Resources::RequestFourthResource, request + assert_equal "hello world", request["resource_name"] + refute_nil options + end + + Gapic::ServiceStub.stub :new, fourth_plain_client_stub do + # Create client + client = ::Testing::Resources::ServiceResources::Client.new do |config| + config.credentials = grpc_channel + end + + # Use hash object + client.fourth_plain({ resource_name: resource_name }) do |response, operation| + assert_equal grpc_response, response + assert_equal grpc_operation, operation + end + + # Use named arguments + client.fourth_plain resource_name: resource_name do |response, operation| + assert_equal grpc_response, response + assert_equal grpc_operation, operation + end + + # Use protobuf object + client.fourth_plain ::Testing::Resources::RequestFourthResource.new(resource_name: resource_name) do |response, operation| + assert_equal grpc_response, response + assert_equal grpc_operation, operation + end + + # Use hash object with options + client.fourth_plain({ resource_name: resource_name }, grpc_options) do |response, operation| + assert_equal grpc_response, response + assert_equal grpc_operation, operation + end + + # Use protobuf object with options + client.fourth_plain(::Testing::Resources::RequestFourthResource.new(resource_name: resource_name), grpc_options) do |response, operation| + assert_equal grpc_response, response + assert_equal grpc_operation, operation + end + + # Verify method calls + assert_equal 5, fourth_plain_client_stub.call_rpc_count + end + end + + def test_configure + grpc_channel = GRPC::Core::Channel.new "localhost:8888", nil, :this_channel_is_insecure + + client = block_config = config = nil + dummy_stub = ClientStub.new nil, nil + Gapic::ServiceStub.stub :new, dummy_stub do + client = ::Testing::Resources::ServiceResources::Client.new do |config| + config.credentials = grpc_channel + end + end + + config = client.configure do |c| + block_config = c + end + + assert_same block_config, config + assert_kind_of ::Testing::Resources::ServiceResources::Client::Configuration, config + end +end diff --git a/shared/protos/testing/resources/resources.proto b/shared/protos/testing/resources/resources.proto new file mode 100644 index 000000000..863ae6b82 --- /dev/null +++ b/shared/protos/testing/resources/resources.proto @@ -0,0 +1,65 @@ +syntax = "proto3"; + +package testing.resources; + +import "google/api/client.proto"; +import "google/api/resource.proto"; + + +option ruby_package = "Testing::Resources"; + +service ServiceResources { + option (google.api.default_host) = "resources.example.com"; + + rpc Plain(RequestResource) returns(Response) { } + rpc AnotherPlain(RequestAnotherResource) returns(Response) { } + rpc ThirdPlain(RequestThirdResource) returns(Response) { } + rpc FourthPlain(RequestFourthResource) returns(Response) { } +} + +message RequestResource { + option (google.api.resource) = { + type: "testing.example.com/RequestResource" + pattern: "projects/{project}/resources/{resource}/versions/{version}" + pattern: "projects/{project}/resources/{resource}/subjects/{subject}/versions/{version}" + pattern: "projects/{project}/compatibility/resources/{resource}/versions" + pattern: "projects/{project}/compatibility/resources/{resource}/versions/{version}" + pattern: "projects/{project}/compatibility/resources/{resource}/subjects/{subject}/versions/{version}" + }; + + string resource_name = 1; +} + +message RequestAnotherResource { + option (google.api.resource) = { + type: "testing.example.com/RequestAnotherResource" + pattern: "projects/responses" + pattern: "projects/compatibility/responses" + pattern: "projects/{project}/responses" + }; + + string resource_name = 1; +} + +message RequestThirdResource { + option (google.api.resource) = { + type: "testing.example.com/RequestThirdResource" + pattern: "projects/responses" + pattern: "projects/compatibility/responses" + }; + + string resource_name = 1; +} + +message RequestFourthResource { + option (google.api.resource) = { + type: "testing.example.com/RequestFourthResource" + pattern: "projects/{project}/resources/{resource}/versions/{version}" + pattern: "projects/{project}/compatibility/resources/{resource}/versions/{version}" + }; + + string resource_name = 1; +} + +message Response { +}