Skip to content

Commit 75ae244

Browse files
authored
Update BuildTools and specs to use JSON.load_file (#3143)
1 parent d5f8c5e commit 75ae244

File tree

10 files changed

+53
-45
lines changed

10 files changed

+53
-45
lines changed

Gemfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ if defined?(JRUBY_VERSION)
1414
end
1515

1616
# protocol parsers
17-
gem 'json', '>= 2.4.0', '<= 2.7.6' # due to load_file support and we use it for specs
17+
gem 'json', '>= 2.4.0' # due to load_file support
1818
gem 'nokogiri', '>= 1.6.8.1'
1919
gem 'oga'
2020
gem 'rexml'

build_tools/aws-sdk-code-generator/spec/aws-sdk-code-generator/shared_example_spec.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ module AwsSdkCodeGenerator
77

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

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

1616
def load_example_input(operation_name)
1717
example = examples[operation_name][0]

build_tools/custom_service.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ def build
5252
private
5353

5454
def load_json(model_dir)
55-
JSON.load(File.read(model_path(model_dir)))
55+
JSON.load_file(model_path(model_dir))
5656
end
5757

5858
def model_path(model_dir)

build_tools/services.rb

+5-5
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ def services
5656
end
5757

5858
def manifest
59-
JSON.load(File.read(@manifest_path))
59+
JSON.load_file(@manifest_path)
6060
end
6161

6262
def build_service(svc_name, config)
@@ -84,21 +84,21 @@ def build_service(svc_name, config)
8484
end
8585

8686
def load_api(svc_name, models_dir)
87-
api = JSON.load(File.read(model_path('api-2.json', models_dir)))
87+
api = JSON.load_file(model_path('api-2.json', models_dir))
8888
BuildTools::Customizations.apply_api_customizations(svc_name, api)
8989
api
9090
end
9191

9292
def load_docs(svc_name, models_dir)
93-
docs = JSON.load(File.read(model_path('docs-2.json', models_dir)))
93+
docs = JSON.load_file(model_path('docs-2.json', models_dir))
9494
BuildTools::Customizations.apply_doc_customizations(svc_name, docs)
9595
docs
9696
end
9797

9898
def load_examples(svc_name, models_dir)
9999
path = model_path('examples-1.json', models_dir)
100100
if path
101-
examples = JSON.load(File.read(path))
101+
examples = JSON.load_file(path)
102102
BuildTools::Customizations.apply_example_customizations(svc_name, examples)
103103
examples
104104
else
@@ -109,7 +109,7 @@ def load_examples(svc_name, models_dir)
109109
def load_smoke(svc_name, models_dir)
110110
path = model_path('smoke-2.json', models_dir)
111111
if path
112-
smoke = JSON.load(File.read(path))
112+
smoke = JSON.load_file(path)
113113
BuildTools::Customizations.apply_smoke_customizations(svc_name, smoke)
114114
smoke
115115
else

gems/aws-eventstream/spec/spec_helper.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ def expected_decoded_error(path)
2828
end
2929

3030
def convert_msg(path)
31-
hash = JSON.load(File.read(path))
31+
hash = JSON.load_file(path)
3232
Aws::EventStream::Message.new(
3333
headers: build_headers(hash['headers']),
3434
payload: StringIO.new(Base64.decode64(hash['payload']))

gems/aws-partitions/spec/aws_partitions_spec.rb

+20-17
Original file line numberDiff line numberDiff line change
@@ -242,8 +242,9 @@ module Aws
242242

243243
describe 'metadata' do
244244
let(:partition_metadata_json) do
245-
path = File.expand_path('../test_partitions_metadata.json', __FILE__)
246-
JSON.load(File.read(path))
245+
JSON.load_file(
246+
File.expand_path('test_partitions_metadata.json', __dir__)
247+
)
247248
end
248249

249250
before do
@@ -267,22 +268,23 @@ module Aws
267268
end
268269

269270
after do
270-
path = File.expand_path('../../partitions.json', __FILE__)
271-
original_json = JSON.load(File.read(path))
271+
original_json =
272+
JSON.load_file(File.expand_path('../partitions.json', __dir__))
272273
Partitions.clear
273274
Partitions.add(original_json)
274275
Partitions.merge_metadata(
275-
JSON.load(File.read(
276-
File.expand_path('../../partitions-metadata.json', __FILE__)))
276+
JSON.load_file(File.expand_path('../partitions-metadata.json', __dir__))
277277
)
278278
end
279279
end
280280

281281
# normal endpoint testing
282282
describe Partitions::EndpointProvider do
283283
let(:partition_json) do
284-
path = File.expand_path('../test_partition.json', __FILE__)
285-
JSON.load(File.read(path))
284+
JSON.load_file(
285+
File.expand_path('test_partition.json', __dir__)
286+
)
287+
286288
end
287289

288290
before { Partitions.add(partition_json) }
@@ -428,8 +430,9 @@ module Aws
428430
# variants endpoints testing
429431
describe Partitions::EndpointProvider do
430432
let(:fips_partition_json) do
431-
path = File.expand_path('../variant_test_partition.json', __FILE__)
432-
JSON.load(File.read(path))
433+
JSON.load_file(
434+
File.expand_path('variant_test_partition.json', __dir__)
435+
)
433436
end
434437

435438
before do
@@ -438,18 +441,19 @@ module Aws
438441
end
439442

440443
after do
441-
path = File.expand_path('../../partitions.json', __FILE__)
442-
original_json = JSON.load(File.read(path))
444+
original_json =
445+
JSON.load_file(File.expand_path('../partitions.json', __dir__))
443446
Partitions.clear
444447
Partitions.add(original_json)
445448
Partitions.merge_metadata(
446-
JSON.load(File.read(
447-
File.expand_path('../../partitions-metadata.json', __FILE__)))
449+
JSON.load_file(
450+
File.expand_path('../partitions-metadata.json', __dir__)
451+
)
448452
)
449453
end
450454

451-
path = File.expand_path('../variant_test_cases.json', __FILE__)
452-
test_cases = JSON.load(File.read(path))
455+
test_cases =
456+
JSON.load_file(File.expand_path('variant_test_cases.json', __dir__))
453457

454458
describe '.resolve' do
455459
test_cases.each_with_index do |test_case, index|
@@ -503,6 +507,5 @@ module Aws
503507
end
504508
end
505509
end
506-
507510
end
508511
end

gems/aws-sdk-core/spec/api_helper.rb

+11-12
Original file line numberDiff line numberDiff line change
@@ -7,48 +7,47 @@ class << self
77

88
def sample_json # dynamodb
99
@sample_json ||= begin
10-
api = File.expand_path('../fixtures/apis/dynamodb.json', __FILE__)
11-
api = JSON.load(File.read(api))
10+
api =
11+
JSON.load_file(File.expand_path('fixtures/apis/dynamodb.json', __dir__))
1212
sample_service(api: api)
1313
end
1414
end
1515

1616
def sample_query # iam
1717
@sample_query ||= begin
18-
api = File.expand_path('../fixtures/apis/iam.json', __FILE__)
19-
api = JSON.load(File.read(api))
18+
api =
19+
JSON.load_file(File.expand_path('fixtures/apis/iam.json', __dir__))
2020
sample_service(api: api)
2121
end
2222
end
2323

2424
def sample_rest_xml # s3
2525
@sample_rest_xml ||= begin
26-
api = File.expand_path('../fixtures/apis/s3.json', __FILE__)
27-
api = JSON.load(File.read(api))
26+
api =
27+
JSON.load_file(File.expand_path('fixtures/apis/s3.json', __dir__))
2828
sample_service(api: api)
2929
end
3030
end
3131

3232
def sample_rest_json # glacier
3333
@sample_rest_json ||= begin
34-
api = File.expand_path('../fixtures/apis/glacier.json', __FILE__)
35-
api = JSON.load(File.read(api))
34+
api =
35+
JSON.load_file(File.expand_path('fixtures/apis/glacier.json', __dir__))
3636
sample_service(api: api)
3737
end
3838
end
3939

4040
def sample_ec2 # ec2 has its own protocol
4141
@sample_ec2 ||= begin
42-
api = File.expand_path('../fixtures/apis/ec2.json', __FILE__)
43-
api = JSON.load(File.read(api))
42+
api = JSON.load_file(File.expand_path('fixtures/apis/ec2.json', __dir__))
4443
sample_service(api: api)
4544
end
4645
end
4746

4847
def sample_rpcv2_cbor # cloudwatch logs changed to cbor
4948
@sample_rpcv2_cbor ||= begin
50-
api = File.expand_path('../fixtures/apis/logs.json', __FILE__)
51-
api = JSON.load(File.read(api))
49+
api =
50+
JSON.load_file(File.expand_path('fixtures/apis/logs.json', __dir__))
5251
sample_service(api: api)
5352
end
5453
end

gems/aws-sdk-core/spec/aws/xml/error_handler_spec.rb

+9-3
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@ module Xml
88

99
let(:cloudfront) {
1010
ApiHelper.sample_service(
11-
api: JSON.load(File.read(File.expand_path('../../../fixtures/apis/cloudfront.json', __FILE__)))
11+
api: JSON.load_file(
12+
File.expand_path('../../fixtures/apis/cloudfront.json', __dir__)
13+
)
1214
)::Client.new(
1315
region: 'us-west-2',
1416
retry_limit: 0,
@@ -19,7 +21,9 @@ module Xml
1921

2022
let(:route53) {
2123
ApiHelper.sample_service(
22-
api: JSON.load(File.read(File.expand_path('../../../fixtures/apis/route53.json', __FILE__)))
24+
api: JSON.load_file(
25+
File.expand_path('../../fixtures/apis/route53.json', __dir__)
26+
)
2327
)::Client.new(
2428
region: 'us-west-2',
2529
retry_limit: 0,
@@ -39,7 +43,9 @@ module Xml
3943

4044
let(:sns) {
4145
ApiHelper.sample_service(
42-
api: JSON.load(File.read(File.expand_path('../../../fixtures/apis/sns.json', __FILE__)))
46+
api: JSON.load_file(
47+
File.expand_path('../../fixtures/apis/sns.json', __dir__)
48+
)
4349
)::Client.new(
4450
region: 'us-west-2',
4551
retry_limit: 0,

gems/aws-sdk-s3/spec/encryptionV2/kat_spec.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ def self.build_kat(raw_kat)
2727
)
2828
end
2929

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

tasks/update-defaults-mode.rake

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ task 'update-defaults-mode', [:defaults_file] do |t, args|
1010
end
1111

1212
puts "Loading defaults from: #{defaults_file}"
13-
defaults = JSON.load(File.read(defaults_file))
13+
defaults = JSON.load_file(defaults_file)
1414

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

0 commit comments

Comments
 (0)