Skip to content

Commit

Permalink
feat: Introduce google.api.api_version option to generated clients (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
aandreassa committed May 3, 2024
1 parent 372d2f3 commit df0504f
Show file tree
Hide file tree
Showing 89 changed files with 986 additions and 393 deletions.
5 changes: 5 additions & 0 deletions gapic-generator/lib/gapic/presenters/service_presenter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,11 @@ def generic_endpoint?
gem.generic_endpoint?
end

# @return [String] The api_version for this service, or empty if not defined.
def api_version
@service.api_version.to_s
end

def client_scopes
scopes = Array(common_service_delegate&.client_scopes)
return scopes unless scopes.empty?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,11 @@ def is_deprecated?
@main_service.is_deprecated?
end

# @return [String] The api_version for this service, or empty if not defined.
def api_version
@main_service.api_version.to_s
end

private

# @return [Gapic::Presenters::ServicePresenter]
Expand Down
8 changes: 7 additions & 1 deletion gapic-generator/lib/gapic/schema/wrappers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,8 @@ def initialize descriptor, address, docs, methods

OPTION_EXTENSION_NAMES = {
"google.api.default_host" => [1049, :string],
"google.api.oauth_scopes" => [1050, :string]
"google.api.oauth_scopes" => [1050, :string],
"google.api.api_version" => [525_000_001, :string]
}.freeze

##
Expand All @@ -310,6 +311,11 @@ def scopes
String(option_named("google.api.oauth_scopes")).split ","
end

# @return [String] The API version for this service.
def api_version
option_named "google.api.api_version"
end

# @return [String] Ruby Package
def ruby_package
return nil if parent.nil?
Expand Down
3 changes: 3 additions & 0 deletions gapic-generator/templates/default/service/client/_client.erb
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ require "securerandom"
#
<%- end -%>
class <%= service.client_name %>
# @private
API_VERSION = "<%= service.api_version %>".freeze

# @private
DEFAULT_ENDPOINT_TEMPLATE = <%= service.client_endpoint_template.inspect %>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ require "<%= service.lro_service.proto_service_require %>"
<% end %>
# Service that implements Longrunning Operations API.
class <%= service.operations_name %>
# @private
API_VERSION = "<%= service.api_version %>".freeze

# @private
DEFAULT_ENDPOINT_TEMPLATE = <%= service.client_endpoint_template.inspect %>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@ options = ::Gapic::CallOptions.new(**options.to_h) if options.respond_to? :to_h
# Customize the options with defaults
metadata = @config.rpcs.<%= method.name %>.metadata.to_h

# Set x-goog-api-client and x-goog-user-project headers
# 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: ::<%= method.service.gem.version_name_full %>
metadata[:"x-goog-api-version"] = API_VERSION unless API_VERSION.empty?
metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id
<%- if method.routing_params? && !method.client_streaming? -%>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ require "securerandom"
#
<%- end -%>
class <%= service.rest.client_name %>
# @private
API_VERSION = "<%= service.api_version %>".freeze

# @private
DEFAULT_ENDPOINT_TEMPLATE = <%= service.client_endpoint_template.inspect %>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ require "gapic/operation"
<% end %>
# Service that implements Longrunning Operations API.
class <%= service.operations_name %>
# @private
API_VERSION = "<%= service.api_version %>".freeze

# @private
DEFAULT_ENDPOINT_TEMPLATE = <%= service.client_endpoint_template.inspect %>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@ options = ::Gapic::CallOptions.new(**options.to_h) if options.respond_to? :to_h
# Customize the options with defaults
call_metadata = @config.rpcs.<%= method.name %>.metadata.to_h

# Set x-goog-api-client and x-goog-user-project headers
# Set x-goog-api-client, x-goog-user-project and x-goog-api-version headers
call_metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \
lib_name: @config.lib_name, lib_version: @config.lib_version,
gapic_version: ::<%= method.service.gem.version_name_full %>,
transports_version_send: [:rest]

call_metadata[:"x-goog-api-version"] = API_VERSION unless API_VERSION.empty?
call_metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id

options.apply_defaults timeout: @config.rpcs.<%= method.name %>.timeout,
Expand All @@ -19,4 +20,4 @@ options.apply_defaults timeout: @config.rpcs.<%= method.name %>.timeout,

options.apply_defaults timeout: @config.timeout,
metadata: @config.metadata,
retry_policy: @config.retry_policy
retry_policy: @config.retry_policy
2 changes: 1 addition & 1 deletion shared/googleapis
Submodule googleapis updated 512 files
Binary file modified shared/input/language_v1_desc.bin
Binary file not shown.
Binary file modified shared/input/showcase_desc.bin
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ module CampaignService
# Service to manage campaigns.
#
class Client
# @private
API_VERSION = ""

# @private
DEFAULT_ENDPOINT_TEMPLATE = "googleads.$UNIVERSE_DOMAIN$"

Expand Down Expand Up @@ -260,10 +263,11 @@ def mutate_campaigns request, options = nil
# Customize the options with defaults
metadata = @config.rpcs.mutate_campaigns.metadata.to_h

# Set x-goog-api-client and x-goog-user-project headers
# 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: ::Google::Ads::GoogleAds::VERSION
metadata[:"x-goog-api-version"] = API_VERSION unless API_VERSION.empty?
metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id

header_params = {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ module Rest
# The Addresses API.
#
class Client
# @private
API_VERSION = ""

# @private
DEFAULT_ENDPOINT_TEMPLATE = "compute.$UNIVERSE_DOMAIN$"

Expand Down Expand Up @@ -242,12 +245,13 @@ def aggregated_list request, options = nil
# Customize the options with defaults
call_metadata = @config.rpcs.aggregated_list.metadata.to_h

# Set x-goog-api-client and x-goog-user-project headers
# Set x-goog-api-client, x-goog-user-project and x-goog-api-version headers
call_metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \
lib_name: @config.lib_name, lib_version: @config.lib_version,
gapic_version: ::Google::Cloud::Compute::V1::VERSION,
transports_version_send: [:rest]

call_metadata[:"x-goog-api-version"] = API_VERSION unless API_VERSION.empty?
call_metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id

options.apply_defaults timeout: @config.rpcs.aggregated_list.timeout,
Expand Down Expand Up @@ -331,12 +335,13 @@ def delete request, options = nil
# Customize the options with defaults
call_metadata = @config.rpcs.delete.metadata.to_h

# Set x-goog-api-client and x-goog-user-project headers
# Set x-goog-api-client, x-goog-user-project and x-goog-api-version headers
call_metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \
lib_name: @config.lib_name, lib_version: @config.lib_version,
gapic_version: ::Google::Cloud::Compute::V1::VERSION,
transports_version_send: [:rest]

call_metadata[:"x-goog-api-version"] = API_VERSION unless API_VERSION.empty?
call_metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id

options.apply_defaults timeout: @config.rpcs.delete.timeout,
Expand Down Expand Up @@ -422,12 +427,13 @@ def get request, options = nil
# Customize the options with defaults
call_metadata = @config.rpcs.get.metadata.to_h

# Set x-goog-api-client and x-goog-user-project headers
# Set x-goog-api-client, x-goog-user-project and x-goog-api-version headers
call_metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \
lib_name: @config.lib_name, lib_version: @config.lib_version,
gapic_version: ::Google::Cloud::Compute::V1::VERSION,
transports_version_send: [:rest]

call_metadata[:"x-goog-api-version"] = API_VERSION unless API_VERSION.empty?
call_metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id

options.apply_defaults timeout: @config.rpcs.get.timeout,
Expand Down Expand Up @@ -510,12 +516,13 @@ def insert request, options = nil
# Customize the options with defaults
call_metadata = @config.rpcs.insert.metadata.to_h

# Set x-goog-api-client and x-goog-user-project headers
# Set x-goog-api-client, x-goog-user-project and x-goog-api-version headers
call_metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \
lib_name: @config.lib_name, lib_version: @config.lib_version,
gapic_version: ::Google::Cloud::Compute::V1::VERSION,
transports_version_send: [:rest]

call_metadata[:"x-goog-api-version"] = API_VERSION unless API_VERSION.empty?
call_metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id

options.apply_defaults timeout: @config.rpcs.insert.timeout,
Expand Down Expand Up @@ -619,12 +626,13 @@ def list request, options = nil
# Customize the options with defaults
call_metadata = @config.rpcs.list.metadata.to_h

# Set x-goog-api-client and x-goog-user-project headers
# Set x-goog-api-client, x-goog-user-project and x-goog-api-version headers
call_metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \
lib_name: @config.lib_name, lib_version: @config.lib_version,
gapic_version: ::Google::Cloud::Compute::V1::VERSION,
transports_version_send: [:rest]

call_metadata[:"x-goog-api-version"] = API_VERSION unless API_VERSION.empty?
call_metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id

options.apply_defaults timeout: @config.rpcs.list.timeout,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ module Rest
# The GlobalOperations API.
#
class Client
# @private
API_VERSION = ""

# @private
DEFAULT_ENDPOINT_TEMPLATE = "compute.$UNIVERSE_DOMAIN$"

Expand Down Expand Up @@ -207,12 +210,13 @@ def delete request, options = nil
# Customize the options with defaults
call_metadata = @config.rpcs.delete.metadata.to_h

# Set x-goog-api-client and x-goog-user-project headers
# Set x-goog-api-client, x-goog-user-project and x-goog-api-version headers
call_metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \
lib_name: @config.lib_name, lib_version: @config.lib_version,
gapic_version: ::Google::Cloud::Compute::V1::VERSION,
transports_version_send: [:rest]

call_metadata[:"x-goog-api-version"] = API_VERSION unless API_VERSION.empty?
call_metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id

options.apply_defaults timeout: @config.rpcs.delete.timeout,
Expand Down Expand Up @@ -287,12 +291,13 @@ def get request, options = nil
# Customize the options with defaults
call_metadata = @config.rpcs.get.metadata.to_h

# Set x-goog-api-client and x-goog-user-project headers
# Set x-goog-api-client, x-goog-user-project and x-goog-api-version headers
call_metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \
lib_name: @config.lib_name, lib_version: @config.lib_version,
gapic_version: ::Google::Cloud::Compute::V1::VERSION,
transports_version_send: [:rest]

call_metadata[:"x-goog-api-version"] = API_VERSION unless API_VERSION.empty?
call_metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id

options.apply_defaults timeout: @config.rpcs.get.timeout,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ module Rest
# The Networks API.
#
class Client
# @private
API_VERSION = ""

# @private
DEFAULT_ENDPOINT_TEMPLATE = "compute.$UNIVERSE_DOMAIN$"

Expand Down Expand Up @@ -248,12 +251,13 @@ def list_peering_routes request, options = nil
# Customize the options with defaults
call_metadata = @config.rpcs.list_peering_routes.metadata.to_h

# Set x-goog-api-client and x-goog-user-project headers
# Set x-goog-api-client, x-goog-user-project and x-goog-api-version headers
call_metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \
lib_name: @config.lib_name, lib_version: @config.lib_version,
gapic_version: ::Google::Cloud::Compute::V1::VERSION,
transports_version_send: [:rest]

call_metadata[:"x-goog-api-version"] = API_VERSION unless API_VERSION.empty?
call_metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id

options.apply_defaults timeout: @config.rpcs.list_peering_routes.timeout,
Expand Down Expand Up @@ -337,12 +341,13 @@ def remove_peering request, options = nil
# Customize the options with defaults
call_metadata = @config.rpcs.remove_peering.metadata.to_h

# Set x-goog-api-client and x-goog-user-project headers
# Set x-goog-api-client, x-goog-user-project and x-goog-api-version headers
call_metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \
lib_name: @config.lib_name, lib_version: @config.lib_version,
gapic_version: ::Google::Cloud::Compute::V1::VERSION,
transports_version_send: [:rest]

call_metadata[:"x-goog-api-version"] = API_VERSION unless API_VERSION.empty?
call_metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id

options.apply_defaults timeout: @config.rpcs.remove_peering.timeout,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ module Rest
# The RegionInstanceGroupManagers API.
#
class Client
# @private
API_VERSION = ""

# @private
DEFAULT_ENDPOINT_TEMPLATE = "compute.$UNIVERSE_DOMAIN$"

Expand Down Expand Up @@ -236,12 +239,13 @@ def resize request, options = nil
# Customize the options with defaults
call_metadata = @config.rpcs.resize.metadata.to_h

# Set x-goog-api-client and x-goog-user-project headers
# Set x-goog-api-client, x-goog-user-project and x-goog-api-version headers
call_metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \
lib_name: @config.lib_name, lib_version: @config.lib_version,
gapic_version: ::Google::Cloud::Compute::V1::VERSION,
transports_version_send: [:rest]

call_metadata[:"x-goog-api-version"] = API_VERSION unless API_VERSION.empty?
call_metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id

options.apply_defaults timeout: @config.rpcs.resize.timeout,
Expand Down

0 comments on commit df0504f

Please sign in to comment.