Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ module Generators
# Contains the cloud generator's parameters
module CloudGeneratorParameters
BOOL_PARAMETERS_ALIASES = {
"ruby-cloud-format" => ":format",
"ruby-cloud-free-tier" => ":gem.:free_tier",
"ruby-cloud-yard-strict" => ":gem.:yard_strict",
"ruby-cloud-generic-endpoint" => ":gem.:generic_endpoint",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ def test_parse_parameters_readable
["ruby-cloud-is-cloud-product", API_INFO[:is_cloud_product].to_s],
["ruby-cloud-generate-metadata", API_INFO[:generate_metadata].to_s],
["ruby-cloud-rest-numeric-enums", API_INFO[:rest_numeric_enums].to_s],
["ruby-cloud-format", API_INFO[:format].to_s],

["ruby-cloud-gem-name", API_INFO[:name]],
["ruby-cloud-gem-namespace", API_INFO[:namespace]],
Expand Down
1 change: 1 addition & 0 deletions gapic-generator/lib/gapic/generators/base_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ def generate_file template, filename, **args
alias_method :g, :generate_file

def format_files files
return files unless @api.format?
FileFormatter.new(format_config, files).files
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ module Generators
# Contains the default generator's parameters
module DefaultGeneratorParameters
BOOL_PARAMETERS = [
":format",
":gem.:free_tier",
":gem.:yard_strict",
":gem.:generic_endpoint",
Expand Down
6 changes: 6 additions & 0 deletions gapic-generator/lib/gapic/schema/api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,12 @@ def generate_yardoc_snippets?
configuration.fetch :generate_yardoc_snippets, true
end

# Whether to format generated files
# @return [Boolean]
def format?
configuration.fetch :format, true
end

# Whether to generate gapic metadata (drift manifest) file
# @return [Boolean]
def generate_metadata
Expand Down
19 changes: 18 additions & 1 deletion gapic-generator/test/gapic/schema/api_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

require "test_helper"
require "api_test_resources"
require "gapic/generators/base_generator"

class ApiTest < Minitest::Test
API_INFO = ApiTestResources::API_INFO
Expand All @@ -41,6 +42,7 @@ def test_parse_parameters_literal
[":gem.:is_cloud_product", API_INFO[:is_cloud_product].to_s],
[":gem.:rest_numeric_enums", API_INFO[:rest_numeric_enums].to_s],
[":generate_metadata", API_INFO[:generate_metadata].to_s],
[":format", API_INFO[:format].to_s],

[":gem.:name", API_INFO[:name]],
[":gem.:namespace", API_INFO[:namespace]],
Expand Down Expand Up @@ -91,8 +93,9 @@ def test_parse_parameters_readable
["gem-generic-endpoint", API_INFO[:generic_endpoint]],
["gem-is-cloud-product", API_INFO[:is_cloud_product]],
["rest-numeric-enums", API_INFO[:rest_numeric_enums]],
# this parameter has no alias in gapic-generator-vanilla
# these parameters have no alias in gapic-generator-vanilla
[":generate_metadata", API_INFO[:generate_metadata]],
[":format", API_INFO[:format]],

["gem-name", API_INFO[:name]],
["gem-namespace", API_INFO[:namespace]],
Expand Down Expand Up @@ -147,6 +150,20 @@ def test_parameter_reconstruction
assert_equal parameter, api.protoc_parameter
end

def test_format_default_and_override
default_api = Gapic::Schema::Api.new OpenStruct.new(parameter: "", proto_file: [])
assert default_api.format?

unformatted_api = Gapic::Schema::Api.new OpenStruct.new(parameter: ":format=false", proto_file: [])
refute unformatted_api.format?

file = Google::Protobuf::Compiler::CodeGeneratorResponse::File.new(
name: "foo.rb", content: "x = 'unformatted'\n"
)
formatted = Gapic::Generators::BaseGenerator.new(unformatted_api).send(:format_files, [file])
assert_equal "x = 'unformatted'\n", formatted.first.content
end

private

# Create a list of parameters and values
Expand Down
4 changes: 3 additions & 1 deletion shared/test_resources/api_test_resources.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ module ApiTestResources
is_cloud_product: true,
generate_metadata: false,
rest_numeric_enums: true,
format: false,

# string parameters
name: 'google-cloud-container_analysis-v1',
Expand Down Expand Up @@ -113,6 +114,7 @@ module ApiTestResources
wrapper_gem_name: API_INFO[:wrapper_gem_name_override]
},
transports: API_INFO[:transports],
generate_metadata: API_INFO[:generate_metadata]
generate_metadata: API_INFO[:generate_metadata],
format: API_INFO[:format]
}.freeze
end
Loading