Skip to content

Commit

Permalink
Update BuildTools and specs to use JSON.load_file (#3143)
Browse files Browse the repository at this point in the history
  • Loading branch information
jterapin authored Nov 21, 2024
1 parent d5f8c5e commit 75ae244
Show file tree
Hide file tree
Showing 10 changed files with 53 additions and 45 deletions.
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ if defined?(JRUBY_VERSION)
end

# protocol parsers
gem 'json', '>= 2.4.0', '<= 2.7.6' # due to load_file support and we use it for specs
gem 'json', '>= 2.4.0' # due to load_file support
gem 'nokogiri', '>= 1.6.8.1'
gem 'oga'
gem 'rexml'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ module AwsSdkCodeGenerator

let(:dir) { File.dirname(__FILE__) }
let(:example_path) { File.join(dir, '..', 'fixtures', 'shared_examples', 'examples.json') }
let(:example_file) { File.open(example_path, 'rb') {|file| JSON.load(file.read)} }
let(:example_file) { JSON.load_file(example_path) }
let(:examples) {example_file['examples']}

let(:api_path) { File.join(dir, '..', 'fixtures', 'shared_examples', 'api.json') }
let(:s3_api) { File.open(api_path, 'rb') {|file| JSON.load(file.read)} }
let(:s3_api) { JSON.load_file(api_path) }

def load_example_input(operation_name)
example = examples[operation_name][0]
Expand Down
2 changes: 1 addition & 1 deletion build_tools/custom_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def build
private

def load_json(model_dir)
JSON.load(File.read(model_path(model_dir)))
JSON.load_file(model_path(model_dir))
end

def model_path(model_dir)
Expand Down
10 changes: 5 additions & 5 deletions build_tools/services.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def services
end

def manifest
JSON.load(File.read(@manifest_path))
JSON.load_file(@manifest_path)
end

def build_service(svc_name, config)
Expand Down Expand Up @@ -84,21 +84,21 @@ def build_service(svc_name, config)
end

def load_api(svc_name, models_dir)
api = JSON.load(File.read(model_path('api-2.json', models_dir)))
api = JSON.load_file(model_path('api-2.json', models_dir))
BuildTools::Customizations.apply_api_customizations(svc_name, api)
api
end

def load_docs(svc_name, models_dir)
docs = JSON.load(File.read(model_path('docs-2.json', models_dir)))
docs = JSON.load_file(model_path('docs-2.json', models_dir))
BuildTools::Customizations.apply_doc_customizations(svc_name, docs)
docs
end

def load_examples(svc_name, models_dir)
path = model_path('examples-1.json', models_dir)
if path
examples = JSON.load(File.read(path))
examples = JSON.load_file(path)
BuildTools::Customizations.apply_example_customizations(svc_name, examples)
examples
else
Expand All @@ -109,7 +109,7 @@ def load_examples(svc_name, models_dir)
def load_smoke(svc_name, models_dir)
path = model_path('smoke-2.json', models_dir)
if path
smoke = JSON.load(File.read(path))
smoke = JSON.load_file(path)
BuildTools::Customizations.apply_smoke_customizations(svc_name, smoke)
smoke
else
Expand Down
2 changes: 1 addition & 1 deletion gems/aws-eventstream/spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def expected_decoded_error(path)
end

def convert_msg(path)
hash = JSON.load(File.read(path))
hash = JSON.load_file(path)
Aws::EventStream::Message.new(
headers: build_headers(hash['headers']),
payload: StringIO.new(Base64.decode64(hash['payload']))
Expand Down
37 changes: 20 additions & 17 deletions gems/aws-partitions/spec/aws_partitions_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -242,8 +242,9 @@ module Aws

describe 'metadata' do
let(:partition_metadata_json) do
path = File.expand_path('../test_partitions_metadata.json', __FILE__)
JSON.load(File.read(path))
JSON.load_file(
File.expand_path('test_partitions_metadata.json', __dir__)
)
end

before do
Expand All @@ -267,22 +268,23 @@ module Aws
end

after do
path = File.expand_path('../../partitions.json', __FILE__)
original_json = JSON.load(File.read(path))
original_json =
JSON.load_file(File.expand_path('../partitions.json', __dir__))
Partitions.clear
Partitions.add(original_json)
Partitions.merge_metadata(
JSON.load(File.read(
File.expand_path('../../partitions-metadata.json', __FILE__)))
JSON.load_file(File.expand_path('../partitions-metadata.json', __dir__))
)
end
end

# normal endpoint testing
describe Partitions::EndpointProvider do
let(:partition_json) do
path = File.expand_path('../test_partition.json', __FILE__)
JSON.load(File.read(path))
JSON.load_file(
File.expand_path('test_partition.json', __dir__)
)

end

before { Partitions.add(partition_json) }
Expand Down Expand Up @@ -428,8 +430,9 @@ module Aws
# variants endpoints testing
describe Partitions::EndpointProvider do
let(:fips_partition_json) do
path = File.expand_path('../variant_test_partition.json', __FILE__)
JSON.load(File.read(path))
JSON.load_file(
File.expand_path('variant_test_partition.json', __dir__)
)
end

before do
Expand All @@ -438,18 +441,19 @@ module Aws
end

after do
path = File.expand_path('../../partitions.json', __FILE__)
original_json = JSON.load(File.read(path))
original_json =
JSON.load_file(File.expand_path('../partitions.json', __dir__))
Partitions.clear
Partitions.add(original_json)
Partitions.merge_metadata(
JSON.load(File.read(
File.expand_path('../../partitions-metadata.json', __FILE__)))
JSON.load_file(
File.expand_path('../partitions-metadata.json', __dir__)
)
)
end

path = File.expand_path('../variant_test_cases.json', __FILE__)
test_cases = JSON.load(File.read(path))
test_cases =
JSON.load_file(File.expand_path('variant_test_cases.json', __dir__))

describe '.resolve' do
test_cases.each_with_index do |test_case, index|
Expand Down Expand Up @@ -503,6 +507,5 @@ module Aws
end
end
end

end
end
23 changes: 11 additions & 12 deletions gems/aws-sdk-core/spec/api_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,48 +7,47 @@ class << self

def sample_json # dynamodb
@sample_json ||= begin
api = File.expand_path('../fixtures/apis/dynamodb.json', __FILE__)
api = JSON.load(File.read(api))
api =
JSON.load_file(File.expand_path('fixtures/apis/dynamodb.json', __dir__))
sample_service(api: api)
end
end

def sample_query # iam
@sample_query ||= begin
api = File.expand_path('../fixtures/apis/iam.json', __FILE__)
api = JSON.load(File.read(api))
api =
JSON.load_file(File.expand_path('fixtures/apis/iam.json', __dir__))
sample_service(api: api)
end
end

def sample_rest_xml # s3
@sample_rest_xml ||= begin
api = File.expand_path('../fixtures/apis/s3.json', __FILE__)
api = JSON.load(File.read(api))
api =
JSON.load_file(File.expand_path('fixtures/apis/s3.json', __dir__))
sample_service(api: api)
end
end

def sample_rest_json # glacier
@sample_rest_json ||= begin
api = File.expand_path('../fixtures/apis/glacier.json', __FILE__)
api = JSON.load(File.read(api))
api =
JSON.load_file(File.expand_path('fixtures/apis/glacier.json', __dir__))
sample_service(api: api)
end
end

def sample_ec2 # ec2 has its own protocol
@sample_ec2 ||= begin
api = File.expand_path('../fixtures/apis/ec2.json', __FILE__)
api = JSON.load(File.read(api))
api = JSON.load_file(File.expand_path('fixtures/apis/ec2.json', __dir__))
sample_service(api: api)
end
end

def sample_rpcv2_cbor # cloudwatch logs changed to cbor
@sample_rpcv2_cbor ||= begin
api = File.expand_path('../fixtures/apis/logs.json', __FILE__)
api = JSON.load(File.read(api))
api =
JSON.load_file(File.expand_path('fixtures/apis/logs.json', __dir__))
sample_service(api: api)
end
end
Expand Down
12 changes: 9 additions & 3 deletions gems/aws-sdk-core/spec/aws/xml/error_handler_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ module Xml

let(:cloudfront) {
ApiHelper.sample_service(
api: JSON.load(File.read(File.expand_path('../../../fixtures/apis/cloudfront.json', __FILE__)))
api: JSON.load_file(
File.expand_path('../../fixtures/apis/cloudfront.json', __dir__)
)
)::Client.new(
region: 'us-west-2',
retry_limit: 0,
Expand All @@ -19,7 +21,9 @@ module Xml

let(:route53) {
ApiHelper.sample_service(
api: JSON.load(File.read(File.expand_path('../../../fixtures/apis/route53.json', __FILE__)))
api: JSON.load_file(
File.expand_path('../../fixtures/apis/route53.json', __dir__)
)
)::Client.new(
region: 'us-west-2',
retry_limit: 0,
Expand All @@ -39,7 +43,9 @@ module Xml

let(:sns) {
ApiHelper.sample_service(
api: JSON.load(File.read(File.expand_path('../../../fixtures/apis/sns.json', __FILE__)))
api: JSON.load_file(
File.expand_path('../../fixtures/apis/sns.json', __dir__)
)
)::Client.new(
region: 'us-west-2',
retry_limit: 0,
Expand Down
4 changes: 2 additions & 2 deletions gems/aws-sdk-s3/spec/encryptionV2/kat_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ def self.build_kat(raw_kat)
)
end

fixture_path = File.expand_path('../../fixtures/encryption', __FILE__)
kats = JSON.load File.new(File.join(fixture_path, 'aes_gcm_kat.json'))
fixture_path = File.expand_path('../fixtures/encryption', __dir__)
kats = JSON.load_file(File.new(File.join(fixture_path, 'aes_gcm_kat.json')))
kats.each_with_index do |raw, i|
kat = build_kat(raw)

Expand Down
2 changes: 1 addition & 1 deletion tasks/update-defaults-mode.rake
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ task 'update-defaults-mode', [:defaults_file] do |t, args|
end

puts "Loading defaults from: #{defaults_file}"
defaults = JSON.load(File.read(defaults_file))
defaults = JSON.load_file(defaults_file)

default_mode_docs = ["<p>The following <code>:default_mode</code> values are supported: </p>"]
default_mode_docs << "<ul>"
Expand Down

0 comments on commit 75ae244

Please sign in to comment.